Player timers and Player timers with variable
#1

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

Quote:
Originally Posted by NoteND
View Post
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"20000"d"playerid); 
PHP Code:
OnPlayerDisconnect(playeridreason)
{
  
KillTimer(timer[playerid]);
  return 
1;

Reply
#3

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)
Reply
#4

Quote:
Originally Posted by Kwarde
View Post
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?
Reply
#5

Quote:
Originally Posted by Kwarde
View Post
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 ?
Reply
#6

Quote:
Originally Posted by NoteND
View Post
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
Reply
#7

Quote:
Originally Posted by Kasichok
View Post
Depends on time if its for a sec or less no need to store it in array
That makes no sense to me
Reply
#8

Quote:
Originally Posted by NoteND
View Post
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
Reply
#9

Quote:
Originally Posted by Kasichok
View Post
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?
Reply
#10

Quote:
Originally Posted by Kasichok
View Post
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)