stock SavePlayerData(playerid)
{
new File[200],pName[24],Float:armour,weap[13],ammo[13];
GetPlayerArmour(playerid,armour);
GetPlayerName(playerid,pName,24);
format(File,200,"FreeRoam/Users/%s.sav",pName);
//if(!IsPlayerConnected(playerid)) return false;
for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, weap[i], ammo[i]);
}
if(dini_Exists(File))
{
dini_IntSet(File,"Score",GetPlayerScore(playerid));
dini_IntSet(File,"Money",GetPlayerMoney(playerid));
dini_IntSet(File,"Skin",PlayerInfo[playerid][skin]);
dini_IntSet(File,"Spawn",PlayerInfo[playerid][spawn]);
dini_FloatSet(File,"Armour",armour);
dini_IntSet(File,"First Spawn",FirstSpawn[playerid]);
dini_IntSet(File,"Weap0",weap[0]); dini_IntSet(File,"Ammo0",ammo[0]);
dini_IntSet(File,"Weap1",weap[1]); dini_IntSet(File,"Ammo1",ammo[1]);
dini_IntSet(File,"Weap2",weap[2]); dini_IntSet(File,"Ammo2",ammo[2]);
dini_IntSet(File,"Weap3",weap[3]); dini_IntSet(File,"Ammo3",ammo[3]);
dini_IntSet(File,"Weap4",weap[4]); dini_IntSet(File,"Ammo4",ammo[4]);
dini_IntSet(File,"Weap5",weap[5]); dini_IntSet(File,"Ammo5",ammo[5]);
dini_IntSet(File,"Weap6",weap[6]); dini_IntSet(File,"Ammo6",ammo[6]);
dini_IntSet(File,"Weap7",weap[7]); dini_IntSet(File,"Ammo7",ammo[7]);
dini_IntSet(File,"Weap8",weap[8]); dini_IntSet(File,"Ammo8",ammo[8]);
dini_IntSet(File,"Weap9",weap[9]); dini_IntSet(File,"Ammo9",ammo[9]);
dini_IntSet(File,"Weap10",weap[10]); dini_IntSet(File,"Ammo10",ammo[10]);
dini_IntSet(File,"Weap11",weap[11]); dini_IntSet(File,"Ammo11",ammo[11]);
dini_IntSet(File,"Weap12",weap[12]); dini_IntSet(File,"Ammo12",ammo[12]);
SendClientMessage(playerid,lightblue,"Player Data Has Been Automatically Saved");
}
return 1;
}
new LoggedIn[MAXPLAYERS];
onplayerspawn = LoggedIn[playerid]
CMD:gmx(playerid, params[])
{
foreach(Player, i)
{
SaveStats();
LoggedIn[i] = 0;
SendClientMessage(playerid, -1, "SERVER: The server is being restarted.");
}
SendRconCommand("gmx");
return 1;
}
forward SaveStats();
public SaveStats() //this is a shell on how to do it replace playerid with i
{
Foreach(Player, i)
{
if(LoggedIn[i])
{
// https://sampforum.blast.hk/showthread.php?tid=273088// the disconnect stuff, replace playerid with i
new INI:File = INI_Open(UserPath(i));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",GetPlayerMoney(i));
INI_WriteInt(File,"Admin",PlayerInfo[i][pAdmin]);
INI_WriteInt(File,"Kills",PlayerInfo[i][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[i][pDeaths]);
INI_Close(File);
}
}
return 1;
}
https://sampforum.blast.hk/showthread.php?tid=273088
pawn Code:
|
stock gmx()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SavePlayerData(i); // save the player's account
Kick(i); // and then kick the player
}
}
SendRconCommand("gmx");
}
I had already thought of that but what if the server would crash? Then they wouldn't save.
|
new GMX = 0;//On top of script
CMD:gmx(playerid, params[])
{
//blah blah
GMX = 1;
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
SavePlayerData(i);
}
}
}
public OnPlayerDisconnect(playerid)
{
if(GMX == 0)
{
SavePlayerData(playerid);
}
return 1;
}