Advertisement
Jonny_5

SyncPlayerTime_ALS_INC

May 6th, 2012
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.80 KB | None | 0 0
  1. /*
  2. Include:    SyncPlayerTime For SAMP: 0.3d+
  3. Author:         Jonny5
  4. Version:        0.3
  5. Description:
  6. This include will create a Textdraw Clock and Sync all Players to the same time.
  7. There is currently 2 modes of display:
  8.  
  9. Mode 1: Will Sync all Players times to the servers real world time.
  10. Mode 2: Will sync all players to the same (in Game) time
  11.  
  12. Both systems can be used to change the day/to night  night/ to day.
  13. Mode 1 will keep the time more constant, mode 2 is relying on PAWN timers to keep
  14. acurate time so the time will be off by up to 5ms atleast.
  15.  
  16. Credits to:
  17. Twisted_Insane : Requested the script.
  18. */
  19.  
  20. #define TD_FONT_COLOR           0x99CCFFFF      //Time Font Color
  21. #define TD_OUTLINE_COLOR        0x0066CCFF      //Time OutLine Color
  22. #define TD_OUTLINE_SIZE         1               //Time OutLine Size
  23. #define SYNC_SERVER_TIME                        //if uncommented will use server time, 1 real hour = 1 game hour
  24. #define USA_TIME_FORMAT                         //Use the 12 hour format.
  25. #define EFFECT_WEATHER                          //Set weather with player clock (only for mode 1)
  26.  
  27.  
  28.  
  29. new Hour, Minute, TIMER_WorldTime;
  30. #if defined SYNC_SERVER_TIME
  31. new Second;
  32. #endif
  33. new Text:tdWorldTime;
  34. new PlayerIsSpawned[MAX_PLAYERS];
  35.  
  36.  
  37. forward UpdateWorldTime();
  38. public UpdateWorldTime()
  39. {
  40. #if defined SYNC_SERVER_TIME
  41.     gettime(Hour, Minute, Second);
  42.     new str[9];
  43. #else
  44.     new str[6];
  45.     Minute++;
  46.     if(Minute == 60)
  47.     {
  48.         Minute=0;
  49.         Hour++;
  50.     }
  51.     if(Hour == 24) Hour=0;
  52. #endif
  53. #if defined USA_TIME_FORMAT
  54.     if (Hour > 12)
  55.     {
  56.         format(str, sizeof(str), "%02d:%02d:PM", Hour - 12, Minute);
  57.     }
  58.     else if (Hour ==0)
  59.     {
  60.         format(str, sizeof(str), "%02d:%02d:AM", Hour + 12, Minute);
  61.     }
  62.     else
  63.     {
  64.         format(str, sizeof(str), "%02d:%02d:AM", Hour, Minute);
  65.     }
  66. #else
  67.     format(str, sizeof(str), "%02d:%02d", Hour, Minute);
  68. #endif
  69.     TextDrawSetString(tdWorldTime,str);
  70.    
  71. #if defined EFFECT_WEATHER & defined SYNC_SERVER_TIME
  72.     for(new i = 0,pl = GetMaxPlayers(); i < pl ;i++)
  73.     {
  74.         if(PlayerIsSpawned[i] == 1)
  75.         {
  76.             SetPlayerTime(i,Hour,Minute);
  77.         }
  78.     }
  79. #endif
  80. #if !defined SYNC_SERVER_TIME
  81.     for(new i = 0,pl = GetMaxPlayers(); i < pl ;i++)
  82.     {
  83.         if(PlayerIsSpawned[i] == 1)
  84.         {
  85.             SetPlayerTime(i,Hour,Minute);
  86.         }
  87.     }
  88. #endif
  89.     return 1;
  90. }
  91.  
  92.  
  93. //For more info on ALS Hooking check
  94. //http://forum.sa-mp.com/showthread.php?t=85907
  95.  
  96. //--------------OnGameModeExit Hook-------------------
  97. public OnGameModeExit()
  98. {
  99.     new ret = 1;
  100.     KillTimer           (TIMER_WorldTime);
  101.     TextDrawHideForAll  (tdWorldTime);
  102.     TextDrawDestroy     (tdWorldTime);
  103.     if (funcidx("SPT_OnGameModeExit") != -1)
  104.     {
  105.         ret = CallLocalFunction("SPT_OnGameModeExit", "");
  106.     }
  107.     return ret;
  108. }
  109. #if defined _ALS_OnGameModeExit
  110.     #undef OnGameModeExit
  111. #else
  112.     #define _ALS_OnGameModeExit
  113. #endif
  114. #define OnGameModeExit SPT_OnGameModeExit
  115. forward SPT_OnGameModeExit();
  116.  
  117. //--------------OnGameModeInit Hook-------------------
  118. public OnGameModeInit()
  119. {
  120.     new ret = 1;
  121.     tdWorldTime = TextDrawCreate(605.0,25.0," ");
  122.     TextDrawUseBox          (tdWorldTime, 0);
  123.     TextDrawFont            (tdWorldTime, 3);
  124.     TextDrawColor           (tdWorldTime, TD_FONT_COLOR);
  125.     TextDrawSetOutline      (tdWorldTime, TD_OUTLINE_SIZE);
  126.     TextDrawBackgroundColor (tdWorldTime, TD_OUTLINE_COLOR);
  127.     TextDrawSetShadow       (tdWorldTime, 0);
  128.     TextDrawAlignment       (tdWorldTime, 3);
  129.     TextDrawLetterSize      (tdWorldTime, 0.3, 1.0);
  130.     TextDrawShowForAll      (tdWorldTime);
  131.     TIMER_WorldTime = SetTimer("UpdateWorldTime", 1000, true);
  132.     if (funcidx("SPT_OnGameModeInit") != -1)
  133.     {
  134.         ret = CallLocalFunction("SPT_OnGameModeInit", "");
  135.     }
  136.     return ret;
  137. }
  138. #if defined _ALS_OnGameModeInit
  139.     #undef OnGameModeInit
  140. #else
  141.     #define _ALS_OnGameModeInit
  142. #endif
  143. #define OnGameModeInit SPT_OnGameModeInit
  144. forward SPT_OnGameModeInit();
  145.  
  146. //--------------OnPlayerConnect Hook-------------------
  147. public OnPlayerConnect(playerid)
  148. {
  149.     new ret = 1;
  150.     TogglePlayerClock(playerid, 0);
  151.     if (funcidx("SPT_OnPlayerConnect") != -1)
  152.     {
  153.         ret = CallLocalFunction("SPT_OnPlayerConnect", "i",playerid);
  154.     }
  155.     return ret;
  156. }
  157. #if defined _ALS_OnPlayerConnect
  158.     #undef OnPlayerConnect
  159. #else
  160.     #define _ALS_OnPlayerConnect
  161. #endif
  162. #define OnPlayerConnect SPT_OnPlayerConnect
  163. forward SPT_OnPlayerConnect(playerid);
  164.  
  165. //--------------OnPlayerDisconnect Hook-------------------
  166. public OnPlayerDisconnect(playerid, reason)
  167. {
  168.     new ret = 1;
  169.     PlayerIsSpawned[playerid] = 0;
  170.     if (funcidx("SPT_OnPlayerDisconnect") != -1)
  171.     {
  172.         ret = CallLocalFunction("SPT_OnPlayerDisconnect", "ii",playerid, reason);
  173.     }
  174.     return ret;
  175. }
  176. #if defined _ALS_OnPlayerDisconnect
  177.     #undef OnPlayerDisconnect
  178. #else
  179.     #define _ALS_OnPlayerDisconnect
  180. #endif
  181. #define OnPlayerDisconnect SPT_OnPlayerDisconnect
  182. forward SPT_OnPlayerDisconnect(playerid, reason);
  183.  
  184. //--------------OnPlayerRequestClass Hook-------------------
  185. public OnPlayerRequestClass(playerid, classid)
  186. {
  187.     new ret = 1;
  188.     TextDrawHideForPlayer(playerid,tdWorldTime);
  189.     PlayerIsSpawned[playerid] = 0;
  190.     if (funcidx("SPT_OnPlayerRequestClass") != -1)
  191.     {
  192.         ret = CallLocalFunction("SPT_OnPlayerRequestClass", "ii",playerid, classid);
  193.     }
  194.     return ret;
  195. }
  196. #if defined _ALS_OnPlayerRequestClass
  197.     #undef OnPlayerRequestClass
  198. #else
  199.     #define _ALS_OnPlayerRequestClass
  200. #endif
  201. #define OnPlayerRequestClass SPT_OnPlayerRequestClass
  202. forward SPT_OnPlayerRequestClass(playerid, classid);
  203.  
  204. //--------------OnPlayerSpawn Hook-------------------
  205. public OnPlayerSpawn(playerid)
  206. {
  207.     new ret = 1;
  208.     PlayerIsSpawned[playerid] = 1;
  209.     SetPlayerTime(playerid,Hour,Minute);
  210.     TextDrawShowForPlayer(playerid,tdWorldTime);
  211.     if (funcidx("SPT_OnPlayerSpawn") != -1)
  212.     {
  213.         ret = CallLocalFunction("SPT_OnPlayerSpawn", "i",playerid);
  214.     }
  215.     return ret;
  216. }
  217. #if defined _ALS_OnPlayerSpawn
  218.     #undef OnPlayerSpawn
  219. #else
  220.     #define _ALS_OnPlayerSpawn
  221. #endif
  222. #define OnPlayerSpawn SPT_OnPlayerSpawn
  223. forward SPT_OnPlayerSpawn(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement