Jump to content

save Data


Lloyd Logan

Recommended Posts

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) 

Link to comment
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) 

Link to comment
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

Link to comment
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) 

Link to comment

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" )  

Link to comment

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 ] ) 

Link to comment

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] ) 
  

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...