Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2008
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  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.  
  210. public OnPlayerCommandText(playerid, cmdtext[])
  211. {
  212. dcmd(hit, 3, cmdtext);
  213.  
  214. if(!strcmp(cmdtext, "/hits", true))
  215. {
  216. new count = 0;
  217. SendClientMessage(playerid, COLOR_MSG, "Listing currently placed hits:");
  218. for(new i = 0; i < MAX_PLAYERS; i++)
  219. {
  220. if(IsPlayerConnected(i) && hit[i] > 0)
  221. {
  222. new string[256];
  223. format(string, 256, "Hit on %s (%i) for $%i", ReturnPlayerName(i), i, hit[i]);
  224. SendClientMessage(playerid, COLOR_FOUND, string);
  225. count++;
  226. }
  227. }
  228. if(count == 0)
  229. {
  230. SendClientMessage(playerid, COLOR_ERROR, "No hits placed at this time!");
  231. }
  232. }
  233. return 0;
  234. }
  235.  
  236.  
  237. public OnPlayerDeath(playerid, killerid, reason)
  238. {
  239. if(reason <= 46 && hit[playerid] != 0)
  240. {
  241. new string[256];
  242. format(string, sizeof(string), "%s (%i) killed %s (%i) and recieved $%i for a completed hit", ReturnPlayerName(killerid), killerid, ReturnPlayerName(playerid), playerid, hit[playerid]);
  243. SendClientMessageToAll(COLOR_MSG, string);
  244. GivePlayerMoney(killerid, hit[playerid]);
  245. GivePlayerMoney(hiter[playerid], GetPlayerMoney(hiter[playerid])-hit[playerid]);
  246. hit[playerid] = 0;
  247. }
  248. else if(hit[playerid] != 0)
  249. {
  250. new string[256];
  251. format(string, sizeof(string), "The hit on %s (%i) has been cancelled (died)", ReturnPlayerName(playerid), playerid);
  252. SendClientMessageToAll(COLOR_MSG, string);
  253. hit[playerid] = 0;
  254. }
  255. return 1;
  256. }
  257.  
  258.  
  259. public OnPlayerDisconnect(playerid)
  260. {
  261. if(hit[playerid] > 0)
  262. {
  263. new string[256];
  264. format(string, sizeof(string), "The hit on %s (%i) has been cancelled (disconnected)", ReturnPlayerName(playerid), playerid);
  265. SendClientMessageToAll(COLOR_MSG, string);
  266. hit[playerid] = 0;
  267. }
  268. return 1;
  269. }
  270.  
  271. forward antispamtimer(id);
  272.  
  273. public antispamtimer(id)
  274. {
  275. antispam[id] = 0;
  276. }
  277.  
  278.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement