Guest User

a_timer

a guest
Apr 13th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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], 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;
  25.             else TimerTime[A] = GetTime+TimerInterval[A];
  26.                     CallLocalFunction(TimerName[A], "");
  27.         }
  28.     }
  29.     return 1;
  30. }
  31.  
  32. stock TSetTimer(funcname[], interval, repeating)
  33. {
  34.     for(new A; A != MAX_TIMERS; A++)
  35.     {
  36.             if(TimerTime[A] != 0) continue;
  37.         strmid(TimerName[A], funcname, 0, strlen(funcname));
  38.         TimerInterval[A] = interval;
  39.         TimerTime[A] = GetTickCount()+interval;
  40.         TimerRepeating[A] = repeating;
  41.         return A;
  42.     }
  43.     return -1;
  44. }
  45.  
  46. stock KillTimerEx(timerid) TimerTime[timerid] = 0;
  47.  
  48. #define SetTimer TSetTimer
  49.  
  50. #if defined _ALS_OnGameModeInit
  51.     #undef OnGameModeInit
  52. #else
  53.     #define _ALS_OnGameModeInit
  54. #endif
  55. #define OnGameModeInit TOnGameModeInit
Advertisement
Add Comment
Please, Sign In to add comment