Jump to content

Money Saving System


marty000123

Recommended Posts

Posted

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

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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") 
  

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

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

Posted

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) 

Omerta Roleplay

Posted
aboudmad, sry mate.

/del

Problem?

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted
sorry for reposting in this topic but i have a question about if it is possible to delete all money in the server like /setAccountData deleteALL money

you mean remove all account data from key by command ?

Omerta Roleplay

Posted
sorry for reposting in this topic but i have a question about if it is possible to delete all money in the server like /setAccountData deleteALL money

you mean remove all account data from key by command ?

sort of, i just want to delete all cash in server

Posted

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) 

I'll help When I Can.

Posted

Yeah just add on the second line: players = getElementsByType ('player')

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

How are you saving the money?

If you're not saving, use this code:

  
for i,v in ipairs (getElementsByType('players')) do 
setPlayerMoney (v,0) 
end 
  

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

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