Jump to content

Moeny saving


bartje01

Recommended Posts

Hey guys,. Sorry that I'm asking something again but I want to save money but it doesn't work

I've got no errors

  
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 onPlayerLogin ( ) 
      -- 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 ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 
  

Please help

Link to comment

When a player logins it can't retrieve the account data because it is only set when he quits from server so you should try 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 onPlayerLogin ( ) 
      -- 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 ) 
            else 
                  setPlayerMoney ( source, 0 ) -- if it cant retrieve data set it to 0 
            end 
      end 
end 
  
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 
  

Link to comment
Hey guys,. Sorry that I'm asking something again but I want to save money but it doesn't work

I've got no errors

  
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 onPlayerLogin ( ) 
      -- 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 ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) 
  

Please help

use this

  
function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) 
  if  not (isGuestAccount (getPlayerAccount (source))) then 
    local accountData = getAccountData (theCurrentAccount, "savemoney.money") 
    if (accountData) then 
      local playerMoney = getAccountData (theCurrentAccount, "savemoney.money") 
      setPlayerMoney (source, playerMoney) 
    end    
  end 
end 
addEventHandler ("onPlayerLogin", getRootElement(), playerLogin) 
  
function onQuit (quitType, reason, responsibleElement) 
  if not (isGuestAccount (getPlayerAccount (source))) then 
    account = getPlayerAccount (source) 
    if (account) then 
      setAccountData (account, "savemoney.money", tostring (getPlayerMoney (source))) 
    end 
  end 
end 
addEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
  

Link to comment

i don't think this will work in race because the race game mode will spawn your player at the start of the race and the maps change all the time so you could spawn your player outside of the map if you get what im trying to explain,

in other words if you do manage to get this to work then say i join your server on map A and logout then it will save my position and then if map B started then ill spawn in the same place where i was on map A and i would be out of the race.

theres probably another way to do this but i don't know how you would do it whilst the maps are changing sorry.

Link to comment

Aaah proracer. I see. I already noticed that there was no money bar in the right cornor of the game.

But can you please give an example on how to do this? Or send me the right wiki page?

Because when I know how to make element data cash I can do much more.

Link to comment

Ok you can try this but I'm not sure if it will work...

function onLoginSetCash ( ) 
    if not isGuestAccount ( getPlayerAccount ( source ) ) then 
        if getElementData ( source, "data.cash" ) then 
            outputChatBox ( "You're cash is transfered back!", source ) 
        else 
            setElementData ( source, "data.cash", 0 ) 
            outputChatBox ( "You're new and your cash will now be saved." ) 
        end 
    end 
end 
  
function onWastedSetCash ( ) 
    if not isGuestAccount ( getPlayerAccount ( source ) ) then 
        local getPlayerCash = getElementData ( source, "data.cash" ) 
        setElementData ( source, "data.cash", getPlayerCash + 100 ) 
        outputChatBox ( "You got 100$ for your death.", source ) 
    end 
end 
  
addEventHandler ( "onPlayerLogin", root, onLoginSetCash ) 
addEventHandler ( "onPlayerWasted", root, onWastedSetCash ) 

Edited by Guest
Link to comment

Alright. It shows me the outputchatbox texts.

But will this save? Even when I reconnect?

And can someone help me making the cmd to check my cash?

I tried:

  
function myCash ( thePlayer, commandName ) 
  
    local cash = getPlayerCash ( thePlayer ) 
  
    outputChatBox ( "Your cash is: " .. cash, thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 
  

And failed. No message shows up when I type /cash

Thank you very much Proracer

Link to comment

Thanks for helping but,

We're using element data cash now.

You can see that in the posts above.

I've edited it to this now

function myCash ( thePlayer ) 
  
    local cash = getPlayerCash ( thePlayer ) 
  
    outputChatBox ( "Your cash is: " .. tostring ( cash ), thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 

Just no message shows up

Link to comment

sorry ignore my other post i didn't read it properly,

if the script proracer put was right then i think to make the command would be:

  
function myCash ( thePlayer ) 
      local cash = getElementData ( thePlayer, "data.cash" ) --sorry my bad i put source instead of thePlayer 
      outputChatBox ( "Your cash is: " .. tostring ( cash ), thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 
  
  

edited from The Kid, maybe im wrong.

Edited by Guest
Link to comment
  • Moderators

Replace by this ?:

function myCash ( thePlayer, commandName ) 
      local cash = getElementData ( thePlayer, "data.cash" ) 
      outputChatBox ( "Your cash is: " .. tostring( cash ), thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 

If you have this message again "Your cash is: false" it's because this elementData doesn't exist for this player

Link to comment

[2011-03-06 23:18:16] WARNING: testmode\server.lua:25: Bad argument @ 'getElementData'

And it must be there.

My whole script

  
function onLoginSetCash ( ) 
    if not isGuestAccount ( getPlayerAccount ( source ) ) then 
        if getElementData ( source, "data.cash" ) then 
            outputChatBox ( "You're cash is transfered back!", source ) 
        else 
            setElementData ( source, "data.cash", 0 ) 
            outputChatBox ( "You're new and your cash will now be saved." ) 
        end 
    end 
end 
  
function onWastedSetCash ( ) 
    if not isGuestAccount ( getPlayerAccount ( source ) ) then 
        local getPlayerCash = getElementData ( source, "data.cash" ) 
        setElementData ( source, "data.cash", getPlayerCash + 100 ) 
        outputChatBox ( "You got 100$ for your death.", source ) 
    end 
end 
  
addEventHandler ( "onPlayerLogin", root, onLoginSetCash ) 
addEventHandler ( "onPlayerWasted", root, onWastedSetCash ) 
  
  
function myCash ( thePlayer ) 
      local cash = getElementData ( source, "data.cash" ) 
      outputChatBox ( "Your cash is: " .. tostring ( cash ), thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 
  

Link to comment
  • Moderators

Yeah try with this:

function myCash ( thePlayer, commandName ) 
      local cash = getElementData ( thePlayer, "data.cash" ) 
      outputChatBox ( "Your cash is: " .. tostring( cash ), thePlayer ) 
end 
addCommandHandler ( "cash", myCash ) 

And tell me the result.

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