Save money for next respawn - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Save money for next respawn (
/showthread.php?tid=273352)
Save money for next respawn -
Superthijs - 01.08.2011
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.
Re: Save money for next respawn -
Kitten - 01.08.2011
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?
Re: Save money for next respawn -
Superthijs - 01.08.2011
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?
Re: Save money for next respawn -
Kitten - 01.08.2011
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
Re: Save money for next respawn -
Superthijs - 01.08.2011
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?
Re: Save money for next respawn -
Kitten - 01.08.2011
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.
Re: Save money for next respawn -
Scenario - 01.08.2011
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;
}
Re: Save money for next respawn -
Superthijs - 01.08.2011
So that code dumps it into a file? Sorry, i'm not an expert.
Re: Save money for next respawn -
Scenario - 02.08.2011
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.