Jump to content

Saving money not working?


littlejth

Recommended Posts

Does someone know why this may not be working, this is the example from the wiki that I am trying to use:

function onPlayerQuit ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
............. 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 

Link to comment
Does someone know why this may not be working, this is the example from the wiki that I am trying to use:

function onPlayerQuit ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
............. 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 

You just should have to save

            setAccountData ( playeraccount, "money", playermoney ) 

in another file.

And for the onPlayerJoin part the sever have to know who the player is. And how many money he or she has.

Maybe try getClientName or something.

Link to comment

Hookerkiller, you obviously haven't got the foggiest idea of what you're saying. Shut up until you know what you're talking about.

As for you, littlejth,

1) Don't listen to thehookerkiller

2) You need to give us more info. Error messages and warnings (the entire message) and the lines they indicate.

Link to comment

I think this part is giving you trouble...

function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 

Because most probably, when a player joins, he still is on a guest account. (which doesn't have any account data)

I guess this might make it work, not sure, but worth a try I guess... (I think you can remove onPlayerJoin if you use this)

function onClientLogin ( previous, new ) 
      if new and not isGuestAccount ( new ) then -- Just added this to be sure 
            local playermoney = getAccountData ( new, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
addEventHandler ( "onClientLogin", getRootElement ( ), onClientLogin ) 

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