27.04.2013, 20:52
Hi. I have a question - how i can create function to save player's account per x secs? X = optimally time, i dont know, so you should choose. + repping for good reply.
I need that because my /stats command use variables from scriptfiles. So yeah, if i get money that should appear in /stats in that moment, not after relog or smth like that.
|
You can save stats just after inputting command /stats, and then show it for player. But i dont think that showing stats from the file its good idea. Why you should use data from files to show it for player? Work with variables. (Sorry for my bad English, i'm Ukrainian)
|
CMD:stats(playerid, params[])
{
new Float:gihp, Float:giar;
GetPlayerHealth(playerid, gihp);
GetPlayerArmour(playerid, giar);
GetPlayerWantedLevel(playerid);
new temp[1000];
new info[1000];
format(temp, sizeof(temp), "Cash: %i$\n",PlayerInfo[playerid][pCash]);
strcat(info, temp);
format(temp, sizeof(temp), "Skin ID: %d\n",PlayerInfo[playerid][pSkin]);
strcat(info, temp);
format(temp, sizeof(temp), "Admin Level: %d\n",PlayerInfo[playerid][pAdmin]);
strcat(info, temp);
format(temp, sizeof(temp), "Kills: %i\n",PlayerInfo[playerid][pKills]);
strcat(info, temp);
format(temp, sizeof(temp), "Deaths: %i\n",PlayerInfo[playerid][pDeaths]);
strcat(info, temp);
format(temp, sizeof(temp), "Health: %0.1f\n",PlayerInfo[playerid][pHealth]);
strcat(info, temp);
format(temp, sizeof(temp), "Armour: %0.1f\n",PlayerInfo[playerid][pArmour]);
strcat(info, temp);
format(temp, sizeof(temp), "Level: %d)\n",PlayerInfo[playerid][pLevel]);
strcat(info, temp);
format(temp, sizeof(temp), "Score: %i\n",GetPlayerScore(playerid));
strcat(info, temp);
ShowPlayerDialog(playerid, 14, DIALOG_STYLE_MSGBOX,"{53C506}Your Stats",info,"Close","");
return true;
}
Yeah but i dont have damn idea how to do it. My stats command:
pawn Code:
|
Firstly, you say, that get information from the file, but you dont do that in your script. You dont need timer to save stats, just do it in the OnPlayerDisconnect. And if you worry about data lost, you can save stats once per 5-10 minutes or after changing priority variables.
|
To find X you need to ask yourself the question: how often are stats updated? You'd want to go with no less than 10 minutes. Yes, minutes. Very important changes (like change in admin level, password, etc) should be written out immediately.
|
task autosaveAccounts[60000*7.5]()
{
foreach(new i : Player) YourSaveFunction(i);
return 1;
}