Save timer and "points"
#2

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.
Reply


Messages In This Thread
Save timer and "points" - by Sellize - 27.01.2013, 09:18
Re: Save timer and "points" - by Rupert - 27.01.2013, 10:28

Forum Jump:


Users browsing this thread: 2 Guest(s)