SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 20/02/2011, 08:11 AM   #1
!Phoenix!
Big Clucker
 
Join Date: Feb 2011
Location: 127.0.0.1 - Germany
Posts: 87
Reputation: 0
Default Efficiency of timers

Hey all,
While writing a script it's important for me to make it as efficient as I can do it.
So I taught about what would be better:
For example(!), I have a timer which repeats every second and checks for cheats. Furthermore the players speed (in vehicle) should be updated every second (speedometer) and a clock every 60 seconds.
So we have two functions which runs all the time (cheat-detector and clock-updater) and one which actually only have to run if the player is in a vehicle. Cheat-Detector and speedometer with the same interval and the clock * 60
What would be the best way to do it?
1. A seperate timer for each function (and each player who enters a vehicle)
2. Speedometer together with cheatfunction (for -> if in vehicle)
3. All together (2. + if sec == 60 do min++)

I don't exactly know how timers work so I ask for your knowledge

Phoenix
!Phoenix! is offline  
Old 20/02/2011, 08:23 AM   #2
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,428
Reputation: 271
Default Re: Efficiency of timers

I'd use seperate timers and stagger them. Its not timers that are inefficient its what people put inside them that is. You should set the players speedo timer when they enter a vehicle with SetTimerEx.
iggy1 is offline  
Old 20/02/2011, 08:32 AM   #3
!Phoenix!
Big Clucker
 
Join Date: Feb 2011
Location: 127.0.0.1 - Germany
Posts: 87
Reputation: 0
Default AW: Efficiency of timers

Do timers anyway need computing power while they are not running? (Something like the server checks every second if a task has to be executed either way)
!Phoenix! is offline  
Old 20/02/2011, 08:42 AM   #4
iggy1
High-roller
 
iggy1's Avatar
 
Join Date: Mar 2009
Location: One past the end.
Posts: 2,428
Reputation: 271
Default Re: Efficiency of timers

I'm not sure how it works internally but, generally a CPU can process many "ifs" per millisecond (depending on what it is checking ofc) so i can't see it being inefficient. I'm no expert on efficiency But thats what i gather. In a mode i'm writting every player has their own update timer, so i don't have to use one timer that loops through all players saving their stats. (maybe causing lag spikes)
iggy1 is offline  
Old 20/02/2011, 08:56 AM   #5
!Phoenix!
Big Clucker
 
Join Date: Feb 2011
Location: 127.0.0.1 - Germany
Posts: 87
Reputation: 0
Default AW: Efficiency of timers

Ok, thanks a lot, iggy1

(If anyone knows exactly how it works I would be still interested )
!Phoenix! is offline  
Old 20/02/2011, 09:01 AM   #6
Macluawn
Gangsta
 
Macluawn's Avatar
 
Join Date: Aug 2010
Location: Latvia
Posts: 639
Reputation: 78
Default Re: Efficiency of timers

If you have a lot of code inside them then you should keep them separate. But if its only few lines in timers that collide, you should combine them.
Macluawn is offline  
Old 20/02/2011, 09:03 AM   #7
!Phoenix!
Big Clucker
 
Join Date: Feb 2011
Location: 127.0.0.1 - Germany
Posts: 87
Reputation: 0
Default AW: Efficiency of timers

Thanks but now I'm not really smarter.
WHY?

(So only one user-unspecific timer for a speedometer?)
!Phoenix! is offline  
 

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
Mysql + SScanf = efficiency Cameltoe Help Archive 4 17/09/2010 03:37 PM
Efficiency ScottCFR Help Archive 2 18/07/2010 03:38 AM
Anticheat Efficiency BP13 Help Archive 1 04/01/2010 07:16 AM
SQLite efficiency questions. Outbreak Help Archive 3 07/12/2009 11:34 AM
Tutorial: variable efficiency maij Help Archive 5 13/05/2009 09:04 PM


All times are GMT. The time now is 02:39 PM.


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