Player timers and Player timers with variable -
NoteND - 25.10.2019
Hey!
I got a question about timers.. basically I'm not sure when should I use for example..
First option:
Code:
new timer[MAX_PLAYERS];
timer[playerid] = SetTimerEx("Test", 2000, 0, "d", playerid);
or
Second Option:
Code:
SetTimerEx("Test", 2000, 0, "d", playerid);
Because what happens if for example during the time timer is valid, player disconnects? I guess timer gets bugged and next time that ID connects it bugs him out or something?
Because lets say I use the second option for multiple player id's.. I guess I gotta use first option if I use it for more player id's than one.. or ?
Re: Player timers and Player timers with variable -
WalkZ - 25.10.2019
Quote:
Originally Posted by NoteND
Hey!
I got a question about timers.. basically I'm not sure when should I use for example..
First option:
Code:
new timer[MAX_PLAYERS];
timer[playerid] = SetTimerEx("Test", 2000, 0, "d", playerid);
or
Second Option:
Code:
SetTimerEx("Test", 2000, 0, "d", playerid);
Because what happens if for example during the time timer is valid, player disconnects? I guess timer gets bugged and next time that ID connects it bugs him out or something?
Because lets say I use the second option for multiple player id's.. I guess I gotta use first option if I use it for more player id's than one.. or ?
|
You should do something like this to prevent conflicts of player ids when player disconnect.
PHP Code:
new timer[MAX_PLAYERS];
timer[playerid] = SetTimerEx("Test", 2000, 0, "d", playerid);
PHP Code:
OnPlayerDisconnect(playerid, reason)
{
KillTimer(timer[playerid]);
return 1;
}
Re: Player timers and Player timers with variable -
Kwarde - 25.10.2019
Always check SA-MP Wiki: SetTimer(Ex) returns the ID of the timer. On the same page you could have seen there's a KillTimer function.
Not killing timers will indeed mess things up if they are repeatable timers: At some point one player would have multiple timers running, making the script run more often.
Your examples are timers that don't repeat. So not assigning the timer ID to a player to kill it later won't hurt it that quick because the timer runs once (assuming it's not set again in the public function it calls)
Re: Player timers and Player timers with variable -
Kasichok - 25.10.2019
Quote:
Originally Posted by Kwarde
Always check SA-MP Wiki: SetTimer(Ex) returns the ID of the timer. On the same page you could have seen there's a KillTimer function.
Not killing timers will indeed mess things up if they are repeatable timers: At some point one player would have multiple timers running, making the script run more often.
Your examples are timers that don't repeat. So not assigning the timer ID to a player to kill it later won't hurt it that quick because the timer runs once (assuming it's not set again in the public function it calls)
|
what if the timer is set to 1 min and player leave after like 20 seconds?
Re: Player timers and Player timers with variable -
NoteND - 25.10.2019
Quote:
Originally Posted by Kwarde
Always check SA-MP Wiki: SetTimer(Ex) returns the ID of the timer. On the same page you could have seen there's a KillTimer function.
Not killing timers will indeed mess things up if they are repeatable timers: At some point one player would have multiple timers running, making the script run more often.
Your examples are timers that don't repeat. So not assigning the timer ID to a player to kill it later won't hurt it that quick because the timer runs once (assuming it's not set again in the public function it calls)
|
Okay, so if I understand you correctly, if I dont set timer to repeat, I can do "SetTimerEx..." for multiple players at once without any problem ?
Re: Player timers and Player timers with variable -
Kasichok - 25.10.2019
Quote:
Originally Posted by NoteND
Okay, so if I understand you correctly, if I dont set timer to repeat, I can do "SetTimerEx..." for multiple players at once without any problem ?
|
Depends on time if its for a sec or less no need to store it in array
Re: Player timers and Player timers with variable -
NoteND - 25.10.2019
Quote:
Originally Posted by Kasichok
Depends on time if its for a sec or less no need to store it in array
|
That makes no sense to me
Re: Player timers and Player timers with variable -
Kasichok - 25.10.2019
Quote:
Originally Posted by NoteND
That makes no sense to me
|
its not hard to understand
200 ms timer for example will end even if player quits it will end shorly after,
but 1 min timer for example player will leave and in the mean time another player can join get the same id then what ever you done in that callback will happen to this player and only then the timer will end
Re: Player timers and Player timers with variable -
NoteND - 25.10.2019
Quote:
Originally Posted by Kasichok
its not hard to understand
200 ms timer for example will end even if player quits it will end shorly after,
but 1 min timer for example player will leave and in the mean time another player can join get the same id then what ever you done in that callback will happen to this player and only then the timer will end
|
So I can set 3secs timer I guess?
Re: Player timers and Player timers with variable -
Kwarde - 25.10.2019
Quote:
Originally Posted by Kasichok
what if the timer is set to 1 min and player leave after like 20 seconds?
|
"later won't hurt it that quick because"
That's why I typed 'that quick', because it нs possible indeed. I'd kill player timers too when someone disconnect.