Jump to content

LabiVila

Members
  • Posts

    272
  • Joined

  • Last visited

Everything posted by LabiVila

  1. LabiVila

    Lock System

    Do not add this to your script, just start testing how this kind of tables work out. Then make a Lock System around this, not around getElementDatas, it should be far more efficient and better
  2. It is: addEventHandler ("onMarkerHit", marker, onHit) otherwise, the 'onPlayerMarkerHit' doesn't have the second argument a 'marker', but it has the root element. Just replace onPlayerMarkerHit with onMarkerHit and it should be working fine. I suggest you re-read these again: https://wiki.multitheftauto.com/wiki/OnMarkerHit https://wiki.multitheftauto.com/wiki/OnPlayerMarkerHit
  3. No, wordBreak won't do stuff if it's inside a dxDrawRectangle and you using a table, then you can make a count = 0 then start count = count + 1 for every loop it passes. Then you can do if (k == 5 [like 5 elements (or five texts) fill a rectangle]) then you can create a scrollBar. I don't think there is a function to check a bottom like say)
  4. You can use this: https://wiki.multitheftauto.com/wiki/IsMouseInPosition and use the on client click: https://wiki.multitheftauto.com/wiki/OnClientClick and you make it work like this: when on client click, you check if is mouse in position of the dxdrawtext, If it is, then you can relate the 'key' of your "getElementsByType" with the 'value (playerNames in our case). Good luck
  5. Why would you use element datas for a lot of items inside something like an inventory? So you wanna set an element data for every piece of item you get? It would be just a lot faster and more organised if you used tables
  6. LabiVila

    Lock System

    I used (would personally use) player element instead of serial, but if that's how you really want it: players = {} local currentSerial = getPlayerSerial (player) players [currentSerial] = {shares = {}, lockable = false / true and anything you want here}
  7. Let me first explain the stuff I did above: so this: local x, y = guiGetScreenSize () gets your screen's size so you fit it for every screen (I didn't fit mine there) then on Client Render keeps the frames going so you can actually 'draw' the text. Then for playerPosition, playerName are usually found as (for k, v) or for (i, v), I did it so you can understand it easier; they loop through the table of all online players and you use the dxDrawText finally. dxDrawText (0 (because I did "center" at last argument I wrote up), then 20 + (playerPosition * 20). playerPosition * 20 is going to keep growing every time you loop through the table, so if there are 5 players, you'll have these coordinates: 50, 70, 90, 110, 130 as for your second question, you can do that but it would be messy af. I highly recommend a full GUI interface or just try to create a dx one (might be hard for a beginner)
  8. Another way is by using 'vehicle variants', this is the way some race servers implemented Vinyls and it works with models as well. https://wiki.multitheftauto.com/wiki/Vehicle_variants
  9. First of all, you don't have to declare this local player_cache = {} since 'getElementsByType' already created a table. Second, you just declared memberlist = {} empty, and 'k' returns you the index of the player, so this part: for k = 1, 200 do if (memberlist [k] == nil) then ... end end is kind of useless. And to make a button, you should as well use gridlists to get the clicked item since the way with only a button works not. You can write this to display all the names of online players (since getElementsByType "player") returns online players; local x, y = guiGetScreenSize () addEventHandler ("onClientRender", getRootElement(), function () for playerPosition, playerName in ipairs (getElementsByType ("player")) do dxDrawText (playerName, 0, 50 + (playerPosition * 20), x, y, tocolor (255, 255, 255, 200), 1, "default-bold", "center") end end ) MTA Wiki provides a very similar example to getting player's name: https://wiki.multitheftauto.com/wiki/Gu ... etItemText
  10. LabiVila

    Lock System

    Firstly, I think you should use tables and not elemnt datas since it'll mess things up (in my opinion at least) and tables are made for such things. So you can do something like this: local players = {shares = {}} now everytime you want someone to lock, you insert the player this way: players [player] = {} and everytime you want to share the table with someone, you write: for _,v in pairs (players) do table.insert (v.shares, sharedPlayer) end now when a player wants to get in the car, you can check it this way (if he's allowed) for _,v in pairs (players) do for _,a in pairs (v.shares) do if (a == specifiedPlayerWhoWantsToJoinTheCar) then --allow him end end end and by the way, don't you need a function to remove the player from `car share` ?
  11. You can do random a number from 0 - 1000, then if number is less than 5 (0.05 %), give M4, if number is from 5 to 100, give him Shotgun, if number is from 100 - 300 give him something else and so on. This would work
  12. Haha, cool to see how you edited your post, then replied to me
  13. By the way, '900000' is not an hour, '3600000' is
  14. By the way, since you had the same outputChatBox for both 'if not other then' and 'if not amount then', you can merge them to one line: if not other or not amount then outputChatBox("Syntax: /pay (playerName) (amount)",player,0,255,255) end
  15. addEventHandler ("onPlayerLogin", getRootElement(), function () local acc = getPlayerAccount (source) if acc and not isGuestAccount (acc) then local everPlayed = getAccountData (acc, "everPlayedHere") if (everPlayed == false) then --showWindow setAccountData (acc, "everPlayedHere", true) outputChatBox ("Table showed cuz you never logged in here", source) else outputChatBox ("Table not showed cuz u've logged in here once", source) end end end ) The same stuff can be client-side (since you have GUIs, but it works like this)
  16. Hello so my question is, how can I create another table and get returned that and not self? I'm a beginner in OOP and so far I've achieved somehow what I wanted with this: local players = {} local count = 0 function players:addPlayers (name, age) count = count + 1 local list = {} setmetatable (list, self) self [count] = {name = name, age = age} return self end function players:getAll () return self end addCommandHandler ("add", function (_, _, a, b) players:addPlayers (a, b) end ) addCommandHandler ("go", function () ai = players:getAll () for i,v in pairs (ai) do if (tonumber (i)) then outputChatBox (v.name.." "..v.age) end end end ) but If I loop through the self table, I get all function names (getPlayers, addPlayers and I don't know why) and I want a clear table for my players, not the 'self' one. thank you further
  17. You can do that by writing: table.insert (table, {something = "storing data"}) and you can access it by: for _,v in ipairs (table) do outputChatBox (v.something) --would output 'storing data' end
  18. ROFL didn't notice that
  19. Use it server-side, as client-side has no argument "player". If you use it client-side, you should remove the argument "player" and do 'setElementPosition (localPlayer, 0, 0, 3)
  20. So you want that all the players with 'NameGroup' see your messages when you write, not the rest? If not, be more specific please
  21. Hello, local x,y = guiGetScreenSize () local mapSmallness = 5 --Handle render target; addEventHandler ("onClientResourceStart", getRootElement(), function () renderTarget = dxCreateRenderTarget (180, 180, true) end ) --Keep the map appeared; addEventHandler ("onClientRender", getRootElement(), function () if renderTarget then dxSetRenderTarget (renderTarget) ---------------------------------- local _, _, pedRotation = getElementRotation (localPlayer) dxDrawRectangle (0, 0, 180, 180, tocolor (0, 0, 0, 150)) dxDrawImage (80, 80, 20, 20, "blip_player.png", pedRotation) getBlips () ---------------------------------- dxSetRenderTarget () dxDrawImage (20, 400, 180, 180, renderTarget) end end ) --Created blips; function getBlips () local myX, myY = getElementPosition (localPlayer) for i,v in ipairs (getElementsByType ("object")) do if (getElementModel (v) == 673) then local treeX, treeY = getElementPosition (v) dxDrawRectangle (87.5 + (myX - treeX) * mapSmallness, 87.5 + (myY - treeY) * mapSmallness, 6, 6, tocolor (0, 255, 0, 150)) end if (getElementModel (v) == 746) then local rockX, rockY = getElementPosition (v) dxDrawRectangle (87.5 + (myX - rockX) * mapSmallness, 87.5 + (myY - rockY) * mapSmallness, 6, 6, tocolor (0, 255, 0, 150)) end if (getElementModel (v) == 3276) then local fenceX, fenceY = getElementPosition (v) dxDrawRectangle (87.5 + (myX - fenceX) * mapSmallness, 87.5 + (myY - fenceY) * mapSmallness, 6, 6, tocolor (0, 255, 0, 150)) end end end so the radar works fine but I can't manage to make it work as I want. Currently when you rotate, it's the player's blip that moves but I don't want this (since it seems quite messed up on gameplay). I want the player's blip to stand still (not moving, not rotating) but the objects behind should move when you rotate. So I'm having problems with player's blip, it works strangely. Thanks further
  22. function increaseHP (_, enemy) if (enemy) then setElementHealth (enemy, getElementHealth (enemy) + 10) outputChatBox ("Your HP has been increased because you killed "..getPlayerName (source).."#ffffff.", enemy, 255, 255, 255, true) end end addEventHandler ("onPlayerWasted", getRootElement(), increaseHP)
  23. There is afaik, it's MtaScriptingSchool or soemthing liek that, check this guy's channel, it helped me a lot back then: https://www.youtube.com/channel/UCzxhXI ... yAot6ALS_A
  24. If you want to use isElementInRange then you have to include this somewhere in your code: function isElementInRange(ele, x, y, z, range) if isElement(ele) and type(x) == "number" and type(y) == "number" and type(z) == "number" and type(range) == "number" then return getDistanceBetweenPoints3D(x, y, z, getElementPosition(ele)) <= range -- returns true if it the range of the element to the main point is smaller than (or as big as) the maximum range. end return false end I'll re-edit this code in a bit, gonna edit this post later EDIT: gate1 = createObject (975, -2685.5, 1274.8, 56.1, 0, 0, 180) gate1_open = false --You have to include this function isElementInRange(ele, x, y, z, range) if isElement(ele) and type(x) == "number" and type(y) == "number" and type(z) == "number" and type(range) == "number" then return getDistanceBetweenPoints3D(x, y, z, getElementPosition(ele)) <= range -- returns true if it the range of the element to the main point is smaller than (or as big as) the maximum range. end return false end addCommandHandler ("gate1", function () if (isElementInRange (localPlayer(), -2690.7, 1268.7, 55.95, 2) == true) then --Dunno if this works, I always did the range-check manually moveObject (gate1, 4000, -2695.5, 1274.8, 52.5) if (gate1_open == false) then --?! gate1_open = true--?! else--?! gate1_open = false--?! end else outputChatBox ("Stelle dich in den Wirk...", 255, 0, 0) end end ) the --?! I wrote them because I don't know why you wrote those, if you want to do something later with them then fine, but if this all you want they're useless
×
×
  • Create New...