SA-MP Forums Archive
Save timer and "points" - 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: Save timer and "points" (/showthread.php?tid=410918)



Save timer and "points" - Sellize - 27.01.2013

Hey guys I'm looking to know how to save the timer for a player, ex: when he types /hello it will set a timer for 1 min, and when he rejoins the 1 min is still continuing. And I have something like /givepoint [ID] but how can i save someones points?


Re: Save timer and "points" - Rupert - 27.01.2013

Declare two variables for all players like these:

Код:
new hellotime[MAX_PLAYERS];
new timerr[MAX_PLAYERS];
Create a prototype for the timer:

Код:
forward HelloPlayer(playerid);
When a player types "/hello":

Код:
timerr = SetTimerEx("HelloPlayer", 1000, true, "i", playerid);
hellotime[playerid] = 0;
And let's continue with our callback:

Код:
HelloPlayer(playerid)
{
hellotime[playerid]++;
if(hellotime[playerid] == 60) KillTimer(timerr[playerid]);
return 1;
}
-----------------------------------------------------------------------------------------------------------------------

Now we have to save the time if the player disconnect.

Код:
public OnPlayerDisconnect(playerid, reason)
{
new timeFile[128], name[24];
GetPlayerName(playerid, 24);
format(timeFile, 128, "time_%s", name);
if(!fexist(timeFile)) dini_Create(timeFile);
KillTimer(timerr[playerid]);
dini_IntSet(timeFile, "Time", hellotime[playerid]);
return 1;
}
You ought to load the 'hellotime' when the player connect.

Код:
public OnPlayerConnect(playerid)
{
new timeFile[128], name[24];
GetPlayerName(playerid, 24);
format(timeFile, 128, "time_%s", name);
if(fexist(timeFile))
{
hellotime[playerid] = dini_Int(timeFile, "Time");
timerr[playerid] = SetTimerEx("HelloPlayer", 1000, true, "i", playerid);
}
return 1;
}
I hope I helped you.