PDA

View Full Version : Saving


Xerli
10/11/2012, 06:19 AM
Well i looked at multiple threads about this problem and tried to add code to make it work, Some of it compiled successfully but still did not work in-game. My problem is that the server only saves the player stats when they log out before restart but if they stay logged in during the restart they're stats get reset. I don't know where it is saving the files if it saving them at all i guess, I also don't know if there is any type of GMX to be heard of. Here is some code that i think is needed.

OnPlayerDisconnect:

public OnPlayerDisconnect(playerid, reason)
{
if(IsPlayerNPC(playerid))
{
IsSpawned[playerid] =0;
return 1;
}
if(afktag[playerid] == 1)
{
new pname[16];
GetPlayerName(playerid,pname,16);
strdel(pname, strlen(pname)-5, strlen(pname));
afktag[playerid] =0;
SetPlayerName(playerid,pname);
}
new string[128];
new pname[24];
GetPlayerName(playerid,pname,sizeof(pname));

//Save Wanted Level && Jailtime
SavedWantedLevel[playerid] =GetPlayerWantedLevel(playerid);
SavedJailTime[playerid] =JailTime[playerid];

if(PLAYERLIST_authed[playerid] == 1)
{
dUserSetINT(PlayerName(playerid)).("Bankcash",BankCash[playerid]);
dUserSetINT(PlayerName(playerid)).("Cash",GetPlayerMoney(playerid));
dUserSetINT(PlayerName(playerid)).("Score",GetPlayerScore(playerid));
dUserSetINT(PlayerName(playerid)).("Adminlevel",AdminLevel[playerid]);
dUserSetINT(PlayerName(playerid)).("Army",CanUseArmy[playerid]);
dUserSetINT(PlayerName(playerid)).("CIA",CanUseCIA[playerid]);
dUserSetINT(PlayerName(playerid)).("RegularPlayer",IsRegularPlayer[playerid]);
dUserSetINT(PlayerName(playerid)).("DrugHouseOwner",DrugHouseOwner[playerid]);
dUserSetINT(PlayerName(playerid)).("OttoOwner",OttoOwner[playerid]);
dUserSetINT(PlayerName(playerid)).("TSkill",TerroristSkill[playerid]);
dUserSetINT(PlayerName(playerid)).("RobSkill",RobSkill[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackC4",HasPackC4[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackRope",HasPackRope[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackMoney",HasPackMoney[playerid]);
dUserSetINT(PlayerName(playerid)).("SavedWantedLevel",SavedWantedLevel[playerid]);
dUserSetINT(PlayerName(playerid)).("SavedJailTime",SavedJailTime[playerid]);
}

//Do things to the playerid
ResetVariables(playerid);
TextDrawHideForPlayer(playerid,VersionTD);
TextDrawHideForPlayer(playerid,WebsiteTD);
TextDrawDestroy(MessageTD[playerid]);
TextDrawDestroy(JailTimer[playerid]);
TextDrawDestroy(LocationTD[playerid]);

if (PlayerInfo[playerid][pRoadblock] != 0)
{
RemoveRoadblock(playerid);
}
for(new i = 0; i < sizeof(Objects); i++) ////Xobj
{
if(Player[playerid][view][i])
{
Player[playerid][view][i] = false;
DestroyPlayerObject(playerid,Player[playerid][objid][i]);
}
}
format(string,sizeof(string),"%s Has just left the server! (%s)",pname,aDisconnectNames[reason]);
SendClientMessageToAll(COLOR_VIOLETBLUE,string);
format(string,sizeof(string),"1%s Has just left the server! (%s)",pname,aDisconnectNames[reason]);
IRC_Say(gGroupID,IRC_CHANNEL,string);
return 1;
}


OnGameModeExit:


public OnGameModeExit()
{
//////xobject
for(new i = 0; i < MAX_PLAYERS; i++)
{
for(new o = 0; o < sizeof(Objects); o++)
{
if(Player[i][view][o])
{
Player[i][view][o] = false;
DestroyPlayerObject(i,Player[i][objid][o]);
}
}
}
KillTimer(timer);
// Disconnect the first bot
IRC_Quit(gBotID[0], "Gamemode exiting");
// Destroy the group
IRC_DestroyGroup(gGroupID);
IRC_DestroyGroup(gGroupAdminID);
return 1;
}

Xerli
10/11/2012, 10:35 AM
Bump.

Konstantinos
10/11/2012, 10:38 AM
Make a for loop in OnGameModeExit and save the data there!

>> This forum requires that you wait 120 seconds between posts. Please try again in 28 seconds.

Xerli
10/11/2012, 10:55 AM
So something like:


for(new i = 0; i < MAX_PLAYERS; i++)
{
dUserSetINT(PlayerName(playerid)).("Bankcash",BankCash[playerid]);
dUserSetINT(PlayerName(playerid)).("Cash",GetPlayerMoney(playerid));
dUserSetINT(PlayerName(playerid)).("Score",GetPlayerScore(playerid));
dUserSetINT(PlayerName(playerid)).("Adminlevel",AdminLevel[playerid]);
dUserSetINT(PlayerName(playerid)).("Army",CanUseArmy[playerid]);
dUserSetINT(PlayerName(playerid)).("CIA",CanUseCIA[playerid]);
dUserSetINT(PlayerName(playerid)).("RegularPlayer",IsRegularPlayer[playerid]);
dUserSetINT(PlayerName(playerid)).("DrugHouseOwner",DrugHouseOwner[playerid]);
dUserSetINT(PlayerName(playerid)).("OttoOwner",OttoOwner[playerid]);
dUserSetINT(PlayerName(playerid)).("TSkill",TerroristSkill[playerid]);
dUserSetINT(PlayerName(playerid)).("RobSkill",RobSkill[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackC4",HasPackC4[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackRope",HasPackRope[playerid]);
dUserSetINT(PlayerName(playerid)).("HasPackMoney",HasPackMoney[playerid]);
dUserSetINT(PlayerName(playerid)).("SavedWantedLevel",SavedWantedLevel[playerid]);
dUserSetINT(PlayerName(playerid)).("SavedJailTime",SavedJailTime[playerid]);
}

Konstantinos
10/11/2012, 10:59 AM
Almost.

for(new i = 0; i < MAX_PLAYERS; i++)
{
dUserSetINT(PlayerName(i)).("Bankcash",BankCash[i]);
dUserSetINT(PlayerName(i)).("Cash",GetPlayerMoney(i));
dUserSetINT(PlayerName(i)).("Score",GetPlayerScore(i));
dUserSetINT(PlayerName(i)).("Adminlevel",AdminLevel[i]);
dUserSetINT(PlayerName(i)).("Army",CanUseArmy[i]);
dUserSetINT(PlayerName(i)).("CIA",CanUseCIA[i]);
dUserSetINT(PlayerName(i)).("RegularPlayer",IsRegularPlayer[i]);
dUserSetINT(PlayerName(i)).("DrugHouseOwner",DrugHouseOwner[i]);
dUserSetINT(PlayerName(i)).("OttoOwner",OttoOwner[i]);
dUserSetINT(PlayerName(i)).("TSkill",TerroristSkill[i]);
dUserSetINT(PlayerName(i)).("RobSkill",RobSkill[i]);
dUserSetINT(PlayerName(i)).("HasPackC4",HasPackC4[i]);
dUserSetINT(PlayerName(i)).("HasPackRope",HasPackRope[i]);
dUserSetINT(PlayerName(i)).("HasPackMoney",HasPackMoney[i]);
dUserSetINT(PlayerName(i)).("SavedWantedLevel",SavedWantedLevel[i]);
dUserSetINT(PlayerName(i)).("SavedJailTime",SavedJailTime[i]);
}

Xerli
10/11/2012, 11:47 AM
Thanks and how would i say make a command that can save everything and then restart?

Konstantinos
10/11/2012, 12:39 PM
What do you mean by that?

Xerli
10/11/2012, 02:07 PM
Like say that i want a server restart command, and when that command is entered i want it to save all the files and then kick every player and restart?

Konstantinos
10/11/2012, 02:18 PM
I am not 100 percent sure, but it should work good!

CMD:restart( playerid, params[ ] )
{
OnGameModeExit( );
SendRconCommand( "gmx" );
return 1;
}

Xerli
10/11/2012, 02:26 PM
Ok i will try that now and get back to you!

EDIT: It's saving everything else but for some reason the money is not saving now.

Xerli
10/11/2012, 06:30 PM
Bump.