Advertisement
exod182

IRC Filterscript

Jun 12th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. #include <a_samp>
  3. #include <ocmd>
  4. ////////////////////////////////////////////////////////////////////////////////
  5. #define Creator "Exod_Martinez"
  6. #define Version "1.0"
  7. ////////////////////////////////////////////////////////////////////////////////
  8. new IRCCHANNEL[MAX_PLAYERS] = -1;
  9. ////////////////////////////////////////////////////////////////////////////////
  10. public OnFilterScriptInit()
  11. {
  12. print("\n--------------------------------------");
  13. printf(" IRC Filterscript by %s ",Creator);
  14. printf(" Version %s, ", Version);
  15. print("--------------------------------------\n");
  16. return 1;
  17. }
  18. ////////////////////////////////////////////////////////////////////////////////
  19. ocmd:irc(playerid, params[])
  20. {
  21. new channel;
  22. if(sscanf(params,"d",channel))return SendClientMessage(playerid, -1, "Benutzung: '/irc [Channelnummer]");
  23. IRCCHANNEL[playerid] = channel;
  24. return 1;
  25. }
  26.  
  27. ocmd:leaveirc(playerid)
  28. {
  29. IRCCHANNEL[playerid] = -1;
  30. SendClientMessage(playerid, -1, "Du hast den IRC Channel verlassen");
  31. }
  32.  
  33. ocmd:i(playerid, params[])
  34. {
  35. new text[256];
  36. if(IRCCHANNEL[playerid] == -1)return SendClientMessage(playerid, -1, "Du bist in keinem IRC Channel");
  37. if(sscanf(params,"s",text))return SendClientMessage(playerid, -1, "Benutzung: '/i [TEXT]");
  38. for(new i = 0; i < MAX_PLAYERS; i++)
  39. {
  40. if(IRCCHANNEL[i] == IRCCHANNEL[playerid])
  41. {
  42. SendClientMessage(i,-1,text);
  43. }
  44. }
  45. return 1;
  46. }
  47.  
  48. ////////////////////////////////////////////////////////////////////////////////
  49. public OnFilterScriptExit()
  50. {
  51. print("IRC Filterscript entladen");
  52. return 1;
  53. }
  54. ////////////////////////////////////////////////////////////////////////////////
  55. public OnPlayerConnect(playerid)
  56. {
  57. IRCCHANNEL[playerid] = -1;
  58. return 1;
  59. }
  60. ////////////////////////////////////////////////////////////////////////////////
  61. stock sscanf(string[], format[], {Float,_}:...)
  62. {
  63. #if defined isnull
  64. if (isnull(string))
  65. #else
  66. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  67. #endif
  68. {
  69. return format[0];
  70. }
  71. #pragma tabsize 4
  72. new
  73. formatPos = 0,
  74. stringPos = 0,
  75. paramPos = 2,
  76. paramCount = numargs(),
  77. delim = ' ';
  78. while (string[stringPos] && string[stringPos] <= ' ')
  79. {
  80. stringPos++;
  81. }
  82. while (paramPos < paramCount && string[stringPos])
  83. {
  84. switch (format[formatPos++])
  85. {
  86. case '\0':
  87. {
  88. return 0;
  89. }
  90. case 'i', 'd':
  91. {
  92. new
  93. neg = 1,
  94. num = 0,
  95. ch = string[stringPos];
  96. if (ch == '-')
  97. {
  98. neg = -1;
  99. ch = string[++stringPos];
  100. }
  101. do
  102. {
  103. stringPos++;
  104. if ('0' <= ch <= '9')
  105. {
  106. num = (num * 10) + (ch - '0');
  107. }
  108. else
  109. {
  110. return -1;
  111. }
  112. }
  113. while ((ch = string[stringPos]) > ' ' && ch != delim);
  114. setarg(paramPos, 0, num * neg);
  115. }
  116. case 'h', 'x':
  117. {
  118. new
  119. num = 0,
  120. ch = string[stringPos];
  121. do
  122. {
  123. stringPos++;
  124. switch (ch)
  125. {
  126. case 'x', 'X':
  127. {
  128. num = 0;
  129. continue;
  130. }
  131. case '0' .. '9':
  132. {
  133. num = (num << 4) | (ch - '0');
  134. }
  135. case 'a' .. 'f':
  136. {
  137. num = (num << 4) | (ch - ('a' - 10));
  138. }
  139. case 'A' .. 'F':
  140. {
  141. num = (num << 4) | (ch - ('A' - 10));
  142. }
  143. default:
  144. {
  145. return -1;
  146. }
  147. }
  148. }
  149. while ((ch = string[stringPos]) > ' ' && ch != delim);
  150. setarg(paramPos, 0, num);
  151. }
  152. case 'c':
  153. {
  154. setarg(paramPos, 0, string[stringPos++]);
  155. }
  156. case 'f':
  157. {
  158.  
  159. new changestr[16], changepos = 0, strpos = stringPos;
  160. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  161. {
  162. changestr[changepos++] = string[strpos++];
  163. }
  164. changestr[changepos] = '\0';
  165. setarg(paramPos,0,_:floatstr(changestr));
  166. }
  167. case 'p':
  168. {
  169. delim = format[formatPos++];
  170. continue;
  171. }
  172. case '\'':
  173. {
  174. new
  175. end = formatPos - 1,
  176. ch;
  177. while ((ch = format[++end]) && ch != '\'') {}
  178. if (!ch)
  179. {
  180. return -1;
  181. }
  182. format[end] = '\0';
  183. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  184. {
  185. if (format[end + 1])
  186. {
  187. return -1;
  188. }
  189. return 0;
  190. }
  191. format[end] = '\'';
  192. stringPos = ch + (end - formatPos);
  193. formatPos = end + 1;
  194. }
  195. case 'u':
  196. {
  197. new
  198. end = stringPos - 1,
  199. id = 0,
  200. bool:num = true,
  201. ch;
  202. while ((ch = string[++end]) && ch != delim)
  203. {
  204. if (num)
  205. {
  206. if ('0' <= ch <= '9')
  207. {
  208. id = (id * 10) + (ch - '0');
  209. }
  210. else
  211. {
  212. num = false;
  213. }
  214. }
  215. }
  216. if (num && IsPlayerConnected(id))
  217. {
  218. setarg(paramPos, 0, id);
  219. }
  220. else
  221. {
  222. #if !defined foreach
  223. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  224. #define __SSCANF_FOREACH__
  225. #endif
  226. string[end] = '\0';
  227. num = false;
  228. new
  229. name[MAX_PLAYER_NAME];
  230. id = end - stringPos;
  231. foreach (Player, playerid)
  232. {
  233. GetPlayerName(playerid, name, sizeof (name));
  234. if (!strcmp(name, string[stringPos], true, id))
  235. {
  236. setarg(paramPos, 0, playerid);
  237. num = true;
  238. break;
  239. }
  240. }
  241. if (!num)
  242. {
  243. setarg(paramPos, 0, INVALID_PLAYER_ID);
  244. }
  245. string[end] = ch;
  246. #if defined __SSCANF_FOREACH__
  247. #undef foreach
  248. #undef __SSCANF_FOREACH__
  249. #endif
  250. }
  251. stringPos = end;
  252. }
  253. case 's', 'z':
  254. {
  255. new
  256. i = 0,
  257. ch;
  258. if (format[formatPos])
  259. {
  260. while ((ch = string[stringPos++]) && ch != delim)
  261. {
  262. setarg(paramPos, i++, ch);
  263. }
  264. if (!i)
  265. {
  266. return -1;
  267. }
  268. }
  269. else
  270. {
  271. while ((ch = string[stringPos++]))
  272. {
  273. setarg(paramPos, i++, ch);
  274. }
  275. }
  276. stringPos--;
  277. setarg(paramPos, i, '\0');
  278. }
  279. default:
  280. {
  281. continue;
  282. }
  283. }
  284. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  285. {
  286. stringPos++;
  287. }
  288. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  289. {
  290. stringPos++;
  291. }
  292. paramPos++;
  293. }
  294. do
  295. {
  296. if ((delim = format[formatPos++]) > ' ')
  297. {
  298. if (delim == '\'')
  299. {
  300. while ((delim = format[formatPos++]) && delim != '\'') {}
  301. }
  302. else if (delim != 'z')
  303. {
  304. return delim;
  305. }
  306. }
  307. }
  308. while (delim > ' ');
  309. return 0;
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement