Jump to content

setAccountData, key..


Chris!i!

Recommended Posts

setAccountData is actually the same construct as setElementData, it just gets saved into the account from the player. The player has to be logged in before this'll work. The parameters are as following:

account theAccount, string key, mixed value 

Meaning that theAccount would be the account gotten with getPlayerAccount, the key is something you made up and the value is the actual value you want to give it. A few examples can be;

local playerAccount = getPlayerAccount ( thePlayer ) 
setAccountData ( playerAccount, "username", "John" ) 
setAccountData ( playerAccount, "password", "Doe" ) 
setAccountData ( playerAccount, "email", "[email protected]" ) 

Link to comment
function onPlayerQuit() 
      local playeraccount = getPlayerAccount(source) 
       if (playerAccount) then 
            local walk = getPedWalkingStyle(source)  
            setAccountData(playeraccount, "walkingstyle", walk)  
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- add an event handler 
---------------------------------------------------- 
---------------------------------------------------- 
function onPlayerLogin() 
    local playerAccount = getPlayerAccount(source) -- get his account 
      if (playerAccount) then 
            local walk = getAccountData(playerAccount, "walkingstyle") 
            if (walk) then 
                  setPedWalkingStyle(source, walk) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Ok what should i do know since i didnt understand anything.

Link to comment

setAccountData(playerAccount, "piraterpg.money", playerMoney)

Here, 'piraterpg.money' is a key and 'playerMoney' money is a value.

The key can have any name 'acb', '12jsdhi', 'MyMoney', etc..

And the value can have things like player's weapon, money, position, rotation, health state, etc..

You can think of keys as variables and values as definitions.

Example:-

So lets say a player have $1650 cash when he quit the game.

And you want to give player the amount of money he left the game with, which is $1650, when he join the game again.

So when he quit, you would save his money by doing

  
playerMoney = getPlayermoney(player) -- player's money which is 1650 
playerAccount = getPlayerAccount(player) -- player's account 
setAccountData(playerAccount,"poorPlayerMoney",playerMoney) -- save player's money to his account with key 'poorPlayerMoney' 
  

And when he join, you would load his money by doing

  
playerAccount = getPlayerAccount(player) -- player's account 
playerMoney = getAccountData(playerAccount,"poorPlayerMoney") -- will return 1650 
givePlayerMoney(player, playerMoney) -- will give 1650 to player 
  

And I added comments to your last code.

  
function onPlayerQuit_handler() 
    local playerAccount = getPlayerAccount(source) -- get player account 
    if (playerAccount) then -- if player has an account or account exist 
        local walk = getPedWalkingStyle(source) -- get the current walking style of player and set it to variable 'walk'. 
    setAccountData(playerAccount, "walkingstyle", walk) -- save/set player's walking style in player's account [data] with key 'walkingstyle' 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit_handler) -- trigger the function when player quit 
---------------------------------------------------- 
---------------------------------------------------- 
function onPlayerLogin_handler() 
    local playerAccount = getPlayerAccount(source) -- get player account 
    if (playerAccount) then -- if player has an an account or account exist 
        local walk = getAccountData(playerAccount, "walkingstyle") -- load/get player's walking style with key 'walkingstyle' which was previously saved in his account 
        if (walk) then -- if player's account data exist with key 'walkingstyle' or succesfully got player's  account data with key 'walkingstyle 
            setPedWalkingStyle(source, walk) -- set player's walking style to it(previous one) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin_handler) -- trigger the function when player login 
  

Hope it helps.

Edited by Guest
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...