Advertisement
Guest User

Untitled

a guest
May 10th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. //
  2. // Keeps the in game time synced to the server's time and
  3. // draws the current time on the player's hud using a textdraw/
  4. // (1 minute = 1 minute real world time)
  5. //
  6. // (c) 2009-2012 SA-MP Team
  7.  
  8. #include <a_samp>
  9. #pragma tabsize 0
  10.  
  11. //--------------------------------------------------
  12.  
  13. new Text:txtTimeDisp;
  14. new hour, minute;
  15. new timestr[32];
  16.  
  17. forward UpdateTimeAndWeather();
  18.  
  19. //--------------------------------------------------
  20.  
  21. new fine_weather_ids[] = {1,2,3,4,5,6,7,12,13,14,15,17,18,24,25,26,27,28,29,30,40};
  22. new foggy_weather_ids[] = {9,19,20,31,32};
  23. new wet_weather_ids[] = {8};
  24.  
  25. stock UpdateWorldWeather()
  26. {
  27. new next_weather_prob = random(100);
  28. if(next_weather_prob < 70) SetWeather(fine_weather_ids[random(sizeof(fine_weather_ids))]);
  29. else if(next_weather_prob < 95) SetWeather(foggy_weather_ids[random(sizeof(foggy_weather_ids))]);
  30. else SetWeather(wet_weather_ids[random(sizeof(wet_weather_ids))]);
  31. }
  32.  
  33. //--------------------------------------------------
  34.  
  35. //new last_weather_update=0;
  36.  
  37. public UpdateTimeAndWeather()
  38. {
  39. // Update time
  40. gettime(hour, minute);
  41.  
  42. format(timestr,32,"%02d:%02d",hour,minute);
  43. TextDrawSetString(txtTimeDisp,timestr);
  44. SetWorldTime(hour);
  45.  
  46. new x=0;
  47. while(x!=MAX_PLAYERS) {
  48. if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE) {
  49. SetPlayerTime(x,hour,minute);
  50. }
  51. x++;
  52. }
  53.  
  54. /* Update weather every hour
  55. if(last_weather_update == 0) {
  56. UpdateWorldWeather();
  57. }
  58. last_weather_update++;
  59. if(last_weather_update == 60) {
  60. last_weather_update = 0;
  61. }*/
  62. }
  63.  
  64. //--------------------------------------------------
  65.  
  66. public OnGameModeInit()
  67. {
  68. // Init our text display
  69. txtTimeDisp = TextDrawCreate(605.0,25.0,"00:00");
  70. TextDrawUseBox(txtTimeDisp, 0);
  71. TextDrawFont(txtTimeDisp, 3);
  72. TextDrawSetShadow(txtTimeDisp,0); // no shadow
  73. TextDrawSetOutline(txtTimeDisp,2); // thickness 1
  74. TextDrawBackgroundColor(txtTimeDisp,0x000000FF);
  75. TextDrawColor(txtTimeDisp,0xFFFFFFFF);
  76. TextDrawAlignment(txtTimeDisp,3);
  77. TextDrawLetterSize(txtTimeDisp,0.5,1.5);
  78.  
  79. UpdateTimeAndWeather();
  80. SetTimer("UpdateTimeAndWeather",1000 * 60,1);
  81.  
  82. return 1;
  83. }
  84.  
  85. //--------------------------------------------------
  86.  
  87. public OnPlayerSpawn(playerid)
  88. {
  89. TextDrawShowForPlayer(playerid,txtTimeDisp);
  90.  
  91. gettime(hour, minute);
  92. SetPlayerTime(playerid,hour,minute);
  93.  
  94. return 1;
  95. }
  96.  
  97. //--------------------------------------------------
  98.  
  99. public OnPlayerDeath(playerid, killerid, reason)
  100. {
  101. TextDrawHideForPlayer(playerid,txtTimeDisp);
  102. return 1;
  103. }
  104.  
  105. //--------------------------------------------------
  106.  
  107. public OnPlayerConnect(playerid)
  108. {
  109. gettime(hour, minute);
  110. SetPlayerTime(playerid,hour,minute);
  111. return 1;
  112. }
  113.  
  114. //--------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement