Jump to content

Money Saving System


marty000123

Recommended Posts

Hello There

Everyone is killing zombies all the way to earn their money to buy some nice weapons from it.

But sometimes the server crashes, and all the resources are turning theirselves off.

So I need to start all the resources over again, but that ain't the biggest problem.

Every time when this happens, the money dissappears! I hate this, people are just losing their money.

Is there any way to save the money with a simple script or something like that?

Please help me out!

Greetings,

Marty

Link to comment

If you're using the default money system, you can use this code to save:

  
-- Server Side -- 
Money = {} 
addEventHandler ("onResourceStop",root, 
    function () 
        for i,v in ipairs (getElementsByType( 'player' ) do -- We get all players in-game 
            if getPlayerAccount (v) and not isGuestAccount( getPlayerAccount (v) ) then -- if they are all logged in 
                Money[i] = getPlayerMoney (v) -- get their money 
                setAccountData (getPlayerAccount(v),"Money",Money[i]) -- Save the money to their accounts data 
            end 
        end 
    end 
) 
  
-- to get the player's money just do getAccountData (theAccount,"Money") 
  

Link to comment

"onResourceStop" might not trigger if the server crash, it's better to use "onPlayerQuit", that works even if a player crash, it's also a good idea to save all player related date during intervals, say like each minute or so with a timer. "onResourceStop" will trigger whenever you restart or stop the resource or if you shut down the server the correct way.

Link to comment

this best way to save money, anyway read this to know more about Account

function savePlayersMoney( ) 
    if (getElementType(source) == "player") then 
        players = {source} 
    else 
        players  = getElementsByType("player") 
    end 
    for _, player in ipairs(players) do 
        local account = getPlayerAccount(player) 
        if  (account) and not (isGuestAccount(account)) then 
            local money = getPlayerMoney (player) 
            setAccountData(account, "Money", money) 
        end 
    end     
end 
addEventHandler ("onResourceStop", resourceRoot, savePlayersMoney) 
addEventHandler ("onPlayerQuit", root, savePlayersMoney) 
addEventHandler ("onPlayerLogout", root, savePlayersMoney) 
  
 function loadPlayersMoney( ) 
    if (getElementType(source) == "player") then 
        players = {source} 
    else 
        players  = getElementsByType("player") 
    end 
    for _, player in ipairs(players) do 
        local account = getPlayerAccount(player) 
        if (account) and not (isGuestAccount(account)) then 
            local money = getAccountData(account, "Money") or 0 
            setPlayerMoney(player, tonumber(money)) 
        end 
    end     
end 
addEventHandler ("onResourceStart", resourceRoot, savePlayersMoney) 
addEventHandler ("onPlayerLogin", root, savePlayersMoney) 

Link to comment

this delete moneys for all players on server

  
function deletemoney() 
for _, player in ipairs(players) do 
local account = getPlayerAccount(player) 
local money = getPlayerMoney (player) 
setAccountData(account, "Money", 0) 
end 
end 
addCommandHandler("deletemoney", deletemoney) 

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