Jump to content

Save money


Benevolence

Recommended Posts

This is the script.

function playerQuit() 
    local playeracc = getPlayerAccount(source) 
    if ( playeraccount == true ) then 
        local playercash = getPlayerMoney(source) 
        setAccountData(playeracc, "cash", playercash) 
    end 
end 
  
function playerLogin() 
    local playeracc = getPlayerAccount(source) 
    if (playeracc == true) then 
        local playerbank = getAccountData(playeracc, "cash") 
        if (playerbank == true) then 
            setPlayerMoney(source, playerbank) 
        else 
            outputChatBox("You are broke.", source, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), playerLogin) 
addEventHandler("onPlayerQuit", getRootElement(), playerQuit) 
addEventHandler("onPlayerLogout",root ,playerQuit) 

I am logged in. I set my money to like $555 for example then I disconnect and connect and then re-login. My money is 0. Why isn't this working?

  • Like 1
Link to comment
function playerQuit() 
    local playerAcc = getPlayerAccount(source) 
    if ( playerAcc  ) then -- You we're checking if (playeraccount == true) then, but your variable name is "playeracc". 
        local playerCash = getPlayerMoney(source) 
        setAccountData(playerAcc, "cash", playerCash) 
        setPlayerMoney(source, 0) 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), playerQuit) 
addEventHandler("onPlayerLogout", getRootElement(), playerQuit) 
  
function playerLogin() 
    local playerAcc = getPlayerAccount(source) 
    if (playerAcc) then 
        local playerBank = getAccountData(playerAcc, "cash") 
        if (playerBank) then 
            setPlayerMoney(source, tonumber(playerBank)) 
        else 
            outputChatBox("You are broke.", source, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onPlayerLogin", getRootElement(), playerLogin) 

  • Like 1
Link to comment

for more example

  
  
  
function onPlayerQuit ( ) 
      -- when a player leaves, store his current money amount in his account data 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in 
            local playermoney = getPlayerMoney ( source ) -- get the player money 
            setAccountData ( playeraccount, "piraterpg.money", playermoney ) -- save it in his account 
      end 
end 
  
function onPlayerLogin (_, playeraccount ) 
      -- when a player logins, retrieve his money amount from his account data and set it 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "your.money" ) 
            -- make sure there was actually a value saved under this key (check if playermoney is not false). 
            -- this will for example not be the case when a player plays the gametype for the first time 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) 
  
  
  
  
  
  

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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