Archinet Posted October 3, 2019 Posted October 3, 2019 (edited) Hello guys of this excelent forum, im trying to get the GetElementPosition of my player inside a table PlayerData to store it after in a database, but no works, im not expert in Lua really, but i try to make it works, i search on the forum about this but i find nothing, i hope someone can help. function savePlayer() if(isElement(source)) then if(getElementData(source, "Logueado") == false) then return true end local playerData = { x = getElementPosition(source).x, -- Here "Attempt to index a numbe value. y = getElementPosition(source).y, z = getElementPosition(source).z, rx = getElementRotation(source).rx, ry = getElementRotation(source).ry, rz = getElementRotation(source).rz, dinero = getPlayerMoney(source), trabajo = getElementData(source, "trabajo"), repartidor_nivel = getElementData(source, "repartidor_nivel"), repartidor_puntos = getElementData(source, "repartidor_puntos") } for k,v in ipairs(playerData) do print(k.." - "..v) end end end addEventHandler("onPlayerQuit", getRootElement(), savePlayer) Edited October 3, 2019 by Archinet
Moderators IIYAMA Posted October 3, 2019 Moderators Posted October 3, 2019 local x, y, z = getElementPosition(source) local xr, yr, zr = getElementRotation(source) local playerData = {x=x, y=y, z=z, xr=xr, yr=yr, zr=zr} Those 2 functions do not return a table, but multiple variables. 4 hours ago, Archinet said: GetElementPosition of my player inside a table PlayerData 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Archinet Posted October 3, 2019 Author Posted October 3, 2019 (edited) 8 hours ago, IIYAMA said: local x, y, z = getElementPosition(source) local xr, yr, zr = getElementRotation(source) local playerData = {x=x, y=y, z=z, xr=xr, yr=yr, zr=zr} Those 2 functions do not return a table, but multiple variables. Thanks so much @IIYAMA is good way! what you think about this method? is bad practice? i still learning function pack(...) return {...} end pos = pack(getElementPosition(source)) playerData = { x = pos[1], y = pos[2], z = pos[3] } Edited October 3, 2019 by Archinet 1
Moderators IIYAMA Posted October 3, 2019 Moderators Posted October 3, 2019 1 minute ago, Archinet said: Thanks so much @IIYAMA is good way, i was testing this method? is bad practice? i still learning function pack(...) return {...} end pos = pack(getElementPosition(source)) playerData = { x = pos[1], y = pos[2], z = pos[3], } Creating a new table is a slower method, but nothing to worry about. You wouldn't notice the difference with the computers these days. You didn't need the pack function to do this: local pos = {getElementPosition(source)} But if it helps you with readability, then why not a pack function? 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Archinet Posted October 3, 2019 Author Posted October 3, 2019 1 minute ago, IIYAMA said: Creating a new table is a slower method, but nothing to worry about. You wouldn't notice the difference with the computers these days. You didn't need the pack function to do this: local pos = {getElementPosition(source)} But if it helps you with readability, then why not a pack function? I din't know that i can store with this method local pos = {getElementPosition(source)} Thanks for help me 1
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