Jump to content

Money save. Searched on wiki


bartje01

Recommended Posts

Posted

Hey guys. I searched on wiki already on how to save money.

I found something like ACL save but that is not what I need.

I want to know how to save player's money when they relog.

Can someone give me an example or wiki page that I need?|

Thanks

  • Discord Moderators
Posted

I don't think there's a wiki page with this exact purpose, however if you want this to work for dudes with an account only, use setAccountData.

Else use databases to store money amount along with player serial

Posted

wiki isn't containing all ready scripts (or solutions) how to solve your every idea..

events:

onPlayerQuit

onPlayerLogout (remember to set player money to zero after logout to avoid bug using!)

onPlayerLogin

functions:

getPlayerMoney

getPlayerAccount

isGuestAccount

getAccountData

setAccountData

setPlayerMoney

btw: isn't such script on community? i can remember several of them..

Posted (edited)

alright. I'm going to try. I don't think I will succeed. I hope one of you can script it for me but I don't want to ask a to big question :P

edit":

found this somewhere.

Doesn't work though

  
     
     
     
     
     
          function onPlayerQuit ( ) 
      -- when a player leaves, store his current money amount in his account data 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "savemoney.money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
      -- when a player joins, retrieve his money amount from his account data and set it 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "savemoney.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 ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 
  
  

Edited by Guest
Posted

ye I understand.

As in my edit;

I've got this:

  
     
     
     
     
     
          function onPlayerQuit ( ) 
      -- when a player leaves, store his current money amount in his account data 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "savemoney.money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
      -- when a player joins, retrieve his money amount from his account data and set it 
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "savemoney.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 ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 
  

just doesn't work.

Posted

remember to add onPlayerLogout event (and set money to zero) - as players can login - get they money, logout, (money will stay), spend money, login again to have money back..

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