SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
3.7 KiB

5 years ago
  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-2014 SA-MP Team
  7. #include <a_samp>
  8. #pragma tabsize 0
  9. #include "../include/gl_common.inc"
  10. //--------------------------------------------------
  11. // Used to override the time in this script
  12. new worldtime_override = 0;
  13. new worldtime_overridehour = 0;
  14. new worldtime_overridemin = 0;
  15. new Text:txtTimeDisp;
  16. new hour, minute;
  17. new timestr[32];
  18. forward UpdateTimeAndWeather();
  19. //--------------------------------------------------
  20. 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};
  21. new foggy_weather_ids[] = {9,19,20,31,32};
  22. new wet_weather_ids[] = {8};
  23. stock UpdateWorldWeather()
  24. {
  25. new next_weather_prob = random(100);
  26. if(next_weather_prob < 70) SetWeather(fine_weather_ids[random(sizeof(fine_weather_ids))]);
  27. else if(next_weather_prob < 95) SetWeather(foggy_weather_ids[random(sizeof(foggy_weather_ids))]);
  28. else SetWeather(wet_weather_ids[random(sizeof(wet_weather_ids))]);
  29. }
  30. //--------------------------------------------------
  31. //new last_weather_update=0;
  32. public UpdateTimeAndWeather()
  33. {
  34. // Update time
  35. if(!worldtime_override) {
  36. gettime(hour, minute);
  37. } else {
  38. hour = worldtime_overridehour;
  39. minute = worldtime_overridemin;
  40. }
  41. format(timestr,32,"%02d:%02d",hour,minute);
  42. TextDrawSetString(txtTimeDisp,timestr);
  43. SetWorldTime(hour);
  44. new x=0;
  45. while(x!=MAX_PLAYERS) {
  46. if(IsPlayerConnected(x) && GetPlayerState(x) != PLAYER_STATE_NONE) {
  47. SetPlayerTime(x,hour,minute);
  48. }
  49. x++;
  50. }
  51. /* Update weather every hour
  52. if(last_weather_update == 0) {
  53. UpdateWorldWeather();
  54. }
  55. last_weather_update++;
  56. if(last_weather_update == 60) {
  57. last_weather_update = 0;
  58. }*/
  59. }
  60. //--------------------------------------------------
  61. public OnGameModeInit()
  62. {
  63. // Init our text display
  64. txtTimeDisp = TextDrawCreate(605.0,25.0,"00:00");
  65. TextDrawUseBox(txtTimeDisp, 0);
  66. TextDrawFont(txtTimeDisp, 3);
  67. TextDrawSetShadow(txtTimeDisp,0); // no shadow
  68. TextDrawSetOutline(txtTimeDisp,2); // thickness 1
  69. TextDrawBackgroundColor(txtTimeDisp,0x000000FF);
  70. TextDrawColor(txtTimeDisp,0xFFFFFFFF);
  71. TextDrawAlignment(txtTimeDisp,3);
  72. TextDrawLetterSize(txtTimeDisp,0.5,1.5);
  73. UpdateTimeAndWeather();
  74. SetTimer("UpdateTimeAndWeather",1000 * 60,1);
  75. return 1;
  76. }
  77. //--------------------------------------------------
  78. public OnPlayerSpawn(playerid)
  79. {
  80. TextDrawShowForPlayer(playerid,txtTimeDisp);
  81. // Update time
  82. if(!worldtime_override) {
  83. gettime(hour, minute);
  84. } else {
  85. hour = worldtime_overridehour;
  86. minute = worldtime_overridemin;
  87. }
  88. SetPlayerTime(playerid,hour,minute);
  89. return 1;
  90. }
  91. //--------------------------------------------------
  92. public OnPlayerDeath(playerid, killerid, reason)
  93. {
  94. TextDrawHideForPlayer(playerid,txtTimeDisp);
  95. return 1;
  96. }
  97. //--------------------------------------------------
  98. public OnPlayerConnect(playerid)
  99. {
  100. gettime(hour, minute);
  101. SetPlayerTime(playerid,hour,minute);
  102. return 1;
  103. }
  104. //--------------------------------------------------
  105. public OnPlayerCommandText(playerid, cmdtext[])
  106. {
  107. new cmd[256+1];
  108. new idx;
  109. cmd = strtok(cmdtext, idx);
  110. if(!IsPlayerAdmin(playerid)) return 0; // this is an admin only script
  111. if(strcmp(cmd, "/sethour", true) == 0) {
  112. new tmp[256+1];
  113. tmp = strtok(cmdtext,idx);
  114. worldtime_override = 1;
  115. worldtime_overridehour = strval(tmp);
  116. UpdateTimeAndWeather();
  117. return 1;
  118. }
  119. if(strcmp(cmd, "/setminute", true) == 0) {
  120. new tmp[256+1];
  121. tmp = strtok(cmdtext,idx);
  122. worldtime_override = 1;
  123. worldtime_overridemin = strval(tmp);
  124. UpdateTimeAndWeather();
  125. return 1;
  126. }
  127. return 0;
  128. }