Save money for next respawn
#1

Hi,
Can I 'save' the current player's money into a variable on the players death and give the player that money back when he respawns?
Thanks.
Reply
#2

pawn Код:
new DeathMoney[MAX_PLAYERS];

public OnPlayerDeath(playerid) {
     DeathMoney[playerid] = GetPlayerMoney(playerid);
     return 1;
}

public OnPlayerSpawn(playerid) {
     GivePlayerMoney(playerid,DeathMoney[playerid]);
     return 1;
}
//  Not tested :D?
Reply
#3

Hey, thanks, it works!
Is it also possible that the current player gets that money again when he disconnects and later reconnects to the server?
Reply
#4

yes.use dini or y_ini

https://sampforum.blast.hk/showthread.php?tid=175565 Y_Ini
https://sampforum.blast.hk/showthread.php?tid=50 Dini

to save onplayerdisconnect
and load the save onplayerconnect
Reply
#5

No, wait, the player keeps his money when he reconnects. But when the server shuts down and restarts, he has lost his money. Can I dump this variable into a file and then read it again?
Reply
#6

Yes its still required a file save system like dini or y_ini

so you can use OnGameModeExit Callback and resetplayermoney there but you must still use onplayerdisconnect to save there money and they reconnect to get there money but on OnGameModeExit make there money into 0 so as the ini file you made with the money you saved with dini or y_ini then ResetPlayerMoney.
Reply
#7

You need to save the players information when the server gets shutdown. If you created a stock function to save the players information, you can call it under the following function (example below):

pawn Код:
public OnGameModeExit()
     {
          foreach(Player, i) // Perform a loop for all players.
          {
               SavePlayerInformation(i); // Save all players' information.
          }
     }
     return 1;
}
Reply
#8

So that code dumps it into a file? Sorry, i'm not an expert.
Reply
#9

Go look at the tutorials board and find a tutorial on how to save a players information into a file- see if you can find one which uses SII or y_ini as those are better... You should understand how to do what you need to do.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)