NoviceWithManyProblems Posted May 2, 2020 Share Posted May 2, 2020 (edited) Hi, how can I insert "userdata" to table? This doesn't work. someTable = {} table.insert(v) "v" are elements from the "for" loop outputChatBox(type(v)) outputChatBox(inspect(v)) output: userdata elem:object[1220]0x1332b or how can I trigger table with this objects? Edited May 2, 2020 by NoviceWithManyProblems Link to comment
Scripting Moderators ds1-e Posted May 2, 2020 Scripting Moderators Share Posted May 2, 2020 (edited) 1 hour ago, NoviceWithManyProblems said: You didn't passed table. I prefer adding elements manually. local someTable = {} local somePed = createPed(11, 0, 0, 3) -- 1st way, ped will be accessible via number, mostly you will need to loop whole table if there's more elements someTable[#someTable + 1] = somePed print(tostring(someTable[1])) -- output: ped userdata -- 2nd way, ped will be accessible via reference someTable[somePed] = somePed print(tostring(someTable[somePed])) -- output: ped userdata Edited May 2, 2020 by majqq 1 1 Link to comment
NoviceWithManyProblems Posted May 2, 2020 Author Share Posted May 2, 2020 ok. thx, but look at this: local peds = { {...}, {...} } for k,v in ipairs(peds) do createPed(...) setElementData(v, "created", true) setElementData(v, "name", v[5]) -- eg. "bobby" end for k,v in ipairs(getElementsByType("ped") do if getElementData(v, "created") then pedsToTrigger = {} table.insert(pedsToTrigger, v) triggerClientEvent(thePlayer, "someEvent", resourceRoot, pedsToTrigger) end end -- client side addEvent("someEvent", true) addEventHandler("someEvent", resourceRoot, function(pedsToTrigger) -- some gui functions pedGridList = guiCreateGridList(0, 0, 50, 50, false) if pedsToTrigger then for _,v in ipairs(pedsToTrigger) do guiGridListAddRow(pedGridList, getElementData(v, "name")) end end end) why this creates me two separate gridlist instead of introducing them to one? it looks like this: Link to comment
Scripting Moderators ds1-e Posted May 2, 2020 Scripting Moderators Share Posted May 2, 2020 (edited) 28 minutes ago, NoviceWithManyProblems said: why this creates me two separate gridlist instead of introducing them to one? You don't check if this gridlist exists. About this part of code, you are destroying your server network. for k,v in ipairs(getElementsByType("ped") do if getElementData(v, "created") then pedsToTrigger = {} table.insert(pedsToTrigger, v) triggerClientEvent(thePlayer, "someEvent", resourceRoot, pedsToTrigger) end end Trigger will be called 1 * count of peds, it's very bad. Because it could be done with just 1 trigger. -- Client local pedsGridlist = false -- function customEvent(serverTable) if not pedsGridlist then pedsGridlist = guiCreateGridList(200, 100, 50, 50, false) end -- Finish your code end addEvent("customEvent", true) addEventHandler("customEvent", resourceRoot, customEvent) local peds = { {11, 0, 0, 3, "NPC 1"}, {11, 0, 0, 4, "NPC 2"}, } -- function createPeds() local ped = false local pedData = false local dataToSend = {} for i = 1, #peds do pedData = peds[i] ped = createPed(pedData[1], pedData[2], pedData[3], pedData[4]) dataToSend[#dataToSend + 1] = {ped, pedData[5]} end setTimer(function() triggerClientEvent(root, "customEvent", resourceRoot, dataToSend) end, 1000, 1) end addEventHandler("onResourceStart", resourceRoot, createPeds) Edited May 2, 2020 by majqq Fix 1 Link to comment
Moderators IIYAMA Posted May 2, 2020 Moderators Share Posted May 2, 2020 48 minutes ago, NoviceWithManyProblems said: why this creates me two separate gridlist instead of introducing them to one? Because you are creating for each event a new gridlist. The following code will create a gridlist if it does not exist if not pedGridList then pedGridList = guiCreateGridList(0, 0, 50, 50, false) end 1 Link to comment
NoviceWithManyProblems Posted May 2, 2020 Author Share Posted May 2, 2020 thank you all guys! 1 Link to comment
NoviceWithManyProblems Posted May 2, 2020 Author Share Posted May 2, 2020 (edited) i fixed that. Edited May 2, 2020 by NoviceWithManyProblems i fixed that Link to comment
Moderators Patrick Posted May 2, 2020 Moderators Share Posted May 2, 2020 5 minutes ago, NoviceWithManyProblems said: I have one more issue... 1 Link to comment
NoviceWithManyProblems Posted May 2, 2020 Author Share Posted May 2, 2020 Thanks, but I fixed that by myself Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now