Jump to content

playeraccount / accountdata


Absence2

Recommended Posts

Posted

Alright so I just entered this part, it's very new to me, including sqlite.

So I'm trying to save every stat a player has, money, skin, location, weapon, and so on..

So far, I've managed the money & skin. Though, the location is causing me problems.

I'm convinced I'm doing something wrong after 30 minutes of trying to figure it out :o

Alright, so this is what I got,

function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        local playerPos = getElementPosition ( source )          
        setAccountData(playerAccount, "money", playerMoney)      
        setAccountData(playerAccount, "skin", playerSkin) 
        setAccountData(playerAccount, "position", playerPos) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        local playerPos = tonumber(getAccountData(playerAccount, "position")) 
        if (playerMoney and playerSkin and playerPos) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
            setElementPosition ( source, playerPos )             
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

as I said, I'm new to sqlite, so I took it as I had to create a table, so I went to wiki and ended up with this

    executeSQLCreateTable ( "position", "x, y, z" ) 

I'm not really sure where the problem lays at >.< so, what to do? I suppose it's at the table, though I don't understand how to do it completely.

Note: this is my third topic about this within a minute, lol. Forums seems to be really slow or it's my internet, causing me to first create two topics by misstake, then delete those two by misstake :?

Posted

oh yes,

but I cannot add commas to line 20:

        if (playerMoney and playerSkin and x,y,z) then 

So I'm not really sure what to do with that one.

Posted

Oh yes, I did try that but didn't work. Syntax however is gone, but there's no "effect".

function onPlayerQuit() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) and not isGuestAccount(playerAccount) then 
        local playerMoney = getPlayerMoney(source) 
        local playerSkin = getElementModel(source) 
        local x,y,z = getElementPosition ( source )          
        setAccountData(playerAccount, "money", playerMoney)      
        setAccountData(playerAccount, "skin", playerSkin) 
        setAccountData(playerAccount, "position", x,y,z) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) 
    if (playerAccount) then 
        local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
        local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
        local x,y,z = tonumber(getAccountData(playerAccount, "position")) 
        if (playerMoney and playerSkin and x and y and z) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
            setElementPosition ( source, x,y,z )             
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
  
function createSQLOnStart () 
    executeSQLCreateTable ( "position", "x, y, z" ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) 

and that's how I trigger the table.. or whatever^

Posted
function onPlayerQuit ( ) 
    local playerAccount = getPlayerAccount ( source ) 
    if ( playerAccount ) and not isGuestAccount ( playerAccount ) then 
        local playerMoney = getPlayerMoney ( source ) 
        local playerSkin = getElementModel ( source ) 
        local x, y, z = getElementPosition ( source ) 
        setAccountData ( playerAccount, "money", playerMoney ) 
        setAccountData ( playerAccount, "skin", playerSkin ) 
        setAccountData ( playerAccount, "posX", x ) 
        setAccountData ( playerAccount, "posY", y ) 
        setAccountData ( playerAccount, "posZ", z ) 
    end 
end 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
  
function onPlayerLogin ( _, playerAccount ) 
    if ( not isGuestAccount ( playerAccount ) ) then 
        local playerMoney = tonumber ( getAccountData ( playerAccount, "money" ) ) or 0 
        local playerSkin = tonumber ( getAccountData ( playerAccount, "skin" ) ) or 0 
        local x = tonumber ( getAccountData ( playerAccount, "posX" ) ) or 0 
        local y = tonumber ( getAccountData ( playerAccount, "posY" ) ) or 0 
        local z = tonumber ( getAccountData ( playerAccount, "posZ" ) ) or 0 
        if ( playerMoney and playerSkin and x and y and z ) then 
            setPlayerMoney(source, playerMoney) 
            setElementModel(source, playerSkin) 
            setElementPosition ( source, x, y, z ) 
        end 
    end 
end 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 

Posted

I don't really get it,

so I have to create a table,

for an example:

  
function createSQLOnStart () 
    executeSQLCreateTable ( "posX", "x" ) 
    executeSQLCreateTable ( "posY", "y" ) 
    executeSQLCreateTable ( "posZ", "z" ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) 

So, this would do the trick? I tested few other ways, but didn't work. I suppose it's this what you mean by with no data. Currently, it keeps spawning me at location '0'.

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...