GammixSAMP

timeupdater.inc - By Gammix

May 15th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. /*
  2. Timeupdate Include/Timer (timeupdater.inc)
  3. * Now its possible to just use one timer for all your player functioning and updating using OnPlayerTimeUpdate!
  4. * Now its possible to just use one timer for all your global functioning and updaing using OnTimeUpdate, ALSO!
  5.  
  6. Author: (creator)
  7. * Gammix
  8.  
  9. (c) Copyright 2015
  10. * This file is provided as is (no warranties).
  11. */
  12.  
  13. /*
  14. CALLBACKS:
  15. public OnPlayerTimeUpdate(playerid, hours, minutes, seconds)
  16. public OnTimeUpdate(hours, minutes, seconds)
  17. */
  18.  
  19. static gPlayerSecondsTimer[MAX_PLAYERS];
  20. static gGlobalSecondsTimer;
  21. static gTimeCount[3];
  22.  
  23. //internal function
  24. stock static TIMER_GetPlayerConnectedTime(playerid, &hours, &minutes, &seconds)
  25. {
  26. new connected_time = NetStats_GetConnectedTime(playerid);
  27. seconds = (connected_time / 1000) % 60;
  28. minutes = (connected_time / (1000 * 60)) % 60;
  29. hours = (connected_time / (1000 * 60 * 60));
  30. return true;
  31. }
  32.  
  33. //Note: if you use this in a filterscript, please define "FILTERSCRIPT" in your script
  34. #if defined FILTERSCRIPT// if used in a filterscript
  35.  
  36. public OnFilterScriptInit()
  37. {
  38. gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1 * 1000, "iii", false, gTimeCount[0], gTimeCount[1], gTimeCount[2]);
  39.  
  40. return CallLocalFunction("TIMER_OnFilterScriptInit", "");
  41. }
  42. #if defined _ALS_OnFilterScriptInit
  43. #undef OnFilterScriptInit
  44. #else
  45. #define _ALS_OnFilterScriptInit
  46. #endif
  47. #define OnFilterScriptInit TIMER_OnFilterScriptInit
  48. forward TIMER_OnFilterScriptInit();
  49.  
  50. public OnFilterScriptExit()
  51. {
  52. KillTimer(gGlobalSecondsTimer);
  53.  
  54. return CallLocalFunction("TIMER_OnFilterScriptExit", "");
  55. }
  56. #if defined _ALS_OnFilterScriptExit
  57. #undef OnFilterScriptExit
  58. #else
  59. #define _ALS_OnFilterScriptExit
  60. #endif
  61. #define OnFilterScriptExit TIMER_OnFilterScriptExit
  62. forward TIMER_OnFilterScriptExit();
  63.  
  64. #else// if used in a gamemode
  65.  
  66. public OnGameModeInit()
  67. {
  68. gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1 * 1000, false, "iii", gTimeCount[0], gTimeCount[1], gTimeCount[2]);
  69.  
  70. return CallLocalFunction("TIMER_OnGameModeInit", "");
  71. }
  72. #if defined _ALS_OnGameModeInit
  73. #undef OnGameModeInit
  74. #else
  75. #define _ALS_OnGameModeInit
  76. #endif
  77. #define OnGameModeInit TIMER_OnGameModeInit
  78. forward TIMER_OnGameModeInit();
  79.  
  80. public OnGameModeExit()
  81. {
  82. KillTimer(gGlobalSecondsTimer);
  83.  
  84. return CallLocalFunction("TIMER_OnGameModeExit", "");
  85. }
  86. #if defined _ALS_OnGameModeExit
  87. #undef OnGameModeExit
  88. #else
  89. #define _ALS_OnGameModeExit
  90. #endif
  91. #define OnGameModeExit TIMER_OnGameModeExit
  92. forward TIMER_OnGameModeExit();
  93.  
  94. #endif
  95.  
  96. public OnPlayerConnect(playerid)
  97. {
  98. static hours, minutes, seconds;
  99. TIMER_GetPlayerConnectedTime(playerid, hours, minutes, seconds);
  100. gPlayerSecondsTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1* 1000, false, "iiii", playerid, hours, minutes, seconds);
  101. return CallLocalFunction("TIMER_OnPlayerConnect", "i", playerid);
  102. }
  103. #if defined _ALS_OnPlayerConnect
  104. #undef OnPlayerConnect
  105. #else
  106. #define _ALS_OnPlayerConnect
  107. #endif
  108. #define OnPlayerConnect TIMER_OnPlayerConnect
  109. forward TIMER_OnPlayerConnect(playerid);
  110.  
  111. public OnPlayerDisconnect(playerid, reason)
  112. {
  113. KillTimer(gPlayerSecondsTimer[playerid]);
  114. return CallLocalFunction("TIMER_OnPlayerDisconnect", "ii", playerid, reason);
  115. }
  116. #if defined _ALS_OnPlayerDisconnect
  117. #undef OnPlayerDisconnect
  118. #else
  119. #define _ALS_OnPlayerDisconnect
  120. #endif
  121. #define OnPlayerDisconnect TIMER_OnPlayerDisconnect
  122. forward TIMER_OnPlayerDisconnect(playerid, reason);
  123.  
  124. forward OnPlayerTimeUpdate(playerid, hours, minutes, seconds);
  125. public OnPlayerTimeUpdate(playerid, hours, minutes, seconds)
  126. {
  127. hours = 0, minutes = 0, seconds = 0;
  128. TIMER_GetPlayerConnectedTime(playerid, hours, minutes, seconds);
  129. gPlayerSecondsTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1* 1000, false, "iiii", playerid, hours, minutes, seconds);
  130. return CallLocalFunction("TIMER_OnPlayerTimeUpdate", "iiii", playerid, hours, minutes, seconds);
  131. }
  132. #if defined _ALS_OnPlayerTimeUpdate
  133. #undef OnPlayerTimeUpdate
  134. #else
  135. #define _ALS_OnPlayerTimeUpdate
  136. #endif
  137. #define OnPlayerTimeUpdate TIMER_OnPlayerTimeUpdate
  138. forward TIMER_OnPlayerTimeUpdate(playerid, hours, minutes, seconds);
  139.  
  140. forward OnTimeUpdate(hours, minutes, seconds);
  141. public OnTimeUpdate(hours, minutes, seconds)
  142. {
  143. gTimeCount[2] += 1;
  144. if(gTimeCount[2] >= 60)
  145. {
  146. gTimeCount[2] = 0;
  147. gTimeCount[1] += 1;
  148.  
  149. if(gTimeCount[1] >= 60)
  150. {
  151. gTimeCount[1] = 0;
  152. gTimeCount[0] += 1;
  153. }
  154. }
  155. hours = 0, minutes = 0, seconds = 0;
  156. gGlobalSecondsTimer = SetTimerEx("OnTimeUpdate", 1* 1000, false, "iii", gTimeCount[0], gTimeCount[1], gTimeCount[2]);
  157. return CallLocalFunction("TIMER_OnTimeUpdate", "iii", hours, minutes, seconds);
  158. }
  159. #if defined _ALS_OnTimeUpdate
  160. #undef OnTimeUpdate
  161. #else
  162. #define _ALS_OnTimeUpdate
  163. #endif
  164. #define OnTimeUpdate TIMER_OnTimeUpdate
  165. forward TIMER_OnTimeUpdate(hours, minutes, seconds);
Advertisement
Add Comment
Please, Sign In to add comment