Guest User

[FS] Custom Clock 2.0

a guest
Jun 5th, 2011
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #if defined FILTERSCRIPT
  4.  
  5. #define CLOCKSPEED 3 //How much faster the in-game time is compared to the real time. Higher numbers is faster speed, Lower numbers is slower speed
  6. #define CLOCKCYCLE 24 //24-hour clock or 12-hour clock
  7.  
  8. new Text:Clock; //The clock textdraw
  9. new hour, minute; //The hours and minutes for the textdraw
  10.  
  11. forward Time(); //Forward for the timer
  12.  
  13. public OnFilterScriptInit()
  14. {
  15. print("\n====================================="
  16. print("Custom Clock Speed FS. Made by 1D10T."
  17. print("=====================================\n"
  18. return 1;
  19. }
  20.  
  21. public OnGameModeInit()
  22. {
  23. if(CLOCKCYCLE == 24)
  24. {
  25. Clock = TextDrawCreate( 549, 24, "0:00" ); //The textdraw itself
  26. TextDrawLetterSize( Clock, 0.55, 2 );
  27. TextDrawFont( Clock, 3 );
  28. TextDrawBackgroundColor( Clock, 0x000000AA );
  29. TextDrawSetOutline( Clock, 2 );
  30. }
  31. else
  32. {
  33. if(CLOCKCYCLE == 12)
  34. {
  35. Clock = TextdrawCreate( 549, 24, "00:00 - AM );
  36. TextDrawLetterSize( Clock, 0.55, 2 );
  37. TextDrawFront( Clock, 3 );
  38. TextDrawBackgroundColor( Clock, 0x000000AA );
  39. TextDrawSetOutLine( Clock, 2 );
  40. }
  41. }
  42. SetWorldTime( 0 );
  43.  
  44. SetTimer( "Time", 1/CLOCKSPEED*60000, 1 ); //1 is devided by the clockspeed and then multiplied by 60000milliseconds (1 mintue)
  45.  
  46. return 1;
  47. }
  48.  
  49. public Time() //Where the 'magic' happens
  50. {
  51. new string[128];
  52.  
  53. if( CLOCKCYCLE == 24 ) //24 Hour clock
  54. {
  55. if( hour <= 23 )
  56. {
  57. if( minute <= 59 ) //End of the hour
  58. {
  59. if( minute <= 9 ) //For making 0:09 instead of 0:9
  60. {
  61. format( string, 25, "%d:0%d", hour, minute );
  62. minute++; //adds one to the minute of the function
  63. }
  64. else
  65. {
  66. format( string, 25, "%d:%d", hour, minute );
  67. minute++;
  68. }
  69. }
  70. else
  71. {
  72. if( minute == 60 ) //makes it nexthour:00 instead of going from currenthour:60 to nexthour:00
  73. {
  74. minute = 0; //resets the minute so it can continue itself
  75. hour++; //Adds one to the hour of the function
  76. format( string, 25, "%d:0%d", hour, minute );
  77. SetWorldTime( hour ); //Syncs the time with the time effect of the game (light and dark)
  78. }
  79. }
  80. }
  81. else
  82. {
  83. if( hour == 24 ) //makes it 0:00 instead of going from 24:00 to 0:00
  84. {
  85. hour = 0; //resets the hour so it can continue itself
  86. format( string, 25, "%d:0%d", hour, minute );
  87. SetWorldTime( hour );
  88. }
  89. }
  90.  
  91. for(new i = 0; i < MAX_PLAYERS; i++) //Assuming you won't get errors with the MAX_PLAYERS since this is pretty much a basic structure for every script
  92. {
  93. TextDrawHideForPlayer( i, Clock ); //removes the current textdraw
  94. TextDrawSetString( Clock, string ); //Updates the new time
  95. TextDrawShowForPlayer( i, Clock ); //Shows the updated clock
  96. }
  97. }
  98. else
  99. {
  100. if( CLOCKCYCLE == 12 ) //12 Hour clock
  101. {
  102. if( hour <= 23 )
  103. {
  104. if( hour <= 12 )
  105. {
  106. if( minute <= 59 )
  107. {
  108. if( minute <= 9 )
  109. {
  110. format( string, 25, "%d:0%d - AM );
  111. minute++;
  112. }
  113. else
  114. {
  115. format( string, 25, "%d:%d - AM );
  116. minute++;
  117. }
  118. }
  119. else
  120. {
  121. if( minute == 60 )
  122. {
  123. if( hour <= 11 ) //When its before 12AM
  124. {
  125. minute = 0;
  126. hour++;
  127. format( string, 25, "%d:0%d - AM", hour, minute );
  128. SetWorldTime( hour );
  129. }
  130. else
  131. {
  132. if( hour == 12 ) //When its 12AM
  133. {
  134. minute = 0;
  135. hour++;
  136. format( string, 25, "%d:0%d - PM", hour-12, minute );
  137. SetWorldTime( hour );
  138. }
  139. }
  140. }
  141. }
  142. }
  143. else
  144. {
  145. if( hour >= 13 )
  146. {
  147. if( minute <= 59 )
  148. {
  149. if( mintue <= 9 )
  150. {
  151. format( string, 25, "%d:0%d - PM", hour-12, minute );
  152. minute++;
  153. }
  154. else
  155. {
  156. format( string, 25, "%d:%d - PM", hour-12, minute );
  157. minute++;
  158. }
  159. }
  160. else
  161. {
  162. if( minute == 60 )
  163. {
  164. if( hour <= 23 ) //When its before 12PM
  165. {
  166. minute = 0;
  167. hour++;
  168. format( string, 25, "%d:0%d - PM", hour-12, minute );
  169. SetWorldTime( hour );
  170. }
  171. else
  172. {
  173. if( hour == 24 )
  174. {
  175. minute = 0;
  176. hour = 0;
  177. format( string, 25, "%d:0%d - AM", hour, minute );
  178. SetWorldTime( hour );
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }
  186. }
  187.  
  188. for(new i = 0; i < MAX_PLAYERS; i++)
  189. {
  190. TextDrawHideForPlayer( i, Clock );
  191. TextDrawSetString( Clock, string );
  192. TextDrawShowForPlayer( i, Clock );
  193. }
  194. }
  195. return 1;
  196. }
  197.  
  198. public OnPlayerSpawn( playerid )
  199. {
  200. TextDrawShowForPlayer( playerid, Clock ); //Show the clock after you have spawned (whatever the reason) because textdraws are destroyed after a respawn
  201. }
  202.  
  203. #endif
Advertisement
Add Comment
Please, Sign In to add comment