-
Posts
740 -
Joined
-
Days Won
16
Everything posted by Tails
-
Or loop an array of ids: local vehicleIds = {596, 597, 598, 599} function attachBlipToVehicle(vehicle) if getPedOccupiedVehicle(localPlayer) ~= vehicle then for i=1, #vehicleIds do if vehicleIds[i] == getElementModel(vehicle) then vehicleBlips[vehicle] = createBlipAttachedTo(vehicle, 0, 1, 150, 150, 150, 255, -10, 300) setBlipVisibleDistance(vehicleBlips[vehicle], 50) end end end end
-
Hello @Manic69, I made an airdrop script last year but never released it. I'm releasing it for you now It's basically this minus the car: https://streamable.com/ml57 You can also loot it, it has a loot table that you can modify in kits.lua. It spawns weapons. Download here: https://community.multitheftauto.com/index.php?p=resources&s=details&id=14549 Let me know what you think of it
-
You can't sort a named key table directly. You could do something like this: function getPoints() local points = {} for k,v in pairs(tops) do table.insert(points, {name = k, points = v.points}) end table.sort(points, function(a,b) return a.points < b.points end) return points end local points = getPoints() outputChatBox(points[1].name.." got the most points! Total: "..points[1].points)
-
@Gourmet. When I just started scripting I wrote this. You can't send the resources but you can send the data then display that in your gui. function getResourceData() local resources = {} local res = getResources() for k, resource in ipairs(res) do if getResourceInfo(resource, "type") ~= "map" then table.insert(resources, {name=getResourceName(resource), state=getResourceState(resource)}) end end triggerClientEvent("ResourcesTable", root, resources) end addEvent("ResourceList",true) addEventHandler("ResourceList",root,getResourceData) I'm assuming that's what you want.
-
Did you give your script acl rights?
-
You can't use unpack like that if you have other arguments coming after it. local pos = {100, 200, 300} setElementPosition(localPlayer, unpack(pos)) -- works setElementPosition(localPlayer, unpack(pos), false) -- won't work Nothing can come behind unpack() So try one of these methods instead: local x, y, w, h = unpack(loginPanelPos["globalPanel"]) guiCreateStaticImage(x, y, w, h, "LOGIN.png", false) -- or local pos = loginPanelPos["globalPanel"] guiCreateStaticImage(pos[1], pos[2], pos[3], pos[4], "LOGIN.png", false) I recommend the last one if you're doing it in a render because it is faster, performance wise.
-
That's not how you insert data into a table Check out this tutorial, https://www.tutorialspoint.com/lua/lua_tables.htm
- 14 replies
-
- setelementdata
- getelementdata
-
(and 2 more)
Tagged with:
-
You'll have to use triggers for that, or element data but I don't recommend that. Read here: https://wiki.multitheftauto.com/wiki/TriggerServerEvent For example, server-side: addEvent("getData", true) local someData = { {name = "alice", age = 20}, {name = "jack", age = 21}, {name = "jill", age = 18}, {name = "jones", age= 19}, } function getPlayerDataByName(name) for i=1, #someData do if someData[i].name == name then return someData[i] end end end addEventHandler("getData", resourceRoot, function(name) local data = getPlayerDataByName(name) triggerClientEvent("onGetServerData", resourceRoot, data) end ) And client-side: addEvent("onGetServerData", true) function getPlayerData(name) triggerServerEvent("getData", resourceRoot, name) end getPlayerData("alice") addEventHandler("onGetServerData", resourceRoot, function(data) iprint(data) end ) Something like that, untested
-
Read my post again, I edited it.
-
@andreiwow2 Just put the server and client function in a seperate file and add them to the meta. For example <meta> <script src="server.lua" type="server"/> <script src="client.lua" type="client"/> </meta> In shared files, the functions must both work for the client and server, in the mta functions, the server and clientside functions differ from each other, also your code might contain clientside or server code within the callback functions. It won't work like that. Eventhough it says shared on the wiki, just put them in the appropriate file, for whichever side you're working on.
-
I don't exactly know how your database looks but just try storing them like this: payphones = {} for i,row in ipairs(result) do payphones[i] = {pos = {row.PosX, row.PosY, row.PosZ}, number = row.Number} end You could also use your row id and put that as the index/key for i,row in ipairs(result) do payphones[row.id] = {pos = {row.PosX, row.PosY, row.PosZ}, number = row.Number} end Later you can get them by their index phone = payphones[4] blip = createBlip(phone.pos[1], phone.pos[2], phone.pos[3], 0) number = phone.number Hope this helps.
-
I'm not sure how that loop correlates with the first example, maybe you could show us how the table you're looping looks like? Also, I recommend you to check out this page https://en.wikibooks.org/wiki/Lua_Programming/Tables to learn about Lua tables.
-
Because the function doesn't exist. Copy the function over to your script. Anything under https://wiki.multitheftauto.com/wiki/Useful_Functions are functions made by users and aren't actual MTA functions.
-
I just tested your code and it seemed to work fine for me. I only added some entries to the players table and I could only see it for a second before it disappeared. But here's one example of how I would do it: local players = { {name = "Jack", ping = 22, fps = 59, country = "US"}, {name = "Jill", ping = 26, fps = 59, country = "US"}, } local offset = 20 addEventHandler("onClientRender", root, function() for i=1, #players do local item = players[i] if item then local y = offset * (i - 1) dxDrawText(item.name, 200, 302 + y), 847, 350, tocolor(255, 255, 255, 255), 1.50, "default", "left", "top", false, false, false, false, false) end end end )
-
Use the onClientVehicleEnter event. Something like this: addEventHandler("onClientVehicleEnter", root, function(plr) if plr == localPlayer then addEventHandler("onClientRender", root, draw) end end ) function draw() local veh = getPedOccupiedVehicle(localPlayer) if veh then ahudd() else removeEventHandler("onClientRender", root, draw) end end
-
Hello, I got trouble creating fonts in MTA. This is the error I'm getting: WARNING: [my]\[experiments]\terminal\client\terminal.lua:2: Error creating font @ 'create' [dos.ttf] There's nothing wrong with the font, in fact I'm using it in a different script and it works fine there. The problem I found is that VideoMemoryFreeForMTA is at 0. And the dxCreateFont wiki page states that failure is guaranteed when it's at 0. so this is the issue I need to resolve. I already restarted my computer and server but it didn't help. Any ideas?
-
@Sia Because addEventHandler is a function and you're writing the function within it. The argument in addEventHandler requires a function. You can either add a reference to your function or you can directly write your function as the argument. function printMessage() outputChatBox(getPlayerName(source).." Has Spawned") end addEventHandler("onClientPlayerSpawn", root, printMessage) -- put the function in here Or you could write it directly like so: addEventHandler( "onClientPlayerSpawn", root, function() -- write the function here directly outputChatBox( getPlayerName(source).." Has Spawned " ) end) -- or addEventHandler( "onClientPlayerSpawn", root, function() outputChatBox( getPlayerName(source).." Has Spawned " ) end ) -- however you prefer You see, it's an argument so you have to close the addEventHandler function with a ) .
-
I'm pretty sure you can't do that in singleplayer, so there's no magic setting to change that.
-
Check your FPS limit. If it's above 60 then it may cause problems. It's a known bug. try setting it to 60.
-
@Dutchman101 Thanks, we are aware of some of these bugs. I will try and deal with these bugs today if Loki has time as well (I can't test it alone either). If not, I might have a go at it this weekend. Also the code is so old that I don't really like any of the code anymore because nowadays I approach everything in a completely different way. So it's not as easy to find exactly where the bugs are. But yeah, thanks for reporting.
-
@kleinmarquez Ah, yeah. That's the downside of replacing objects in MTA. If you want you could change the objects ids though but you have to go and find an id that you want to replace. You can use the map editor to check the ids on objects in the world. Unpack the zip file and browse to the map folder and open TheCinema.map file with a text editor. Then replace the ids that you see in the first image. Then browse to the screen folder and open up screen.lua and change the ids to the ones you put in the in the map file. (see second image) Hope this helps. Sorry for any inconvenience.
-
You can attach objects to players with attachElements