SA-MP Forums Archive
Saving player's account per x secs. - 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)
+--- Thread: Saving player's account per x secs. (/showthread.php?tid=433584)



Saving player's account per x secs. - lQs - 27.04.2013

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.


Re: Saving player's account per x secs. - Tom1412 - 27.04.2013

very simple, all you need to do is create a repeating timer in gamemodeinit.

that runs the a public which has all of your saving parts for the accounts in.

Rep is i helped ya!


Re: Saving player's account per x secs. - RVRP - 27.04.2013

You are going to need to use a timer - although I must say I wouldn't recommend using said timer very often. In fact, I would recommend against saving user files on a regular basis completely. Saving on disconnect works just fine.

Like I said though, you'll want to use a timer and complete the same actions you would on a player disconnecting.


Re: Saving player's account per x secs. - Vince - 27.04.2013

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.


Re: Saving player's account per x secs. - lQs - 27.04.2013

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.


Re: Saving player's account per x secs. - stabker - 27.04.2013

Quote:
Originally Posted by lQs
View Post
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)

Quote:
Originally Posted by EliteApple
View Post
SA-MP has OnPlayerUpdate which is called almost every second.
its very-very-very bad idea


Re: Saving player's account per x secs. - lQs - 27.04.2013

Quote:
Originally Posted by stabker
View Post
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)
Yeah but i dont have damn idea how to do it. My stats command:
pawn Code:
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;
}



Re: Saving player's account per x secs. - stabker - 27.04.2013

Quote:
Originally Posted by lQs
View Post
Yeah but i dont have damn idea how to do it. My stats command:
pawn Code:
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;
}
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.


Re: Saving player's account per x secs. - lQs - 27.04.2013

Quote:
Originally Posted by stabker
View Post
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.
So whats bad with this cmd? It doesnt update the money, HP, etc.


Re: Saving player's account per x secs. - Scenario - 28.04.2013

I'm seeing a lot of idiotic responses from people and now the thread is 2 pages in. This is the only valid response:

Quote:
Originally Posted by Vince
View Post
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.
You do NOT need to save data every few seconds. Every 5-10 minutes is more than enough; and no, it isn't an inefficiency issue here. Think about it like this: You're a player on the server. You've been playing for 4 hours straight and all of a sudden the server crashes; your stats aren't going to be saved. So... those 4 hours of work you just did are now gone.

How ticked are your players going to be if that happens?

Therefore, you need to make a repeating timer that saves each player's stats every 5-10 minutes. Hell, you could go with every 7.5 minutes if you really wanted to.

A little piece of code like this is going to work fine for you:

pawn Code:
task autosaveAccounts[60000*7.5]()
{
    foreach(new i : Player) YourSaveFunction(i);
    return 1;
}
^ All you have to do is download YSI and add #include <YSI\y_timers> with all of your other includes, and add the code I just gave you to your script. Change "YourSaveFunction" to the function you use to save player accounts. It will save data every 7.5 minutes.