Guest User

Untitled

a guest
Apr 13th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #define MAX_TIMERS 10
  2. #define TIMERS_UPDATE 100
  3.  
  4. forward TOnGameModeInit();
  5. forward UpdateTimers();
  6.  
  7. new TimerTime[MAX_TIMERS], TimerInterval[MAX_TIMERS], bool: TimerRepeating[MAX_TIMERS];
  8. new TimerName[MAX_TIMERS][75];
  9.  
  10. public OnGameModeInit()
  11. {
  12.     SetTimer("UpdateTimers", TIMERS_UPDATE, 1);
  13.     return CallLocalFunction("TOnGameModeInit", "");
  14. }
  15.  
  16. public UpdateTimers()
  17. {
  18.     new GetTime = GetTickCount();
  19.     for(new A; A != MAX_TIMERS; A++)
  20.     {
  21.         if(!TimerTime[A]) continue;
  22.         if(TimerTime[A] <= GetTime)
  23.         {
  24.             if(!TimerRepeating[A]) TimerTime[A] = 0; else TimerTime[A] = GetTime + TimerInterval[A];
  25.             CallLocalFunction(TimerName[A], "");
  26.         }
  27.     }
  28.     return 1;
  29. }
  30.  
  31. stock TSetTimer(const funcname[], const interval, bool: repeating)
  32. {
  33.     for(new A; A != MAX_TIMERS; A++)
  34.     {
  35.         if(TimerTime[A] != 0) continue;
  36.         strmid(TimerName[A], funcname, 0, strlen(funcname));
  37.         TimerInterval[A] = interval;
  38.         TimerTime[A] = GetTickCount() + interval;
  39.         TimerRepeating[A] = repeating;
  40.         return - (A + MAX_TIMERS + 1);
  41.     }
  42.     return -1;
  43. }
  44.  
  45. stock KillTimerEx(timerid)
  46. {
  47.     if(timerid < -1) return TimerTime[- (timerid - MAX_TIMERS - 1)] = 0;
  48.     return KillTimer(timerid);
  49. }
  50.  
  51. #define SetTimer TSetTimer
  52. #define KillTimer KillTimerEx
  53.  
  54. #if defined _ALS_OnGameModeInit
  55.     #undef OnGameModeInit
  56. #else
  57.     #define _ALS_OnGameModeInit
  58. #endif
  59. #define OnGameModeInit TOnGameModeInit
Advertisement
Add Comment
Please, Sign In to add comment