SA-MP Forums Archive
Multiple per-player timers or just one timer with a loop? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Multiple per-player timers or just one timer with a loop? (/showthread.php?tid=171885)



Multiple per-player timers or just one timer with a loop? - Hiddos - 28.08.2010

So I'm thinking to do a bit of an update to my Cowly Cow FS, add some new functions, try to improve coding a li'l bit, etc.

But now I'm wondering on what's better: Having one timer that loops through ALL players and checks if the person is a cow or not, or simply use seperate timers per players, which get killed when the player isn't a cow anymore.

Any advice would be welcome ^^

Note: This script isn't made for mass usage, but for small amounts of people at a time.


Re: Multiple per-player timers or just one timer with a loop? - playbox12 - 28.08.2010

I think per player would be better, but I don't think it would make that big of a difference since its like you say for a small ammount of people


Re: Multiple per-player timers or just one timer with a loop? - Kyosaur - 28.08.2010

I'd go with the single one and looping through the players (foreach would be a good thing to look into if you havent).

Also may i ask what this timer does (no idea what your cow fs does lol...) ? Depending on what it does, you can simply use OnPlayerUpdate; This isnt ideal if the code needs to be ran even when a player is afk though. As long as you make sure your code isn't being executed EVERY update / you dont need to the code ran when players are afk, its fine to use :P.


Re: Multiple per-player timers or just one timer with a loop? - cessil - 28.08.2010

if it can have it as no one is a cow I'd do per player timers


Re: Multiple per-player timers or just one timer with a loop? - Hiddos - 28.08.2010

Quote:
Originally Posted by Kyosaur
View Post
I'd go with the single one and looping through the players (foreach would be a good thing to look into if you havent).

Also may i ask what this timer does (no idea what your cow fs does lol...) ? Depending on what it does, you can simply use OnPlayerUpdate; This isnt ideal if the code needs to be ran even when a player is afk though. As long as you make sure your code isn't being executed EVERY update / you dont need to the code ran when players are afk, its fine to use :P.
It does around 4 floatsin/floatcas (4 Max, 2 minimum) calculations each time it gets executed, gets some positions and requires MapAndreas (Plugin) up to a max of one time at execution.



Quote:
Originally Posted by cessil
View Post
if it can have it as no one is a cow I'd do per player timers
Ah well, it has a command you must perform first, before being able to transform into a cow. So a server can have nobody being a cow, or everybody being a cow.