Raised This Month: $ Target: $400
 0% 

Timers


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
johnjg75
Veteran Member
Join Date: Mar 2004
Location: Delaware
Old 08-04-2006 , 23:59   Timers
Reply With Quote #1

I'm currently making a TKOTH plugin that uses a timer and i figured that I'd share the timer code because some people need help with timers. This example uses a small struct for teams and it shows how easy OOP can be.
Code:
#include <amxmodx> #include <cstrike> /*enum CsTeams {     CS_TEAM_UNASSIGNED = 0,     CS_TEAM_T = 1,     CS_TEAM_CT = 2,     CS_TEAM_SPECTATOR = 3 };*/ new bool:isTimerOn[CsTeams]; new zonetime[CsTeams]; new TimerID[CsTeams]; startTimer(CsTeams:team) {     if(isTimerOn[team])         return 0;     set_task(1.0,"Tick",TimerID[team],team,sizeof(team),"b");     isTimerOn=true; } Tick(CsTeams:team) {     zonetime[team]++; } stopTimer(CsTeams:team) {     remove_task(TimerID[team]);     isTimerOn=false;     resetTimer(team); } resetTimer(CsTeams:team) {     zonetime[team]=0; } pauseTimer(CsTeams:team) {     remove_task(TimerID[team]);     isTimerOn=false; } currentTime(CsTeams:team)     return zonetime[team];
Now this is plugin specific, but you can easily modify it to fit your plugin's needs.

Then you'd simply do what you need to do, i.e.
Code:
new bool:inzone[Team] docheck(); if(inzone[CS_TEAM_T] && !lastcheck[CS_TEAM_T])// if they are now in the zone and wasn't before     startTimer(CS_TEAM_T); if(!inzone[CS_TEAM_T] && lastcheck[CS_TEAM_T]) // if they were in the zone but aren't anymore     stopTimer(CS_TEAM_T); // do same with CT and make an update task every second or so
Pretty simple, eh?
__________________

Last edited by johnjg75; 08-06-2006 at 02:20. Reason: Fixing up code
johnjg75 is offline
Send a message via AIM to johnjg75 Send a message via MSN to johnjg75 Send a message via Yahoo to johnjg75
 



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

Forum Jump


All times are GMT -4. The time now is 17:50.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode