Save timer and "points"
#1

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?
Reply
#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


Forum Jump:


Users browsing this thread: 2 Guest(s)