Guest User

Simple Timer

a guest
Nov 3rd, 2010
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.79 KB | None | 0 0
  1. #define BLACK 0x000000FF
  2. #define WHITE 0xFFFFFFFF
  3. #define COLOR_RED 0xE21F1FFF
  4.  
  5. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  6.  
  7. #include <a_samp>
  8.  
  9. new Text:TextZBC;
  10. new TextZBCHours, TextZBCHoursString[56];
  11. new TextZBCMinutes, TextZBCMinutesString[56];
  12. stock InitializeZBC()
  13. {
  14. TextZBC = TextDrawCreate(546.000000,22.000000,"--:--");
  15. TextDrawAlignment(TextZBC,0);
  16. TextDrawBackgroundColor(TextZBC,BLACK);
  17. TextDrawFont(TextZBC,3);
  18. TextDrawLetterSize(TextZBC,0.635,2.4);
  19. TextDrawColor(TextZBC,WHITE);
  20. TextDrawSetOutline(TextZBC,1);
  21. TextDrawSetProportional(TextZBC,1);
  22. TextDrawSetShadow(TextZBC,1);
  23. }
  24. //------------------------------------------------
  25.  
  26. public OnFilterScriptInit()
  27. {
  28. print("\n--Zinglish's Basic Clock loaded v1.3.\n");
  29. InitializeZBC();
  30. TextZBCMinutes = 00;
  31. TextZBCHours = 00;
  32. SetTimer("UpdateTime", 1000, 1);
  33. SetWorldTime(TextZBCHours);
  34. return 1;
  35. }
  36.  
  37. public OnPlayerSpawn(playerid)
  38. {
  39. TextDrawShowForPlayer(playerid, TextZBC);
  40. return 1;
  41. }
  42.  
  43. //Timer for time (lol)
  44. forward UpdateTime(playerid);
  45. public UpdateTime(playerid)
  46. {
  47. new ClockString[126];
  48. TextZBCMinutes++;
  49. // Checks for clock 'defining' minutes limit as 60 and hours limit as 24
  50. if(TextZBCMinutes == 60)
  51. {
  52. TextZBCMinutes = 00;
  53. if(TextZBCHours == 24)
  54. {
  55. TextZBCHours = 00;
  56. }
  57. TextZBCHours++;
  58. }
  59. if(TextZBCMinutes < 10)
  60. {
  61. format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "0%i", TextZBCMinutes);
  62. }
  63. if(TextZBCMinutes > 10)
  64. {
  65. format(TextZBCMinutesString, sizeof(TextZBCMinutesString), "%i", TextZBCMinutes);
  66. }
  67. if(TextZBCHours < 10)
  68. {
  69. format(TextZBCHoursString, sizeof(TextZBCHoursString), "0%i", TextZBCHours);
  70. }
  71. if(TextZBCHours > 10)
  72. {
  73. format(TextZBCHoursString, sizeof(TextZBCHoursString), "%i", TextZBCHours);
  74. }
  75. format(ClockString, sizeof(ClockString), "%s:%s", TextZBCHoursString, TextZBCMinutesString);
  76. for(new i=0; i<MAX_PLAYERS; i++)
  77. {
  78. if(IsPlayerConnected(i))
  79. {
  80. SetPlayerTime(i, TextZBCHours, TextZBCMinutes);
  81. }
  82. }
  83. TextDrawSetString(TextZBC, ClockString);
  84. }
  85.  
  86. public OnPlayerCommandText(playerid, cmdtext[])
  87. {
  88. dcmd(time,4,cmdtext);
  89.  
  90. return 0;
  91. }
  92.  
  93. dcmd_time(playerid, params[])
  94. {
  95. new time;
  96. if(sscanf(params, "i", time))
  97. {
  98. if(IsPlayerAdmin(playerid))
  99. {
  100. SendClientMessage(playerid, COLOR_RED, "Usage: /settime <0-24>");
  101. SendClientMessage(playerid, COLOR_RED, "Sets global time");
  102. }
  103. }
  104. else if(IsPlayerAdmin(playerid))
  105. {
  106. if(time < 0 || time >24)
  107. {
  108. SendClientMessage(playerid, COLOR_RED, "Time must be between 0 and 24 hours");
  109. }
  110. else if(time <= 24 && time >= 0)
  111. {
  112. TextZBCHours = time;
  113. }
  114. }
  115. else if(!IsPlayerAdmin(playerid))
  116. {
  117. SendClientMessage(playerid, COLOR_RED, "You must be admin for this command to work");
  118. }
  119.  
  120. return 1;
  121. }
  122.  
  123.  
  124. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  125. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  126. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  127. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  128. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  129. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  130. // -------------------------------------------------------------------------------------------------------------------------------------------------------------
  131.  
  132. stock sscanf(string[], format[], {Float,_}:...)
  133. {
  134. #if defined isnull
  135. if (isnull(string))
  136. #else
  137. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  138. #endif
  139. {
  140. return format[0];
  141. }
  142. #pragma tabsize 4
  143. new
  144. formatPos = 0,
  145. stringPos = 0,
  146. paramPos = 2,
  147. paramCount = numargs(),
  148. delim = ' ';
  149. while (string[stringPos] && string[stringPos] <= ' ')
  150. {
  151. stringPos++;
  152. }
  153. while (paramPos < paramCount && string[stringPos])
  154. {
  155. switch (format[formatPos++])
  156. {
  157. case '\0':
  158. {
  159. return 0;
  160. }
  161. case 'i', 'd':
  162. {
  163. new
  164. neg = 1,
  165. num = 0,
  166. ch = string[stringPos];
  167. if (ch == '-')
  168. {
  169. neg = -1;
  170. ch = string[++stringPos];
  171. }
  172. do
  173. {
  174. stringPos++;
  175. if ('0' <= ch <= '9')
  176. {
  177. num = (num * 10) + (ch - '0');
  178. }
  179. else
  180. {
  181. return -1;
  182. }
  183. }
  184. while ((ch = string[stringPos]) > ' ' && ch != delim);
  185. setarg(paramPos, 0, num * neg);
  186. }
  187. case 'h', 'x':
  188. {
  189. new
  190. ch,
  191. num = 0;
  192. while ((ch = string[stringPos]) > ' ' && ch != delim)
  193. {
  194. switch (ch)
  195. {
  196. case 'x', 'X':
  197. {
  198. num = 0;
  199. continue;
  200. }
  201. case '0' .. '9':
  202. {
  203. num = (num << 4) | (ch - '0');
  204. }
  205. case 'a' .. 'f':
  206. {
  207. num = (num << 4) | (ch - ('a' - 10));
  208. }
  209. case 'A' .. 'F':
  210. {
  211. num = (num << 4) | (ch - ('A' - 10));
  212. }
  213. default:
  214. {
  215. return -1;
  216. }
  217. }
  218. }
  219. setarg(paramPos, 0, num);
  220. }
  221. case 'c':
  222. {
  223. setarg(paramPos, 0, string[stringPos++]);
  224. }
  225. case 'f':
  226. {
  227. setarg(paramPos, 0, _:floatstr(string[stringPos]));
  228. }
  229. case 'p':
  230. {
  231. delim = format[formatPos++];
  232. continue;
  233. }
  234. case '\'':
  235. {
  236. new
  237. end = formatPos - 1,
  238. ch;
  239. while ((ch = format[++end]) && ch != '\'') {}
  240. if (!ch)
  241. {
  242. return -1;
  243. }
  244. format[end] = '\0';
  245. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  246. {
  247. if (format[end + 1])
  248. {
  249. return -1;
  250. }
  251. return 0;
  252. }
  253. format[end] = '\'';
  254. stringPos = ch + (end - formatPos);
  255. formatPos = end + 1;
  256. }
  257. case 'u':
  258. {
  259. new
  260. end = stringPos - 1,
  261. id = 0,
  262. bool:num = true,
  263. ch;
  264. while ((ch = string[++end]) && ch != delim)
  265. {
  266. if (num)
  267. {
  268. if ('0' <= ch <= '9')
  269. {
  270. id = (id * 10) + (ch - '0');
  271. }
  272. else
  273. {
  274. num = false;
  275. }
  276. }
  277. }
  278. if (num && IsPlayerConnected(id))
  279. {
  280. setarg(paramPos, 0, id);
  281. }
  282. else
  283. {
  284. #if !defined foreach
  285. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  286. #define __SSCANF_FOREACH__
  287. #endif
  288. string[end] = '\0';
  289. num = false;
  290. new
  291. name[MAX_PLAYER_NAME];
  292. id = end - stringPos;
  293. foreach (Player, playerid)
  294. {
  295. GetPlayerName(playerid, name, sizeof (name));
  296. if (!strcmp(name, string[stringPos], true, id))
  297. {
  298. setarg(paramPos, 0, playerid);
  299. num = true;
  300. break;
  301. }
  302. }
  303. if (!num)
  304. {
  305. setarg(paramPos, 0, INVALID_PLAYER_ID);
  306. }
  307. string[end] = ch;
  308. #if defined __SSCANF_FOREACH__
  309. #undef foreach
  310. #undef __SSCANF_FOREACH__
  311. #endif
  312. }
  313. stringPos = end;
  314. }
  315. case 's', 'z':
  316. {
  317. new
  318. i = 0,
  319. ch;
  320. if (format[formatPos])
  321. {
  322. while ((ch = string[stringPos++]) && ch != delim)
  323. {
  324. setarg(paramPos, i++, ch);
  325. }
  326. if (!i)
  327. {
  328. return -1;
  329. }
  330. }
  331. else
  332. {
  333. while ((ch = string[stringPos++]))
  334. {
  335. setarg(paramPos, i++, ch);
  336. }
  337. }
  338. stringPos--;
  339. setarg(paramPos, i, '\0');
  340. }
  341. default:
  342. {
  343. continue;
  344. }
  345. }
  346. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  347. {
  348. stringPos++;
  349. }
  350. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  351. {
  352. stringPos++;
  353. }
  354. paramPos++;
  355. }
  356. do
  357. {
  358. if ((delim = format[formatPos++]) > ' ')
  359. {
  360. if (delim == '\'')
  361. {
  362. while ((delim = format[formatPos++]) && delim != '\'') {}
  363. }
  364. else if (delim != 'z')
  365. {
  366. return delim;
  367. }
  368. }
  369. }
  370. while (delim > ' ');
  371. return 0;
  372. }
Advertisement
Add Comment
Please, Sign In to add comment