Guest User

a_timer

a guest
Apr 17th, 2013
851
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define MAX_TIMERS 10
  2. #define TIMERS_UPDATE 250
  3. #define INVALID_TIMER_ID (0xFFFF)
  4.  
  5. forward UpdateTimers();
  6.  
  7. enum TInfo
  8. {
  9.     TTime,
  10.     TInterval,
  11.     TRepeating
  12. };
  13. new TimerInfo[MAX_TIMERS][TInfo];
  14. new TimerName[MAX_TIMERS][75];
  15. new StartTimers, UpdateTimersID;
  16.  
  17. public UpdateTimers()
  18. {
  19.     for(new A; A != MAX_TIMERS; A++)
  20.     {
  21.         if(!TimerInfo[A][TTime]) continue;
  22.             if(TimerInfo[A][TTime] <= GetTickCount())
  23.             {
  24.                     if(!TimerInfo[A][TRepeating])
  25.             {
  26.                 TimerInfo[A][TTime] = 0;
  27.                 if(!--StartTimers) KillTimer(UpdateTimersID);
  28.             }
  29.             else TimerInfo[A][TTime] = GetTickCount()+TimerInfo[A][TInterval];
  30.                     CallLocalFunction(TimerName[A], "");
  31.         }
  32.     }
  33.     return 1;
  34. }
  35.  
  36. stock TSetTimer(const funcname[], interval, repeating)
  37. {
  38.     if(!StartTimers) UpdateTimersID = SetTimer("UpdateTimers", TIMERS_UPDATE, 1);
  39.     for(new A; A != MAX_TIMERS; A++)
  40.     {
  41.         if(TimerInfo[A][TTime] != 0) continue;
  42.         strmid(TimerName[A], funcname, 0, strlen(funcname));
  43.         TimerInfo[A][TInterval] = interval;
  44.         TimerInfo[A][TTime] = GetTickCount()+interval;
  45.         TimerInfo[A][TRepeating] = repeating;
  46.         StartTimers++;
  47.         return A;
  48.     }
  49.     return INVALID_TIMER_ID;
  50. }
  51.  
  52. stock TKillTimer(timerid)
  53. {
  54.     if(TimerInfo[timerid][TTime] != 0)
  55.     {
  56.         TimerInfo[timerid][TTime] = 0;
  57.         if(!--StartTimers) KillTimer(UpdateTimersID);
  58.     }
  59.     return 1;
  60. }
RAW Paste Data