COMMAND:restart(playerid, params[])
{
new
File[50],
string[128];
if(PVar[playerid][AuthLvl] <= 4) return AuthError(playerid, 5);
print("[PROCESS: RESTART - STARTING]");
printf("[-] Saving %d player file(s)", global_ConnectedPlayers);
for(new i = 0; i < global_ConnectedPlayers; i++)
{
if(IsPlayerConnected(i))
{
format(File, sizeof(File), PFiles, GetTheirName(i));
GetPlayerPos(i, PVar[i][LastX], PVar[i][LastY], PVar[i][LastZ]);
GetPlayerFacingAngle(playerid, PVar[playerid][LastRot]);
GetPlayerHealth(playerid, PVar[playerid][LastHealth]);
GetPlayerArmour(playerid, PVar[playerid][LastArmour]);
PVar[playerid][Interior] = GetPlayerInterior(playerid);
PVar[playerid][Cash] = GetPlayerMoney(playerid);
djSetInt (File, "Interior", PVar[playerid][Interior]);
djSetInt (File, "Kills", PVar[i][Kills]);
djSetInt (File, "Deaths", PVar[i][Deaths]);
djSetInt (File, "Authorization", PVar[i][AuthLvl]);
djSetInt (File, "Cash", PVar[i][Cash]);
djSetInt (File, "BankMoney", PVar[i][BankMoney]);
djSetInt (File, "BankAccount", PVar[i][BankAccount]);
djSetInt (File, "BankSavings", PVar[i][BankSavings]);
djSetInt (File, "BankPIN", PVar[i][BankPIN]);
djSetInt (File, "Skin", PVar[i][Skin]);
djSetInt (File, "Age", PVar[i][Age]);
djSetInt (File, "PhoneNumber", PVar[i][PhoneNumber]);
djSetInt (File, "Faction", PVar[i][Faction]);
djSetInt (File, "FactionRank", PVar[i][FRank]);
djSetInt (File, "VIPLevel", PVar[i][VIPLevel]);
djSetInt (File, "Job", PVar[i][Job]);
djSetInt (File, "Materials", PVar[i][Materials]);
djSetInt (File, "Drugs", PVar[i][Drugs]);
djSetInt (File, "JoinLeaveDisplay", PVar[i][JoinLeaveDisplay]);
djSetInt (File, "DeathDisplay", PVar[i][DeathDisplay]);
djSetFloat (File, "LastX", PVar[i][LastX]);
djSetFloat (File, "LastY", PVar[i][LastY]);
djSetFloat (File, "LastZ", PVar[i][LastZ]);
djSetFloat (File, "LastRot", PVar[playerid][LastRot]);
djSetFloat (File, "LastArmour", PVar[playerid][LastArmour]);
djSetFloat (File, "LastHealth", PVar[playerid][LastHealth]);
djSetInt (File, "Player_Record_Kicks", PVar[playerid][PRecord_Kicks]);
djSetInt (File, "Player_Record_Bans", PVar[playerid][PRecord_Bans]);
djSetInt (File, "Player_Record_Jails", PVar[playerid][PRecord_Jails]);
djSetInt (File, "Player_Record_Mutes", PVar[playerid][PRecord_Mutes]);
djSetInt (File, "Level", PVar[i][Level]);
djSetInt (File, "Experience", PVar[i][Experience]);
djSetInt (File, "PlayingHours", PVar[i][PlayingHours]);
//printf("[save] %s position: %f, %f, %f", GetTheirName(playerid), PVar[playerid][LastX], PVar[playerid][LastY], PVar[playerid][LastZ]);
printf("[%d] %s has been saved.", i, GetTheirName(i));
Delete3DTextLabel(NameTag[i]);
}
}
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}Successfully saved {0FA0D1}%d {FFFFFF}user file(s).", global_ConnectedPlayers);
SendClientMessageToAll(-1, string);
ServerHasJustBeenRestarted = 1;
print("[PROCESS: RESTART - COMPLETE]");
GameModeExit();
return 1;
}
Originally Posted by leong124
Basically if you save the player data properly in OnPlayerDisconnect it should be fine.
|
public SaveUserData(playerid)
{
new name[MAX_PLAYER_NAME], file[128];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), UserFile, name);
if(gPlayerLogged[playerid] == 1)
{
if(fexist(file))
{
PlayerInfo[playerid][pActivity] = GetPlayerScore(playerid);
PlayerInfo[playerid][pVirtualWorld] = GetPlayerVirtualWorld(playerid);
PlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
djSetInt(file, "Money", PlayerInfo[playerid][pMoney]);
new Float:Health;
GetPlayerHealth(playerid, Health);
djSetFloat(file, "Health", floatround(Health));
new Float:Armour;
GetPlayerArmour(playerid, Armour);
djSetFloat(file, "Armour", floatround(Armour));
djSetInt(file, "Activity", PlayerInfo[playerid][pActivity]);
djSetInt(file, "Job", PlayerInfo[playerid][pJob]);
djSetInt(file, "Duty", PlayerInfo[playerid][pDuty]);
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
djSetFloat(file, "PosX", (x));
djSetFloat(file, "PosY", (y));
djSetFloat(file, "PosZ", (z));
djSetInt(file, "VirtualWorld", PlayerInfo[playerid][pVirtualWorld]);
djSetInt(file, "Interior", PlayerInfo[playerid][pInterior]);
djSetInt(file, "Weapon1", PlayerInfo[playerid][pWeapon1]);
djSetInt(file, "Weapon2", PlayerInfo[playerid][pWeapon2]);
djSetInt(file, "Weapon3", PlayerInfo[playerid][pWeapon3]);
djSetInt(file, "Weapon4", PlayerInfo[playerid][pWeapon4]);
djSetInt(file, "Weapon5", PlayerInfo[playerid][pWeapon5]);
djSetInt(file, "Weapon6", PlayerInfo[playerid][pWeapon6]);
djSetInt(file, "Weapon7", PlayerInfo[playerid][pWeapon7]);
djSetInt(file, "Weapon8", PlayerInfo[playerid][pWeapon8]);
djSetInt(file, "Weapon9", PlayerInfo[playerid][pWeapon9]);
djSetInt(file, "Weapon10", PlayerInfo[playerid][pWeapon10]);
djSetInt(file, "Weapon11", PlayerInfo[playerid][pWeapon11]);
djSetInt(file, "Weapon12", PlayerInfo[playerid][pWeapon12]);
djSetInt(file, "Ammo1", PlayerInfo[playerid][pAmmo1]);
djSetInt(file, "Ammo2", PlayerInfo[playerid][pAmmo2]);
djSetInt(file, "Ammo3", PlayerInfo[playerid][pAmmo3]);
djSetInt(file, "Ammo4", PlayerInfo[playerid][pAmmo4]);
djSetInt(file, "Ammo5", PlayerInfo[playerid][pAmmo5]);
djSetInt(file, "Ammo6", PlayerInfo[playerid][pAmmo6]);
djSetInt(file, "Ammo7", PlayerInfo[playerid][pAmmo7]);
djSetInt(file, "Ammo8", PlayerInfo[playerid][pAmmo8]);
djSetInt(file, "Ammo9", PlayerInfo[playerid][pAmmo9]);
djSetInt(file, "Ammo10", PlayerInfo[playerid][pAmmo10]);
djSetInt(file, "Ammo11", PlayerInfo[playerid][pAmmo11]);
djSetInt(file, "Ammo12", PlayerInfo[playerid][pAmmo12]);
}
}
return 1;
}
//Try these
public OnGameModeExit()
{
for(new i = 0; i<MAX_PLAYERS;i++)
{
SaveUserData(i);
}
return 1;
}