Lloyd Logan Posted January 26, 2013 Posted January 26, 2013 Hey can I ask why this doesn't save the Elements position? function saved( thePlayer ) local playerName = getPlayerAccount( thePlayer ) if (playerName) then local position = getElementPosition( thePlayer ) if (position) then setAccountData( playerName, "positions", position) end end end function set( thePlayer, playerName ) if (playerName) then positions = getAccountData( thePlayer, "positions" ) if (positions) then setElementPosition( thePlayer, positions) end end end addEventHandler("onPlayerQuit", getRootElement(), saved) addEventHandler("onPlayerLogin", getRootElement(), set)
manve1 Posted January 26, 2013 Posted January 26, 2013 you have 'set' in ur event handler and function name, as it already is a function of MTA try changing it.
csiguusz Posted January 26, 2013 Posted January 26, 2013 You can change MTA function to whatever you want, so it should work. But the saving of the position is wrong, getElementPosition returns three values: local x, y, z = getElementPosition( thePlayer )
manve1 Posted January 26, 2013 Posted January 26, 2013 local playerName = getPlayerAccount( thePlayer ) function saved( thePlayer ) if (playerName) then local x, y, z = getElementPosition( thePlayer ) if (x, y, z) then setAccountData( playerName, "positions", x, y, z) end end end function setback( thePlayer, playerName ) if (playerName) then local xX, yY, zZ = getAccountData( thePlayer, "positions" ) if (xX, yY, zZ) then setElementPosition( thePlayer, xX, yY, zZ) end end end addEventHandler("onPlayerQuit", getRootElement(), saved) addEventHandler("onPlayerLogin", getRootElement(), setback)
Lloyd Logan Posted January 26, 2013 Author Posted January 26, 2013 local playerName = getPlayerAccount( thePlayer ) function saved( thePlayer ) if (playerName) then local x, y, z = getElementPosition( thePlayer ) if (x, y, z) then setAccountData( playerName, "positions", x, y, z) end end end function setback( thePlayer, playerName ) if (playerName) then local xX, yY, zZ = getAccountData( thePlayer, "positions" ) if (xX, yY, zZ) then setElementPosition( thePlayer, xX, yY, zZ) end end end addEventHandler("onPlayerQuit", getRootElement(), saved) addEventHandler("onPlayerLogin", getRootElement(), setback) ) expected near ',' line 5
manve1 Posted January 26, 2013 Posted January 26, 2013 local playerName = getPlayerAccount( thePlayer ) function saved( thePlayer ) if (playerName) then local x, y, z = getElementPosition( thePlayer ) if (x and y and z) then setAccountData( playerName, "positions", x, y, z) end end end function setback( thePlayer, playerName ) if (playerName) then local xX, yY, zZ = getAccountData( thePlayer, "positions" ) if (xX and yY and zZ) then setElementPosition( thePlayer, xX, yY, zZ) end end end addEventHandler("onPlayerQuit", getRootElement(), saved) addEventHandler("onPlayerLogin", getRootElement(), setback)
csiguusz Posted January 26, 2013 Posted January 26, 2013 Is it so hard to read the wiki about set and getAccountData before posting? You can just save one value, so only x coordinate will be saved. And getAccountData never will return three values. You have to use three setAccountDatas to store all three positions setAccountData( thePlayer, "posX", x ) setAccountData( thePlayer, "posY", y ) setAccountData( thePlayer, "posZ", z ) -- and do it so with get: local x = getAccountData( thePlayer, "posX" ) local y = getAccountData( thePlayer, "posY" ) local z = getAccountData( thePlayer, "posZ" )
Castillo Posted January 26, 2013 Posted January 26, 2013 Well, it can return three values or more if you split the string.
csiguusz Posted January 26, 2013 Posted January 26, 2013 Well, it can return three values or more if you split the string. It will still return one value, that you can split into more strings/values. Or do you know something that I don't?
Castillo Posted January 26, 2013 Posted January 26, 2013 Well, you can always save a JSON string, then convert it into a table and it would be more than one value. Like this: setAccountData ( account, "testData", toJSON ( { "Hello", "World" } ) ) Then you can get it like this: testData = fromJSON ( getAccountData ( account, "testData" ) ) outputChatBox ( testData [ 1 ] ) outputChatBox ( testData [ 2 ] ) Or you can use split function: setAccountData ( account, "testData", "Hello, World" ) testData = split ( getAccountData ( account, "testData" ), "," ) outputChatBox ( testData [ 1 ] ) outputChatBox ( testData [ 2 ] )
csiguusz Posted January 26, 2013 Posted January 26, 2013 Yes, I know this. You just said, that it can return more than one values. I know what did you mean, but I think its not true so -- I think returning more walues means this (correct me if I'm wrong): local a, b, c, d, e = getElementData( account, "something" ) -- but it returns one value, wich table for example wich can contains more values: local a = getElementData( account, "something" ) outputChatBox ( a[1] ) outputChatBox ( a[2] )
Castillo Posted January 26, 2013 Posted January 26, 2013 Yeah, well, I guess I didn't expressed myself right. You can return many values though, like this: test1, test2 = unpack ( fromJSON ( getAccountData ( account, "testData" ) ) )
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