Help with a timer and save. -
Rocketeer - 02.08.2011
Hey, so i'm using Mysql and i want my players to see how long they have played on my server, so what i did was i created another variable, and everything went smooth, i went ingame and everything started going, i could see how many hours minutes and seconds i play.
Here is the problem, after i exit server, and come back on. a whole new timer starts, and the problem is Mysql records everything, but then my code tells it to restart whole thing, so here is a part of my code, I want to know why does it restart everytime i reconnect.
This is a timer.
Код:
syncserver = SetTimer("SyncServer", 999, 1);
Код:
forward SyncServer (playerid );
public SyncServer(playerid )
{
PVar[playerid][pHours] ++;
return 1;
}
once, again is there anything wrong with it? Mysql records how many seconds, and then its converted into minutes with some basic math.
For some reason count restarts everytime i reconnect server, and it changed data in mysql
Re: Help with a timer and save. -
PGTips - 02.08.2011
pawn Код:
//under OnGameMode.....
SyncServer = SetTimerEx("SyncServer"...); Im guessing you now how to fill this in
forward SyncServer (playerid );
public SyncServer(playerid )
{
PVar[playerid][pHours] ++;
//InI_Write.... saves here
return 1;
}
the only thing wrongis t repeat a timer you need to set a settimerex timer
Re: Help with a timer and save. -
Blacklite - 02.08.2011
You don't specify a playerid in your SetTimer - I'm not sure exactly of the behaviour of that, but I would use something like this instead (uses timec() which I posted in
this thread):
pawn Код:
public OnGameModeInit()
{
SetTimer("SyncServer", 999, 1);
}
forward SyncServer();
public SyncServer()
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (PVar[playerid][LoggedIn])
{
PVar[playerid][pPlayTime]++;
}
}
}
CMD:playtime(playerid, params[])
{
new string[128];
format(string, sizeof(string), "You have been playing this server for %s.", timec(PVar[playerid][pPlayTime], 0));
SendClientMessage(playerid, WHITE, string);
}
stock timec(timestamp, compare = -1) {
if (compare == -1) {
compare = gettime();
}
new
n,
Float:d = (timestamp > compare) ? timestamp - compare : compare - timestamp,
returnstr[32];
if (d < 60) {
format(returnstr, sizeof(returnstr), '< 1 minute');
return returnstr;
} else if (d < 3600) { // 3600 = 1 hour
n = floatround(floatdiv(d, 60.0), floatround_floor);
format(returnstr, sizeof(returnstr), 'minute');
} else if (d < 86400) { // 86400 = 1 day
n = floatround(floatdiv(d, 3600.0), floatround_floor);
format(returnstr, sizeof(returnstr), 'hour');
} else if (d < 2592000) { // 2592000 = 1 month
n = floatround(floatdiv(d, 86400.0), floatround_floor);
format(returnstr, sizeof(returnstr), 'day');
} else if (d < 31536000) { // 31536000 = 1 year
n = floatround(floatdiv(d, 2592000.0), floatround_floor);
format(returnstr, sizeof(returnstr), 'month');
} else {
n = floatround(floatdiv(d, 31536000.0), floatround_floor);
format(returnstr, sizeof(returnstr), 'year');
}
if (n == 1) {
format(returnstr, sizeof(returnstr), '1 %s', returnstr);
} else {
format(returnstr, sizeof(returnstr), '%d %ss', n, returnstr);
}
return returnstr;
}
The unix timestamp tutorial thread is here:
https://sampforum.blast.hk/showthread.php?tid=254915
Re: Help with a timer and save. -
Rocketeer - 02.08.2011
PGTips no explain, and ive tried nothing works, still when connect it resets timer. and stats
Re: Help with a timer and save. -
Rocketeer - 02.08.2011
Sorry, everyone, im retarded there was no problem, for some reason i made it so PVar resets everytime on connect lol! sorry!!