Raised This Month: $32 Target: $400
 8% 

Timers


Post New Thread Reply   
 
Thread Tools Display Modes
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
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 08-05-2006 , 14:48   Re: Timers
Reply With Quote #2

1. Might actualy use the actual team #'s. As enum's default first value is 0.
2. Not really OOP ;] (Since pawn doesnt support OOP)
Freecode is offline
johnjg75
Veteran Member
Join Date: Mar 2004
Location: Delaware
Old 08-05-2006 , 17:19   Re: Timers
Reply With Quote #3

Quote:
Originally Posted by Freecode
1. Might actualy use the actual team #'s. As enum's default first value is 0.
Done
Quote:
Originally Posted by Freecode
2. Not really OOP ;] (Since pawn doesnt support OOP)
yeah, i know but its as close as you can get in pawn
__________________

Last edited by johnjg75; 08-05-2006 at 17:38.
johnjg75 is offline
Send a message via AIM to johnjg75 Send a message via MSN to johnjg75 Send a message via Yahoo to johnjg75
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-06-2006 , 02:16   Re: Timers
Reply With Quote #4

This would be better done with entity thinks rather than a repeatitive set_task.
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
Reply



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 16:41.


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