marty000123 Posted November 15, 2014 Share Posted November 15, 2014 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
AJXB Posted November 15, 2014 Share Posted November 15, 2014 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
N1kS Posted November 15, 2014 Share Posted November 15, 2014 aboudmad, sry mate. /del Link to comment
Mr_Moose Posted November 15, 2014 Share Posted November 15, 2014 "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
WASSIm. Posted November 15, 2014 Share Posted November 15, 2014 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
AJXB Posted November 15, 2014 Share Posted November 15, 2014 aboudmad, sry mate./del Problem? Link to comment
StreetSaintz Posted November 18, 2014 Share Posted November 18, 2014 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 Link to comment
WASSIm. Posted November 18, 2014 Share Posted November 18, 2014 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 ? Link to comment
StreetSaintz Posted November 19, 2014 Share Posted November 19, 2014 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 Link to comment
boro Posted November 20, 2014 Share Posted November 20, 2014 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
StreetSaintz Posted November 21, 2014 Share Posted November 21, 2014 i get this error [20:43:44] ERROR: para\parasil.lua:2: bad argument #1 to 'ipairs' (table expecte d, got nil) Link to comment
AJXB Posted November 21, 2014 Share Posted November 21, 2014 Yeah just add on the second line: players = getElementsByType ('player') Link to comment
StreetSaintz Posted November 21, 2014 Share Posted November 21, 2014 Yeah just add on the second line: players = getElementsByType ('player') ye that fixed he error but for some reason it doesn't want to delete the money Link to comment
AJXB Posted November 21, 2014 Share Posted November 21, 2014 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now