SetTimerEx question
#1

When I do a SetTimerEx timer, example:

SetTimerEx("CaptureZoneAgain",300000,false,"dd",pl ayerid,id);

and the player left the server and a new player comes in, the timer still counts for the new player or not??
Reply
#2

It does still count for the playerid.


Edit:
This would fix it. The times will stop when the player leaves the server.

pawn Код:
new CaptureTimer[MAX_PLAYERS];
CaptureTimer[playerid] = SetTimerEx("CaptureZoneAgain",300000,false,"dd",playerid,id);
At OnPlayerConnect:
pawn Код:
CaptureTimer[playerid] = -1;
And at OnPlayerDisconnect:
pawn Код:
if(CaptureTimer[playerid] != -1) KillTimer(CaptureTimer[playerid]);
And at the Callback 'CaptureZoneAgain', you have to add:
pawn Код:
CaptureTimer[playerid] = -1;
Reply
#3

hi, thanks for your code.
The timer also will work when I have variables (so the id in the settimerex) ?

my capturezoneagain callback:

pawn Код:
forward CaptureZoneAgain(playerid,id);
public CaptureZoneAgain(playerid,id)
{
    if(LastCapturedZone[id][playerid] == 1)
    {
        LastCapturedZone[id][playerid] = 0;
    }
}
Reply
#4

Jeffry what does the OnPlayerConnect -1 does? xD -1 on some things is all worlds :P
Reply
#5

Oh, there are several ID's. Then it is like this:

At Top:
pawn Код:
new CaptureTimer[MAX_ZONES][MAX_PLAYERS];
Where you start the timer:
pawn Код:
CaptureTimer[id][playerid] = SetTimerEx("CaptureZoneAgain",300000,false,"dd",playerid,id);
At OnPlayerConnect:
pawn Код:
for(new id=0; id<MAX_ZONES; id++) CaptureTimer[id][playerid] = -1;
And at OnPlayerDisconnect:
pawn Код:
for(new id=0; id<MAX_ZONES; id++)  if(CaptureTimer[id][playerid] != -1) KillTimer(CaptureTimer[id][playerid]);
And this is 'CaptureZoneAgain':
pawn Код:
forward CaptureZoneAgain(playerid,id);
public CaptureZoneAgain(playerid,id)
{
    if(LastCapturedZone[id][playerid] == 1)
    {
        LastCapturedZone[id][playerid] = 0;
        CaptureTimer[id][playerid] = -1;
    }
}
Now it should work for playerids and Zone ID's.
(Change MAX_ZONES to the number of zones you have, or define it like: #define MAX_ZONES 10 if you have 10 Zones.)

I hope it works. If you have questions, feel free to ask.



Quote:
Originally Posted by Mike_Peterson
Посмотреть сообщение
Jeffry what does the OnPlayerConnect -1 does? xD -1 on some things is all worlds :P
Here it will just set the variable to -1, as no timer ID has -1. So if the variable is NOT -1, we kill the timer.
Reply
#6

ok, I made that now, how I can test wheter it works?
Reply
#7

Capture a Zone, leave the game, and join again, and wait if the timer will be called for you again.
(Just add a SendClientMessage to the timer, to test it, then remove it again.)
If the message does not come after the 5 mins (Or what you made the timer) then it worked. ^^
Reply
#8

Cool yes it worked thanks for your code!
Reply
#9

Quote:
Originally Posted by Ribber
Посмотреть сообщение
Cool yes it worked thanks for your code!
No problem. Have fun.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)