Advertisement
Guest User

Untitled

a guest
Apr 28th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. #define COLOR_RED (0xFF1A1AC8)
  5. #define COLOR_LILA (0xCC00CCC8)
  6.  
  7. #define DIALOG_RED "{FF1A1A}"
  8. #define DIALOG_LIGHTGREEN "{33F063}"
  9. #define DIALOG_LILA "{CC00CC}"
  10.  
  11. new PlayerName[MAX_PLAYER_NAME];
  12.  
  13. //------------------------------------------------------------------------------
  14.  
  15. public OnPlayerConnect(playerid)
  16. {
  17. GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);
  18. SetPVarInt(playerid, "lastpmid", -1);
  19. return 1;
  20. }
  21.  
  22. public OnPlayerDisconnect(playerid)
  23. {
  24. SetPVarInt(playerid, "lastpmid", -1);
  25. return 1;
  26. }
  27.  
  28. //------------------------------------------------------------------------------
  29.  
  30. CMD:pm(playerid, params[])
  31. {
  32. new id, msg[128], str[128];
  33.  
  34. if(sscanf(params, "ds", id, msg))
  35. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Benutze: /PM <ID> <Nachricht>");
  36.  
  37. if(!IsPlayerConnected(id))
  38. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Diese ID ist nicht verfügbar!");
  39.  
  40. if(GetPVarInt(id, "blockpm") == 1)
  41. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Dieser Spieler blockiert private Nachrichten!");
  42.  
  43. if(id == playerid)
  44. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Du kannst dir keine Nachrichten schreiben!");
  45.  
  46. SetPVarInt(id, "lastpmid", playerid);
  47. format(str, sizeof str, "-PM- %s(%d) schreibt: %s", PlayerName[playerid], playerid, msg);
  48. SendClientMessage(id, COLOR_LILA, str);
  49. SendClientMessage(id, COLOR_LILA, "-PM- "#DIALOG_LIGHTGREEN"Benutze /r <Nachricht>, "#DIALOG_LILA"um die private Nachricht sofort zu beantworten!");
  50. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  51. return 1;
  52. }
  53.  
  54. CMD:r(playerid, params[])
  55. {
  56. new msg[128], str[128];
  57. new id = GetPVarInt(playerid, "lastpmid");
  58.  
  59. if(GetPVarInt(playerid, "lastpmid") < 0)
  60. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Du kannst diesen Command erst benutzen, wenn du eine PM erhalten hast!");
  61.  
  62. if(sscanf(params, "s", msg))
  63. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Benutze: /r <Nachricht>");
  64.  
  65. if(GetPVarInt(id, "blockpm") == 1)
  66. return SendClientMessage(playerid, COLOR_RED, "-Warnung- Dieser Spieler blockiert private Nachrichten!");
  67.  
  68. format(str, sizeof str, "-PM- %s(%d) schreibt: %s", PlayerName[playerid], playerid, msg);
  69. SendClientMessage(id, COLOR_LILA, str);
  70. SendClientMessage(id, COLOR_LILA, "-PM- "#DIALOG_LIGHTGREEN"Benutze /r <Nachricht>, "#DIALOG_LILA"um die private Nachricht sofort zu beantworten!");
  71. PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  72. return 1;
  73. }
  74.  
  75. CMD:blockpm(playerid, params[])
  76. {
  77. if(GetPVarInt(playerid, "blockpm") == 0)
  78. {
  79. SetPVarInt(playerid, "blockpm", 1);
  80. SendClientMessage(playerid, COLOR_LILA, "-PM- "#DIALOG_RED"Du blockierst nun private Nachrichten!");
  81. }
  82. else
  83. {
  84. SetPVarInt(playerid, "blockpm", 0);
  85. SendClientMessage(playerid, COLOR_LILA, "-PM- "#DIALOG_LIGHTGREEN"Du kannst nun wieder private Nachrichten erhalten!");
  86. }
  87. return 1;
  88. }
  89.  
  90. //------------------------------------------------------------------------------
  91.  
  92. stock sscanf(string[], format[], {Float,_}:...)
  93. {
  94. #if defined isnull
  95. if (isnull(string))
  96. #else
  97. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  98. #endif
  99. {
  100. return format[0];
  101. }
  102. #pragma tabsize 4
  103. new
  104. formatPos = 0,
  105. stringPos = 0,
  106. paramPos = 2,
  107. paramCount = numargs(),
  108. delim = ' ';
  109. while (string[stringPos] && string[stringPos] <= ' ')
  110. {
  111. stringPos++;
  112. }
  113. while (paramPos < paramCount && string[stringPos])
  114. {
  115. switch (format[formatPos++])
  116. {
  117. case '\0':
  118. {
  119. return 0;
  120. }
  121. case 'i', 'd':
  122. {
  123. new
  124. neg = 1,
  125. num = 0,
  126. ch = string[stringPos];
  127. if (ch == '-')
  128. {
  129. neg = -1;
  130. ch = string[++stringPos];
  131. }
  132. do
  133. {
  134. stringPos++;
  135. if ('0' <= ch <= '9')
  136. {
  137. num = (num * 10) + (ch - '0');
  138. }
  139. else
  140. {
  141. return -1;
  142. }
  143. }
  144. while ((ch = string[stringPos]) > ' ' && ch != delim);
  145. setarg(paramPos, 0, num * neg);
  146. }
  147. case 'h', 'x':
  148. {
  149. new
  150. num = 0,
  151. ch = string[stringPos];
  152. do
  153. {
  154. stringPos++;
  155. switch (ch)
  156. {
  157. case 'x', 'X':
  158. {
  159. num = 0;
  160. continue;
  161. }
  162. case '0' .. '9':
  163. {
  164. num = (num << 4) | (ch - '0');
  165. }
  166. case 'a' .. 'f':
  167. {
  168. num = (num << 4) | (ch - ('a' - 10));
  169. }
  170. case 'A' .. 'F':
  171. {
  172. num = (num << 4) | (ch - ('A' - 10));
  173. }
  174. default:
  175. {
  176. return -1;
  177. }
  178. }
  179. }
  180. while ((ch = string[stringPos]) > ' ' && ch != delim);
  181. setarg(paramPos, 0, num);
  182. }
  183. case 'c':
  184. {
  185. setarg(paramPos, 0, string[stringPos++]);
  186. }
  187. case 'f':
  188. {
  189. setarg(paramPos, 0, _:floatstr(string[stringPos]));
  190. }
  191. case 'p':
  192. {
  193. delim = format[formatPos++];
  194. continue;
  195. }
  196. case '\'':
  197. {
  198. new
  199. end = formatPos - 1,
  200. ch;
  201. while ((ch = format[++end]) && ch != '\'') {}
  202. if (!ch)
  203. {
  204. return -1;
  205. }
  206. format[end] = '\0';
  207. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  208. {
  209. if (format[end + 1])
  210. {
  211. return -1;
  212. }
  213. return 0;
  214. }
  215. format[end] = '\'';
  216. stringPos = ch + (end - formatPos);
  217. formatPos = end + 1;
  218. }
  219. case 'u':
  220. {
  221. new
  222. end = stringPos - 1,
  223. id = 0,
  224. bool:num = true,
  225. ch;
  226. while ((ch = string[++end]) && ch != delim)
  227. {
  228. if (num)
  229. {
  230. if ('0' <= ch <= '9')
  231. {
  232. id = (id * 10) + (ch - '0');
  233. }
  234. else
  235. {
  236. num = false;
  237. }
  238. }
  239. }
  240. if (num && IsPlayerConnected(id))
  241. {
  242. setarg(paramPos, 0, id);
  243. }
  244. else
  245. {
  246. #if !defined foreach
  247. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  248. #define __SSCANF_FOREACH__
  249. #endif
  250. string[end] = '\0';
  251. num = false;
  252. new
  253. name[MAX_PLAYER_NAME];
  254. id = end - stringPos;
  255. foreach (Player, playerid)
  256. {
  257. GetPlayerName(playerid, name, sizeof (name));
  258. if (!strcmp(name, string[stringPos], true, id))
  259. {
  260. setarg(paramPos, 0, playerid);
  261. num = true;
  262. break;
  263. }
  264. }
  265. if (!num)
  266. {
  267. setarg(paramPos, 0, INVALID_PLAYER_ID);
  268. }
  269. string[end] = ch;
  270. #if defined __SSCANF_FOREACH__
  271. #undef foreach
  272. #undef __SSCANF_FOREACH__
  273. #endif
  274. }
  275. stringPos = end;
  276. }
  277. case 's', 'z':
  278. {
  279. new
  280. i = 0,
  281. ch;
  282. if (format[formatPos])
  283. {
  284. while ((ch = string[stringPos++]) && ch != delim)
  285. {
  286. setarg(paramPos, i++, ch);
  287. }
  288. if (!i)
  289. {
  290. return -1;
  291. }
  292. }
  293. else
  294. {
  295. while ((ch = string[stringPos++]))
  296. {
  297. setarg(paramPos, i++, ch);
  298. }
  299. }
  300. stringPos--;
  301. setarg(paramPos, i, '\0');
  302. }
  303. default:
  304. {
  305. continue;
  306. }
  307. }
  308. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  309. {
  310. stringPos++;
  311. }
  312. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  313. {
  314. stringPos++;
  315. }
  316. paramPos++;
  317. }
  318. do
  319. {
  320. if ((delim = format[formatPos++]) > ' ')
  321. {
  322. if (delim == '\'')
  323. {
  324. while ((delim = format[formatPos++]) && delim != '\'') {}
  325. }
  326. else if (delim != 'z')
  327. {
  328. return delim;
  329. }
  330. }
  331. }
  332. while (delim > ' ');
  333. return 0;
  334. }
  335.  
  336. //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement