Want more features on Pastebin? Sign Up, it's FREE!
Guest

hit

By: a guest on Mar 31st, 2012  |  syntax: None  |  size: 6.36 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <a_samp>
  2.  
  3.  
  4. #define filterscript
  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.  
  8. /* ----------EDIT FROM HERE----------*/
  9. #define COLOR_FOUND 0xFFFF00AA //Color of the message if a hit was found in /hits
  10. #define COLOR_MSG 0x00FFFFFF //Color of general messages
  11. #define COLOR_ERROR 0xFF0000FF //Color of the message if there was an error
  12. #define ANTISPAM_TIME 5 //The minimum time between /hit commands to prevent spam (in seconds)
  13. /*----------NO NEED TO EDIT FROM HERE----------*/
  14.  
  15.  
  16. new hit[MAX_PLAYERS];
  17. new hiter[MAX_PLAYERS];
  18. new ID;
  19. new antispam[MAX_PLAYERS];
  20.  
  21.  
  22. stock ReturnPlayerName(id)
  23. {
  24. new tehname[MAX_PLAYER_NAME];
  25. GetPlayerName(id, tehname, sizeof(tehname));
  26. return tehname;
  27. }
  28.  
  29.  
  30. stock sscanf(string[], format[], {Float,_}:...)
  31. {
  32. new
  33. formatPos = 0,
  34. stringPos = 0,
  35. paramPos = 2,
  36. paramCount = numargs();
  37. while (paramPos < paramCount && string[stringPos])
  38. {
  39. switch (format[formatPos++])
  40. {
  41. case '\0':
  42. {
  43. return 0;
  44. }
  45. case 'i', 'd':
  46. {
  47. new
  48. neg = 1,
  49. num = 0,
  50. ch = string[stringPos];
  51. if (ch == '-')
  52. {
  53. neg = -1;
  54. ch = string[++stringPos];
  55. }
  56. do
  57. {
  58. stringPos++;
  59. if (ch >= '0' && ch <= '9')
  60. {
  61. num = (num * 10) + (ch - '0');
  62. }
  63. else
  64. {
  65. return 1;
  66. }
  67. }
  68. while ((ch = string[stringPos]) && ch != ' ');
  69. setarg(paramPos, 0, num * neg);
  70. }
  71. case 'h', 'x':
  72. {
  73. new
  74. ch,
  75. num = 0;
  76. while ((ch = string[stringPos++]))
  77. {
  78. switch (ch)
  79. {
  80. case 'x', 'X':
  81. {
  82. num = 0;
  83. continue;
  84. }
  85. case '0' .. '9':
  86. {
  87. num = (num << 4) | (ch - '0');
  88. }
  89. case 'a' .. 'f':
  90. {
  91. num = (num << 4) | (ch - ('a' - 10));
  92. }
  93. case 'A' .. 'F':
  94. {
  95. num = (num << 4) | (ch - ('A' - 10));
  96. }
  97. case ' ':
  98. {
  99. break;
  100. }
  101. default:
  102. {
  103. return 1;
  104. }
  105. }
  106. }
  107. setarg(paramPos, 0, num);
  108. }
  109. case 'c':
  110. {
  111. setarg(paramPos, 0, string[stringPos++]);
  112. }
  113. case 'f':
  114. {
  115. new tmp[25];
  116. strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
  117. setarg(paramPos, 0, _:floatstr(tmp));
  118. }
  119. case 's', 'z':
  120. {
  121. new
  122. i = 0,
  123. ch;
  124. if (format[formatPos])
  125. {
  126. while ((ch = string[stringPos++]) && ch != ' ')
  127. {
  128. setarg(paramPos, i++, ch);
  129. }
  130. if (!i) return 1;
  131. }
  132. else
  133. {
  134. while ((ch = string[stringPos++]))
  135. {
  136. setarg(paramPos, i++, ch);
  137. }
  138. }
  139. stringPos--;
  140. setarg(paramPos, i, '\0');
  141. }
  142. default:
  143. {
  144. continue;
  145. }
  146. }
  147. while (string[stringPos] && string[stringPos] != ' ')
  148. {
  149. stringPos++;
  150. }
  151. while (string[stringPos] == ' ')
  152. {
  153. stringPos++;
  154. }
  155. paramPos++;
  156. }
  157. while (format[formatPos] == 'z') formatPos++;
  158. return format[formatPos];
  159. }
  160.  
  161.  
  162. dcmd_hit(playerid, params[])
  163. {
  164. new amount;
  165. if(sscanf(params, "dd", ID, amount))
  166. {
  167. SendClientMessage(playerid, COLOR_ERROR, "USAGE: /hit [ID] [amount]");
  168. }
  169. else if(amount > 0)
  170. {
  171. if(IsPlayerConnected(ID))
  172. {
  173. if(GetPlayerMoney(playerid) >= amount)
  174. {
  175. if(antispam[playerid] == 0)
  176. {
  177. hit[ID] = amount;
  178. hiter[ID] = playerid;
  179. new string[256];
  180. format(string, sizeof(string), "You have placed a hit on %s (%i) for $%i", ReturnPlayerName(ID), ID, amount);
  181. SendClientMessage(playerid, COLOR_MSG, string);
  182. format(string, sizeof(string), "%s (%i) has placed a hit on %s (%i) for $%i", ReturnPlayerName(playerid), playerid, ReturnPlayerName(ID), ID, amount);
  183. SendClientMessageToAll(COLOR_MSG, string);
  184. antispam[playerid] = 1;
  185. SetTimerEx("antispamtimer", ANTISPAM_TIME*1000, false, "d", playerid);
  186. }
  187. else
  188. {
  189. SendClientMessage(playerid, COLOR_ERROR, "Please wait before placing another hit!");
  190. }
  191. }
  192. else
  193. {
  194. SendClientMessage(playerid, COLOR_ERROR, "You do not have enough money!");
  195. }
  196. }
  197. else
  198. {
  199. SendClientMessage(playerid, COLOR_ERROR, "That player is not connected!");
  200. }
  201. }
  202. else
  203. {
  204. SendClientMessage(playerid, COLOR_ERROR, "Minimum amount to hit a person with is $1!");
  205. }
  206. return 1;
  207. }
  208.  
  209. dcmd_cancelhit(playerid, params[])
  210. {
  211. if(sscanf(params, "d", ID))
  212. {
  213. SendClientMessage(playerid, COLOR_ERROR, "USAGE: /hit [ID]");
  214. }
  215. if(IsPlayerConnected(ID))
  216. {
  217. if(antispam[playerid] == 0)
  218. {
  219. hit[ID] = 0;
  220. hiter[ID] = playerid;
  221. /*new string[256];
  222. format(string, sizeof(string), "You have placed a hit on %s (%i) for $%i", ReturnPlayerName(ID), ID, amount);
  223. SendClientMessage(playerid, COLOR_MSG, string);
  224. format(string, sizeof(string), "%s (%i) has placed a hit on %s (%i) for $%i", ReturnPlayerName(playerid), playerid, ReturnPlayerName(ID), ID, amount);
  225. SendClientMessageToAll(COLOR_MSG, string);*/
  226. SendClientMessage(playerid, COLOR_MSG, "Hit was cancelled.");
  227. antispam[playerid] = 1;
  228. SetTimerEx("antispamtimer", ANTISPAM_TIME*1000, false, "d", playerid);
  229. }
  230. else
  231. {
  232. SendClientMessage(playerid, COLOR_ERROR, "Please wait before placing another hit!");
  233. }
  234. }
  235. else
  236. {
  237. SendClientMessage(playerid, COLOR_ERROR, "That player is not connected!");
  238. }
  239. return 1;
  240. }
  241.  
  242. public OnPlayerCommandText(playerid, cmdtext[])
  243. {
  244. dcmd(hit, 3, cmdtext);
  245. dcmd(cancelhit, 3, cmdtext);
  246.  
  247. if(!strcmp(cmdtext, "/hits", true))
  248. {
  249. new count = 0;
  250. SendClientMessage(playerid, COLOR_MSG, "Listing currently placed hits:");
  251. for(new i = 0; i < MAX_PLAYERS; i++)
  252. {
  253. if(IsPlayerConnected(i) && hit[i] > 0)
  254. {
  255. new string[256];
  256. format(string, 256, "Hit on %s (%i) for $%i", ReturnPlayerName(i), i, hit[i]);
  257. SendClientMessage(playerid, COLOR_FOUND, string);
  258. count++;
  259. }
  260. }
  261. if(count == 0)
  262. {
  263. SendClientMessage(playerid, COLOR_ERROR, "No hits placed at this time!");
  264. }
  265. }
  266. return 0;
  267. }
  268.  
  269.  
  270. public OnPlayerDeath(playerid, killerid, reason)
  271. {
  272. if(reason <= 46 && hit[playerid] != 0)
  273. {
  274. new string[256];
  275. format(string, sizeof(string), "%s (%i) killed %s (%i) and recieved $%i for a completed hit", ReturnPlayerName(killerid), killerid, ReturnPlayerName(playerid), playerid, hit[playerid]);
  276. SendClientMessageToAll(COLOR_MSG, string);
  277. GivePlayerMoney(killerid, hit[playerid]);
  278. GivePlayerMoney(hiter[playerid], GetPlayerMoney(hiter[playerid])-hit[playerid]);
  279. hit[playerid] = 0;
  280. }
  281. else if(hit[playerid] != 0)
  282. {
  283. new string[256];
  284. format(string, sizeof(string), "The hit on %s (%i) has been cancelled (died)", ReturnPlayerName(playerid), playerid);
  285. SendClientMessageToAll(COLOR_MSG, string);
  286. hit[playerid] = 0;
  287. }
  288. return 1;
  289. }
  290.  
  291.  
  292. public OnPlayerDisconnect(playerid)
  293. {
  294. if(hit[playerid] > 0)
  295. {
  296. new string[256];
  297. format(string, sizeof(string), "The hit on %s (%i) has been cancelled (disconnected)", ReturnPlayerName(playerid), playerid);
  298. SendClientMessageToAll(COLOR_MSG, string);
  299. hit[playerid] = 0;
  300. }
  301. return 1;
  302. }
  303.  
  304. forward antispamtimer(id);
  305.  
  306. public antispamtimer(id)
  307. {
  308. antispam[id] = 0;
  309. }
clone this paste RAW Paste Data