Advertisement
Guest User

Relogio 0.2

a guest
Jun 23rd, 2011
1,420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. /*--------------------------------------------------------------------
  2. -----------------------[ Relogio by Dr_Pawn ]-----------------------
  3. ------------------------------------------------------------------*/
  4.  
  5. /*------------------------------------------------------------ INCLIDE/DEFINES*/
  6.  
  7. #include a_samp
  8.  
  9. #define RELOGIO_TAMANHO_PEQUENO 0
  10. #define RELOGIO_TAMANHO_MEDIO 1
  11. #define RELOGIO_TAMANHO_GRANDE 2
  12.  
  13. /*-------------------------------------------------------------------- FORWARD*/
  14.  
  15. forward LigarRelogio(Tamanho, bool:Real);
  16. forward DesligarRelogio();
  17. forward HorasRelogio(bool:Real);
  18.  
  19. /*------------------------------------------------------------------------ NEW*/
  20.  
  21. new Text:Relogio,
  22. RelogioFunc[3],
  23. bool:RelogioLigado,
  24. bool:RelogioReal;
  25.  
  26. /*--------------------------------------------------------------- FILTERSCRIPT*/
  27.  
  28. public LigarRelogio(Tamanho, bool:Real)
  29. {
  30. if(Tamanho == RELOGIO_TAMANHO_PEQUENO)
  31. {
  32. Relogio = TextDrawCreate(562.500000, 5.000000, "23:59");
  33. TextDrawLetterSize(Relogio, 0.250000, 1.700000);
  34. }
  35. else if(Tamanho == RELOGIO_TAMANHO_MEDIO)
  36. {
  37. Relogio = TextDrawCreate(556.500000, 5.000000, "23:59");
  38. TextDrawLetterSize(Relogio, 0.299999, 2.000000);
  39. }
  40. else if(Tamanho == RELOGIO_TAMANHO_GRANDE)
  41. {
  42. Relogio = TextDrawCreate(548.500000, 1.000000, "23:59");
  43. TextDrawLetterSize(Relogio, 0.399999, 2.999999);
  44. }
  45. else
  46. {
  47. printf("Nao foi possivel criar o relogio com o tamanho %d.", Tamanho);
  48. return 1;
  49. }
  50. TextDrawBackgroundColor(Relogio, 255);
  51. TextDrawFont(Relogio, 2);
  52. TextDrawColor(Relogio, -1);
  53. TextDrawSetOutline(Relogio, 1);
  54. TextDrawSetProportional(Relogio, 1);
  55.  
  56. if(Real)
  57. {
  58. new segundos;
  59. gettime(RelogioFunc[0], RelogioFunc[1], segundos);
  60. }
  61. else
  62. {
  63. RelogioFunc[0] = 12;
  64. RelogioFunc[1] = -1;
  65. }
  66.  
  67. HorasRelogio(Real);
  68. RelogioFunc[2] = SetTimerEx("HorasRelogio", 1000, true, "i", Real);
  69. RelogioReal = Real;
  70. return 1;
  71. }
  72.  
  73. public DesligarRelogio()
  74. {
  75. TextDrawHideForAll(Relogio);
  76. TextDrawDestroy(Relogio);
  77. KillTimer(RelogioFunc[2]);
  78. RelogioFunc[0] = 23;
  79. RelogioFunc[1] = 59;
  80. return 1;
  81. }
  82.  
  83. public HorasRelogio(bool:Real)
  84. {
  85. new string[12];
  86. if(Real)
  87. {
  88. new segundos;
  89. gettime(RelogioFunc[0], RelogioFunc[1], segundos);
  90. SetWorldTime(RelogioFunc[0]);
  91. format(string, sizeof(string), "%02d:%02d", RelogioFunc[0], RelogioFunc[1]);
  92. TextDrawSetString(Relogio, string);
  93. }
  94. else
  95. {
  96. RelogioFunc[1] ++;
  97. if(RelogioFunc[1] == 60)
  98. {
  99. RelogioFunc[0] ++;
  100. RelogioFunc[1] = 0;
  101. }
  102. if(RelogioFunc[0] == 24)
  103. {
  104. RelogioFunc[0] = 0;
  105. }
  106. SetWorldTime(RelogioFunc[0]);
  107. format(string, sizeof(string), "%02d:%02d", RelogioFunc[0], RelogioFunc[1]);
  108. TextDrawSetString(Relogio, string);
  109. }
  110. return 1;
  111. }
  112.  
  113. public OnFilterScriptInit()
  114. {
  115. print("---------- ------- --------- ----------");
  116. print("---------- Relogio Carregado ----------");
  117. print("---------- ------- --------- ----------");
  118. return 1;
  119. }
  120.  
  121. public OnFilterScriptExit()
  122. {
  123. if(RelogioLigado) DesligarRelogio();
  124. print("--------- ------- ------------ --------");
  125. print("--------- Relogio Descarregado --------");
  126. print("--------- ------- ------------ --------");
  127. return 1;
  128. }
  129.  
  130. public OnPlayerConnect(playerid)
  131. {
  132. TextDrawShowForPlayer(playerid, Relogio);
  133. return 1;
  134. }
  135.  
  136. public OnPlayerDisconnect(playerid, reason)
  137. {
  138. TextDrawHideForPlayer(playerid, Relogio);
  139. return 1;
  140. }
  141.  
  142. public OnPlayerCommandText(playerid, cmdtext[])
  143. {
  144. new cmd[256], idx, tmp[256], sendername[MAX_PLAYER_NAME], string[256];
  145. cmd = strtok(cmdtext, idx);
  146. GetPlayerName(playerid, sendername, sizeof(sendername));
  147.  
  148. if(strcmp(cmd, "/ligarrelogio", true) == 0)
  149. {
  150. if(IsPlayerAdmin(playerid))
  151. {
  152. if(!RelogioLigado)
  153. {
  154. tmp = strtok(cmdtext, idx);
  155. if(!strlen(tmp))
  156. {
  157. SendClientMessage(playerid, 0xAAAAAAAA, "USE: /LigarRelogio [TAMANHO] [HORAS REAIS]");
  158. return 1;
  159. }
  160. new T = strval(tmp);
  161.  
  162. if(T < RELOGIO_TAMANHO_PEQUENO || T > RELOGIO_TAMANHO_GRANDE) return SendClientMessage(playerid, 0xAAAAAAAA, "Tamanho Invalido. (De 0 á 2)");
  163.  
  164. tmp = strtok(cmdtext, idx);
  165. if(!strlen(tmp))
  166. {
  167. SendClientMessage(playerid, 0xAAAAAAAA, "USE: /LigarRelogio [TAMANHO] [HORAS REAIS]");
  168. return 1;
  169. }
  170.  
  171. new bool:Real;
  172. if(!strcmp("sim", tmp, true)) Real = true;
  173. else if(!strcmp("nao", tmp, true) || !strcmp("não", tmp, true)) Real = false;
  174. else return SendClientMessage(playerid, 0xAAAAAAAA, "Horas Reais Invalida. (Use Sim ou Não)");
  175.  
  176. LigarRelogio(T, Real);
  177. TextDrawShowForAll(Relogio);
  178. format(string, sizeof(string), "[ADMIN] %s ligou o relogio.", sendername);
  179. SendClientMessageToAll(0xDDDD00AA, string);
  180. RelogioLigado = true;
  181. return 1;
  182. }
  183. else
  184. {
  185. SendClientMessage(playerid, 0xAAAAAAAA, "O Relogio ja esta ligado.");
  186. return 1;
  187. }
  188. }
  189. else
  190. {
  191. SendClientMessage(playerid, 0xAAAAAAAA, "Você não é admin.");
  192. return 1;
  193. }
  194. }
  195.  
  196. if(strcmp(cmd, "/desligarrelogio", true) == 0)
  197. {
  198. if(IsPlayerAdmin(playerid))
  199. {
  200. if(RelogioLigado)
  201. {
  202. DesligarRelogio();
  203. format(string, sizeof(string), "[ADMIN] %s desligou o relogio.", sendername);
  204. SendClientMessageToAll(0xDDDD00AA, string);
  205. RelogioLigado = false;
  206. return 1;
  207. }
  208. else
  209. {
  210. SendClientMessage(playerid, 0xAAAAAAAA, "O Relogio ja esta desligado.");
  211. return 1;
  212. }
  213. }
  214. else
  215. {
  216. SendClientMessage(playerid, 0xAAAAAAAA, "Você não é admin.");
  217. return 1;
  218. }
  219. }
  220.  
  221. if(strcmp(cmd, "/setarhora", true) == 0)
  222. {
  223. if(IsPlayerAdmin(playerid))
  224. {
  225. if(RelogioLigado)
  226. {
  227.  
  228. if(!RelogioReal) return SendClientMessage(playerid, 0xAAAAAAAA, "Você não pode mudar as horas reais!");
  229.  
  230. tmp = strtok(cmdtext, idx);
  231. if(!strlen(tmp))
  232. {
  233. SendClientMessage(playerid, 0xAAAAAAAA, "USE: /SetarHora [HORA] [MINUTOS]");
  234. return 1;
  235. }
  236. new H = strval(tmp);
  237. tmp = strtok(cmdtext, idx);
  238. if(!strlen(tmp))
  239. {
  240. SendClientMessage(playerid, 0xAAAAAAAA, "USE: /SetarHora [HORA] [MINUTOS]");
  241. return 1;
  242. }
  243. new M = strval(tmp);
  244. if(H < 0 || H > 23 || M < 0 || M > 59)
  245. {
  246. SendClientMessage(playerid, 0xAAAAAAAA, "USE: /SetarHora [0-23] [0-59]");
  247. return 1;
  248. }
  249. RelogioFunc[0] = H;
  250. RelogioFunc[1] = M-1;
  251. KillTimer(RelogioFunc[2]);
  252. HorasRelogio(false);
  253. RelogioFunc[2] = SetTimerEx("HorasRelogio", 1000, true, "i", false);
  254. format(string, sizeof(string), "[ADMIN] %s setou a hora para %d:%d.", sendername, H, M);
  255. SendClientMessageToAll(0xDDDD00AA, string);
  256. return 1;
  257. }
  258. else
  259. {
  260. SendClientMessage(playerid, 0xAAAAAAAA, "O Relogio não esta ligado.");
  261. return 1;
  262. }
  263. }
  264. else
  265. {
  266. SendClientMessage(playerid, 0xAAAAAAAA, "Você não é admin.");
  267. return 1;
  268. }
  269. }
  270. return 0;
  271. }
  272.  
  273. strtok(const string[], &index)
  274. {
  275. new length = strlen(string);
  276. while ((index < length) && (string[index] <= ' '))
  277. {
  278. index++;
  279. }
  280.  
  281. new offset = index;
  282. new result[20];
  283. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  284. {
  285. result[index - offset] = string[index];
  286. index++;
  287. }
  288. result[index - offset] = EOS;
  289. return result;
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement