Advertisement
Guest User

Giacomand

a guest
Jan 30th, 2010
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. #define grey 0xAFAFAFAA
  5. #define red 0xAA3333AA
  6.  
  7. //Choose a type, if 1 it'll be a simple message box. If 2 then there will be an input box to send messages while frozen.
  8. new TYPE = 2;
  9. //
  10.  
  11. new Frozen[MAX_PLAYERS];
  12. new Talk[MAX_PLAYERS];
  13. new Spam[MAX_PLAYERS];
  14.  
  15. forward SpamTimer();
  16.  
  17. public OnFilterScriptInit()
  18. {
  19. print("\n--------------------------------------");
  20. print("Take Damage While Frozen - by Giacomand ");
  21. print("--------------------------------------\n");
  22. SetTimer("SpamTimer", 1000, 1);
  23. return 1;
  24. }
  25.  
  26. public OnFilterScriptExit()
  27. {
  28. return 1;
  29. }
  30.  
  31. public SpamTimer()
  32. {
  33. for(new i = 0; i < MAX_PLAYERS; i++)
  34. {
  35. if(Spam[i] > 0)
  36. {
  37. Spam[i]--;
  38. }
  39. }
  40. return 1;
  41. }
  42.  
  43. //ZCMD Commands
  44.  
  45. command(freezeex, playerid, params[])
  46. {
  47. new targetid;
  48. new string[128];
  49. if(!sscanf(params, "u", targetid))
  50. {
  51. if(targetid != INVALID_PLAYER_ID)
  52. {
  53. Frozen[targetid] = 1;
  54. format(string, sizeof(string), "You have frozen %s", Name(targetid));
  55. SendClientMessage(playerid, grey, string);
  56. format(string, sizeof(string), "You have been frozen by Admin %s", Name(playerid));
  57. ShowPlayerDialog(playerid,665,DIALOG_STYLE_MSGBOX,"FROZEN",string,"Frozen","");
  58.  
  59. }
  60. else
  61. {
  62. SendClientMessage(playerid, red, "Player is not connected");
  63. }
  64. }
  65. else
  66. {
  67. SendClientMessage(playerid, grey, "Usage: /(un)freezeEx [playerid/partofname]");
  68. }
  69. return 1;
  70. }
  71.  
  72. command(unfreezeex, playerid, params[])
  73. {
  74. new targetid;
  75. new string[128];
  76. if(!sscanf(params, "u", targetid))
  77. {
  78. if(targetid != INVALID_PLAYER_ID)
  79. {
  80.  
  81. Frozen[targetid] = 0;
  82. format(string, sizeof(string), "You have thawed %s", Name(targetid));
  83. SendClientMessage(playerid, grey, string);
  84. format(string, sizeof(string), "You have been thawed by Admin %s", Name(playerid));
  85. SendClientMessage(playerid, grey, string);
  86. ShowPlayerDialog(playerid,666,DIALOG_STYLE_MSGBOX,"THAWED",string,"Thaw me","");
  87. Talk[targetid] = 0;
  88.  
  89. }
  90. else
  91. {
  92. SendClientMessage(playerid, red, "Player is not connected");
  93. }
  94. }
  95. else
  96. {
  97. SendClientMessage(playerid, grey, "Usage: /(un)freezeEx [playerid/partofname]");
  98. }
  99. return 1;
  100. }
  101.  
  102. public OnPlayerRequestClass(playerid, classid)
  103. {
  104. return 1;
  105. }
  106.  
  107. public OnPlayerConnect(playerid)
  108. {
  109. Frozen[playerid] = 0;
  110. Talk[playerid] = 0;
  111. Spam[playerid] = 0;
  112. return 1;
  113. }
  114.  
  115. public OnPlayerDisconnect(playerid, reason)
  116. {
  117. Frozen[playerid] = 0;
  118. Talk[playerid] = 0;
  119. Spam[playerid] = 0;
  120. return 1;
  121. }
  122.  
  123. public OnPlayerSpawn(playerid)
  124. {
  125. Frozen[playerid] = 0;
  126. return 1;
  127. }
  128.  
  129. public OnPlayerDeath(playerid, killerid, reason)
  130. {
  131. Frozen[playerid] = 0;
  132. return 1;
  133. }
  134.  
  135. public OnPlayerText(playerid, text[])
  136. {
  137. return 1;
  138. }
  139.  
  140.  
  141. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  142. {
  143. if(dialogid == 665)
  144. {
  145. if(TYPE == 1)
  146. {
  147. ShowPlayerDialog(playerid,665,DIALOG_STYLE_MSGBOX,"FROZEN","Wait for an admin to thaw you.","","");
  148. }
  149. if(Talk[playerid] == 1)
  150. {
  151. if(Spam[playerid] <= 0)
  152. {
  153. // Insert custom text talk here, for my example I'll use "SendClientMessageToAll
  154. SendClientMessageToAll(grey, inputtext);
  155. }
  156. else
  157. {
  158. SendClientMessage(playerid, red, "Wait a second or two.");
  159. }
  160. }
  161. if(TYPE == 2)
  162. {
  163. Talk[playerid] = 1;
  164. ShowPlayerDialog(playerid ,665,DIALOG_STYLE_INPUT,"FROZEN","Speak in chat while frozen:","Talk","");
  165. Spam[playerid] = 2;
  166. }
  167. }
  168. return 1;
  169. }
  170.  
  171. stock Name(playerid) //By Alex "Y_Less" Cole
  172. {
  173. new plname[24];
  174. GetPlayerName(playerid, plname, sizeof(plname));
  175. return plname;
  176. }
  177.  
  178. /*----------------------------------------------------------------------------*-
  179. Function:
  180. sscanf
  181. Params:
  182. string[] - String to extract parameters from.
  183. format[] - Parameter types to get.
  184. {Float,_}:... - Data return variables.
  185. Return:
  186. 0 - Successful, not 0 - fail.
  187. Notes:
  188. A fail is either insufficient variables to store the data or insufficient
  189. data for the format string - excess data is disgarded.
  190.  
  191. A string in the middle of the input data is extracted as a single word, a
  192. string at the end of the data collects all remaining text.
  193.  
  194. The format codes are:
  195.  
  196. c - A character.
  197. d, i - An integer.
  198. h, x - A hex number (e.g. a colour).
  199. f - A float.
  200. s - A string.
  201. z - An optional string.
  202. pX - An additional delimiter where X is another character.
  203. '' - Encloses a litteral string to locate.
  204. u - User, takes a name, part of a name or an id and returns the id if they're connected.
  205.  
  206. Now has IsNumeric integrated into the code.
  207.  
  208. Added additional delimiters in the form of all whitespace and an
  209. optioanlly specified one in the format string.
  210. -*----------------------------------------------------------------------------*/
  211.  
  212. stock sscanf(string[], format[], {Float,_}:...)
  213. {
  214. #if defined isnull
  215. if (isnull(string))
  216. #else
  217. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  218. #endif
  219. {
  220. return format[0];
  221. }
  222. #pragma tabsize 4
  223. new
  224. formatPos = 0,
  225. stringPos = 0,
  226. paramPos = 2,
  227. paramCount = numargs(),
  228. delim = ' ';
  229. while (string[stringPos] && string[stringPos] <= ' ')
  230. {
  231. stringPos++;
  232. }
  233. while (paramPos < paramCount && string[stringPos])
  234. {
  235. switch (format[formatPos++])
  236. {
  237. case '\0':
  238. {
  239. return 0;
  240. }
  241. case 'i', 'd':
  242. {
  243. new
  244. neg = 1,
  245. num = 0,
  246. ch = string[stringPos];
  247. if (ch == '-')
  248. {
  249. neg = -1;
  250. ch = string[++stringPos];
  251. }
  252. do
  253. {
  254. stringPos++;
  255. if ('0' <= ch <= '9')
  256. {
  257. num = (num * 10) + (ch - '0');
  258. }
  259. else
  260. {
  261. return -1;
  262. }
  263. }
  264. while ((ch = string[stringPos]) > ' ' && ch != delim);
  265. setarg(paramPos, 0, num * neg);
  266. }
  267. case 'h', 'x':
  268. {
  269. new
  270. num = 0,
  271. ch = string[stringPos];
  272. do
  273. {
  274. stringPos++;
  275. switch (ch)
  276. {
  277. case 'x', 'X':
  278. {
  279. num = 0;
  280. continue;
  281. }
  282. case '0' .. '9':
  283. {
  284. num = (num << 4) | (ch - '0');
  285. }
  286. case 'a' .. 'f':
  287. {
  288. num = (num << 4) | (ch - ('a' - 10));
  289. }
  290. case 'A' .. 'F':
  291. {
  292. num = (num << 4) | (ch - ('A' - 10));
  293. }
  294. default:
  295. {
  296. return -1;
  297. }
  298. }
  299. }
  300. while ((ch = string[stringPos]) > ' ' && ch != delim);
  301. setarg(paramPos, 0, num);
  302. }
  303. case 'c':
  304. {
  305. setarg(paramPos, 0, string[stringPos++]);
  306. }
  307. case 'f':
  308. {
  309. setarg(paramPos, 0, _:floatstr(string[stringPos]));
  310. }
  311. case 'p':
  312. {
  313. delim = format[formatPos++];
  314. continue;
  315. }
  316. case '\'':
  317. {
  318. new
  319. end = formatPos - 1,
  320. ch;
  321. while ((ch = format[++end]) && ch != '\'') {}
  322. if (!ch)
  323. {
  324. return -1;
  325. }
  326. format[end] = '\0';
  327. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  328. {
  329. if (format[end + 1])
  330. {
  331. return -1;
  332. }
  333. return 0;
  334. }
  335. format[end] = '\'';
  336. stringPos = ch + (end - formatPos);
  337. formatPos = end + 1;
  338. }
  339. case 'u':
  340. {
  341. new
  342. end = stringPos - 1,
  343. id = 0,
  344. bool:num = true,
  345. ch;
  346. while ((ch = string[++end]) && ch != delim)
  347. {
  348. if (num)
  349. {
  350. if ('0' <= ch <= '9')
  351. {
  352. id = (id * 10) + (ch - '0');
  353. }
  354. else
  355. {
  356. num = false;
  357. }
  358. }
  359. }
  360. if (num && IsPlayerConnected(id))
  361. {
  362. setarg(paramPos, 0, id);
  363. }
  364. else
  365. {
  366. #if !defined foreach
  367. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  368. #define __SSCANF_FOREACH__
  369. #endif
  370. string[end] = '\0';
  371. num = false;
  372. new
  373. name[MAX_PLAYER_NAME];
  374. id = end - stringPos;
  375. foreach (Player, playerid)
  376. {
  377. GetPlayerName(playerid, name, sizeof (name));
  378. if (!strcmp(name, string[stringPos], true, id))
  379. {
  380. setarg(paramPos, 0, playerid);
  381. num = true;
  382. break;
  383. }
  384. }
  385. if (!num)
  386. {
  387. setarg(paramPos, 0, INVALID_PLAYER_ID);
  388. }
  389. string[end] = ch;
  390. #if defined __SSCANF_FOREACH__
  391. #undef foreach
  392. #undef __SSCANF_FOREACH__
  393. #endif
  394. }
  395. stringPos = end;
  396. }
  397. case 's', 'z':
  398. {
  399. new
  400. i = 0,
  401. ch;
  402. if (format[formatPos])
  403. {
  404. while ((ch = string[stringPos++]) && ch != delim)
  405. {
  406. setarg(paramPos, i++, ch);
  407. }
  408. if (!i)
  409. {
  410. return -1;
  411. }
  412. }
  413. else
  414. {
  415. while ((ch = string[stringPos++]))
  416. {
  417. setarg(paramPos, i++, ch);
  418. }
  419. }
  420. stringPos--;
  421. setarg(paramPos, i, '\0');
  422. }
  423. default:
  424. {
  425. continue;
  426. }
  427. }
  428. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  429. {
  430. stringPos++;
  431. }
  432. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  433. {
  434. stringPos++;
  435. }
  436. paramPos++;
  437. }
  438. do
  439. {
  440. if ((delim = format[formatPos++]) > ' ')
  441. {
  442. if (delim == '\'')
  443. {
  444. while ((delim = format[formatPos++]) && delim != '\'') {}
  445. }
  446. else if (delim != 'z')
  447. {
  448. return delim;
  449. }
  450. }
  451. }
  452. while (delim > ' ');
  453. return 0;
  454. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement