SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/10/2019, 01:16 PM   #1
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 252
Reputation: 5
Default Player timers and Player timers with variable

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 ?
NoteND is offline   Reply With Quote
Old 25/10/2019, 02:02 PM   #2
WalkZ
Big Clucker
 
WalkZ's Avatar
 
Join Date: Oct 2019
Location: Pakistan
Posts: 100
Reputation: 4
Default Re: Player timers and Player timers with variable

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;

WalkZ is offline   Reply With Quote
Old 25/10/2019, 02:23 PM   #3
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,738
Reputation: 1686
Default Re: Player timers and Player timers with variable

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)
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 25/10/2019, 02:39 PM   #4
Kasichok
Big Clucker
 
Kasichok's Avatar
 
Join Date: Sep 2018
Location: weed farm
Posts: 96
Reputation: 35
Default Re: Player timers and Player timers with variable

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?
__________________



STRESSED? TRY KASICHOK AND RELAX


Kasichok is offline   Reply With Quote
Old 25/10/2019, 02:45 PM   #5
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 252
Reputation: 5
Default Re: Player timers and Player timers with variable

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 ?
NoteND is offline   Reply With Quote
Old 25/10/2019, 02:52 PM   #6
Kasichok
Big Clucker
 
Kasichok's Avatar
 
Join Date: Sep 2018
Location: weed farm
Posts: 96
Reputation: 35
Default Re: Player timers and Player timers with variable

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
__________________



STRESSED? TRY KASICHOK AND RELAX


Kasichok is offline   Reply With Quote
Old 25/10/2019, 03:31 PM   #7
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 252
Reputation: 5
Default Re: Player timers and Player timers with variable

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
NoteND is offline   Reply With Quote
Old 25/10/2019, 03:36 PM   #8
Kasichok
Big Clucker
 
Kasichok's Avatar
 
Join Date: Sep 2018
Location: weed farm
Posts: 96
Reputation: 35
Default Re: Player timers and Player timers with variable

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
__________________



STRESSED? TRY KASICHOK AND RELAX


Kasichok is offline   Reply With Quote
Old 25/10/2019, 03:39 PM   #9
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 252
Reputation: 5
Default Re: Player timers and Player timers with variable

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?
NoteND is offline   Reply With Quote
Old 25/10/2019, 03:53 PM   #10
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,738
Reputation: 1686
Default Re: Player timers and Player timers with variable

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.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about player timers BalkanEliteRP Scripting Help 4 27/02/2018 11:41 PM
foreach or per player timers ? NeXoR Scripting Help 3 09/11/2016 07:57 PM
Player timers MP2 Scripting Help 1 08/07/2012 03:42 AM
[Tutorial] Player-timers Lenny the Cup Tutorials 9 14/10/2010 05:37 PM
Individual player timers? VictorMartinez Help Archive 5 21/07/2010 03:43 AM


All times are GMT. The time now is 11:18 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.