Advertisement
exod182

[SPM] Simple Private Message

Jul 28th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. /*
  2. Filterscript: Simple PN
  3.  
  4. Wäre nett, wenn das drin bleibt, denn Leute, die das raus machen, sind welche,
  5. die denken, sie könnten Scripten, sieht ja eh keiner :)
  6. Ihr dürft:
  7. - Das Script benutzen
  8. - Das Script verändern (ausser das hier oben!)
  9. Ihr dürft NICHT:
  10. - Das Script erneut releasen, ohne zu erwähnen, dass es von mir stammt
  11. - Das hier oben verändern!
  12.  
  13. Mit freundlichen Grüßen,
  14. Azure Jr.
  15. */
  16. #include <a_samp>
  17. #include <ocmd>
  18.  
  19. new axy[MAX_PLAYERS] = -1;
  20.  
  21. public OnFilterScriptInit()
  22. {
  23. print("\n-------------------------------------- ");
  24. print(" Simple PM - Simple Private Message ");
  25. print(" by Azure Jr. ");
  26. print("--------------------------------------\n ");
  27. return 1;
  28. }
  29.  
  30. public OnFilterScriptExit()
  31. {
  32. print("\n-------------------------------------- ");
  33. print(" Simple PM - Simple Private Message ");
  34. print(" by Azure Jr. ");
  35. print(" entladen ");
  36. print("--------------------------------------\n ");
  37. return 1;
  38. }
  39.  
  40. public OnPlayerConnect(playerid)
  41. {
  42. axy[playerid] = -1;
  43. return 1;
  44. }
  45.  
  46. ocmd:pm(playerid, params[])
  47. {
  48. new id, nachricht[128], string[160];
  49. if(sscanf(params, "us", id,nachricht))return SendClientMessage(playerid, -1, "Benutzung: '/pm [Name/ID] [Nachricht]'");
  50. if(!IsPlayerConnected(id))return SendClientMessage(playerid, -1, "Der Spieler ist nicht online!");
  51. format(string, sizeof(string), "[PM]Nachricht von %s: %s", SpielerName(playerid), nachricht);
  52. SendClientMessage(id, -1, string);
  53. format(string, sizeof(string), "[PM]Nachricht an %s: %s", SpielerName(id), nachricht);
  54. SendClientMessage(playerid, -1, string);
  55. axy[id] = playerid;
  56. axy[playerid] = id;
  57. return 1;
  58. }
  59.  
  60. ocmd:r(playerid, params[])return ocmd_reply(playerid, params);
  61.  
  62. ocmd:reply(playerid, params[])
  63. {
  64. new nachricht[128], string[160];
  65. if(axy[playerid] == -1)return SendClientMessage(playerid, -1, "[PM]Du hast bisher keine Nachricht geschrieben / erhalten");
  66. if(sscanf(params, "s", nachricht))return SendClientMessage(playerid, -1, "Benutzung: '/r(eply) [Nachricht]'");
  67. format(string, sizeof(string), "[PM]Nachricht von %s: %s", SpielerName(playerid), nachricht);
  68. SendClientMessage(axy[playerid], -1, string);
  69. format(string, sizeof(string), "[PM]Nachricht an %s: %s", SpielerName(axy[playerid]), nachricht);
  70. SendClientMessage(playerid, -1, string);
  71. return 1;
  72. }
  73.  
  74. public OnPlayerDisconnect(playerid, reason)
  75. {
  76. for(new i=0;i<MAX_PLAYERS;i++)
  77. {
  78. if(axy[i] == playerid)
  79. {
  80. axy[i] = INVALID_PLAYER_ID;
  81. }
  82. }
  83. axy[playerid] = -1;
  84. return 1;
  85. }
  86.  
  87. stock sscanf(string[], format[], {Float,_}:...)
  88. {
  89. #if defined isnull
  90. if (isnull(string))
  91. #else
  92. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  93. #endif
  94. {
  95. return format[0];
  96. }
  97. #pragma tabsize 4
  98. new
  99. formatPos = 0,
  100. stringPos = 0,
  101. paramPos = 2,
  102. paramCount = numargs(),
  103. delim = ' ';
  104. while (string[stringPos] && string[stringPos] <= ' ')
  105. {
  106. stringPos++;
  107. }
  108. while (paramPos < paramCount && string[stringPos])
  109. {
  110. switch (format[formatPos++])
  111. {
  112. case '\0':
  113. {
  114. return 0;
  115. }
  116. case 'i', 'd':
  117. {
  118. new
  119. neg = 1,
  120. num = 0,
  121. ch = string[stringPos];
  122. if (ch == '-')
  123. {
  124. neg = -1;
  125. ch = string[++stringPos];
  126. }
  127. do
  128. {
  129. stringPos++;
  130. if ('0' <= ch <= '9')
  131. {
  132. num = (num * 10) + (ch - '0');
  133. }
  134. else
  135. {
  136. return -1;
  137. }
  138. }
  139. while ((ch = string[stringPos]) > ' ' && ch != delim);
  140. setarg(paramPos, 0, num * neg);
  141. }
  142. case 'h', 'x':
  143. {
  144. new
  145. num = 0,
  146. ch = string[stringPos];
  147. do
  148. {
  149. stringPos++;
  150. switch (ch)
  151. {
  152. case 'x', 'X':
  153. {
  154. num = 0;
  155. continue;
  156. }
  157. case '0' .. '9':
  158. {
  159. num = (num << 4) | (ch - '0');
  160. }
  161. case 'a' .. 'f':
  162. {
  163. num = (num << 4) | (ch - ('a' - 10));
  164. }
  165. case 'A' .. 'F':
  166. {
  167. num = (num << 4) | (ch - ('A' - 10));
  168. }
  169. default:
  170. {
  171. return -1;
  172. }
  173. }
  174. }
  175. while ((ch = string[stringPos]) > ' ' && ch != delim);
  176. setarg(paramPos, 0, num);
  177. }
  178. case 'c':
  179. {
  180. setarg(paramPos, 0, string[stringPos++]);
  181. }
  182. case 'f':
  183. {
  184.  
  185. new changestr[16], changepos = 0, strpos = stringPos;
  186. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  187. {
  188. changestr[changepos++] = string[strpos++];
  189. }
  190. changestr[changepos] = '\0';
  191. setarg(paramPos,0,_:floatstr(changestr));
  192. }
  193. case 'p':
  194. {
  195. delim = format[formatPos++];
  196. continue;
  197. }
  198. case '\'':
  199. {
  200. new
  201. end = formatPos - 1,
  202. ch;
  203. while ((ch = format[++end]) && ch != '\'') {}
  204. if (!ch)
  205. {
  206. return -1;
  207. }
  208. format[end] = '\0';
  209. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  210. {
  211. if (format[end + 1])
  212. {
  213. return -1;
  214. }
  215. return 0;
  216. }
  217. format[end] = '\'';
  218. stringPos = ch + (end - formatPos);
  219. formatPos = end + 1;
  220. }
  221. case 'u':
  222. {
  223. new
  224. end = stringPos - 1,
  225. id = 0,
  226. bool:num = true,
  227. ch;
  228. while ((ch = string[++end]) && ch != delim)
  229. {
  230. if (num)
  231. {
  232. if ('0' <= ch <= '9')
  233. {
  234. id = (id * 10) + (ch - '0');
  235. }
  236. else
  237. {
  238. num = false;
  239. }
  240. }
  241. }
  242. if (num && IsPlayerConnected(id))
  243. {
  244. setarg(paramPos, 0, id);
  245. }
  246. else
  247. {
  248. #if !defined foreach
  249. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  250. #define __SSCANF_FOREACH__
  251. #endif
  252. string[end] = '\0';
  253. num = false;
  254. new
  255. name[MAX_PLAYER_NAME];
  256. id = end - stringPos;
  257. for(new playerid = 0; playerid < MAX_PLAYERS; playerid++)
  258. {
  259. GetPlayerName(playerid, name, sizeof (name));
  260. if (!strcmp(name, string[stringPos], true, id))
  261. {
  262. setarg(paramPos, 0, playerid);
  263. num = true;
  264. break;
  265. }
  266. }
  267. if (!num)
  268. {
  269. setarg(paramPos, 0, INVALID_PLAYER_ID);
  270. }
  271. string[end] = ch;
  272. #if defined __SSCANF_FOREACH__
  273. #undef foreach
  274. #undef __SSCANF_FOREACH__
  275. #endif
  276. }
  277. stringPos = end;
  278. }
  279. case 's', 'z':
  280. {
  281. new
  282. i = 0,
  283. ch;
  284. if (format[formatPos])
  285. {
  286. while ((ch = string[stringPos++]) && ch != delim)
  287. {
  288. setarg(paramPos, i++, ch);
  289. }
  290. if (!i)
  291. {
  292. return -1;
  293. }
  294. }
  295. else
  296. {
  297. while ((ch = string[stringPos++]))
  298. {
  299. setarg(paramPos, i++, ch);
  300. }
  301. }
  302. stringPos--;
  303. setarg(paramPos, i, '\0');
  304. }
  305. default:
  306. {
  307. continue;
  308. }
  309. }
  310. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  311. {
  312. stringPos++;
  313. }
  314. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  315. {
  316. stringPos++;
  317. }
  318. paramPos++;
  319. }
  320. do
  321. {
  322. if ((delim = format[formatPos++]) > ' ')
  323. {
  324. if (delim == '\'')
  325. {
  326. while ((delim = format[formatPos++]) && delim != '\'') {}
  327. }
  328. else if (delim != 'z')
  329. {
  330. return delim;
  331. }
  332. }
  333. }
  334. while (delim > ' ');
  335. return 0;
  336. }
  337.  
  338. stock SpielerName(playerid)
  339. {
  340. new name[MAX_PLAYER_NAME];
  341. GetPlayerName(playerid,name,sizeof(name));
  342. return name;
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement