Guest User

AFKSystem for SA:MP

a guest
May 13th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. //Simple AFK System by chl4ssiii
  2. #define FILTERSCRIPT
  3.  
  4. #include <a_samp>
  5. #include <ocmd>
  6.  
  7. //Farben
  8. #define COLOR_LIGHTBLUE 0x33CCFFAA
  9. #define COLOR_BLUE 0x0000BBAA
  10. #define COLOR_YELLOW 0xFFFF00AA
  11.  
  12. #if defined FILTERSCRIPT
  13.  
  14. public OnFilterScriptInit()
  15. {
  16. print("\n--------------------------------------");
  17. print(" AFK System by chl4ssiii loaded");
  18. print("--------------------------------------\n");
  19. return 1;
  20. }
  21.  
  22. public OnFilterScriptExit()
  23. {
  24. return 1;
  25. }
  26.  
  27. #else
  28.  
  29. main()
  30. {
  31. print("\n----------------------------------");
  32. print(" Blank Gamemode by your name here");
  33. print("----------------------------------\n");
  34. }
  35.  
  36. #endif
  37.  
  38. ocmd:afklist(playerid, params[])
  39. {
  40. SendClientMessage(playerid, COLOR_LIGHTBLUE,"AFK List");
  41. SendClientMessage(playerid, COLOR_LIGHTBLUE,"__________________________________________");
  42. new i = 0, aname[256], string[256];
  43. for(; i < MAX_PLAYERS; i++)
  44. {
  45. if(IsPlayerConnected(i))
  46. {
  47. if(GetPVarInt(i,"AFK")==1)
  48. {
  49. GetPlayerName(i, aname, sizeof(aname));
  50. format(string, 256, "- %s", aname);
  51. SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
  52. }
  53. SendClientMessage(playerid, COLOR_LIGHTBLUE,"__________________________________________");
  54. }
  55. }
  56. return 1;
  57. }
  58.  
  59. ocmd:afk(playerid, params[])
  60. {
  61. if(GetPVarInt(playerid,"AFK")==0)
  62. {
  63. new reason[128], string[128];
  64. if(sscanf(params,"s",reason)) return SendClientMessage(playerid,COLOR_YELLOW,"Benutzung:/afk [Grund]");
  65. format(string,sizeof(string),"Spieler: %s ist AFK gegangen, Grund: %s",SpielerName(playerid),reason);
  66. SendClientMessageToAll(COLOR_BLUE,string);
  67. TogglePlayerControllable(playerid,0);
  68. SetPlayerVirtualWorld(playerid, 2);
  69. SetPVarInt(playerid, "AFK", 1);
  70. }
  71. if(GetPVarInt(playerid,"AFK")==1)
  72. {
  73. SendClientMessage(playerid,COLOR_YELLOW,"Du bist bereits im AFK Modus, tippe /back.");
  74. }
  75. return 1;
  76. }
  77.  
  78. ocmd:back(playerid, params[])
  79. {
  80. if(GetPVarInt(playerid,"AFK")!=1)
  81. {
  82. SendClientMessage(playerid,COLOR_YELLOW,"Du bist nicht AFK!");
  83. }
  84. if(GetPVarInt(playerid,"AFK")==1)
  85. {
  86. new string[128],stringg[128];
  87. if(sscanf(params,"s"))
  88. format(string,sizeof(string),"Spieler: %s ist vom AFK-Modus zürck! ",SpielerName(playerid));
  89. format(stringg,sizeof(stringg),"Willkommen zurück %s",SpielerName(playerid));
  90. SendClientMessageToAll(COLOR_BLUE,string);
  91. GameTextForPlayer(playerid,stringg,5000,5);
  92. TogglePlayerControllable(playerid,1);
  93. SetPVarInt(playerid, "AFK", 0);
  94. SetPlayerVirtualWorld(playerid, 0);
  95. }
  96. return 1;
  97. }
  98.  
  99. //sscanf
  100. stock sscanf(string[], format[], {Float,_}:...)
  101. {
  102. #if defined isnull
  103. if (isnull(string))
  104. #else
  105. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  106. #endif
  107. {
  108. return format[0];
  109. }
  110. #pragma tabsize 4
  111. new
  112. formatPos = 0,
  113. stringPos = 0,
  114. paramPos = 2,
  115. paramCount = numargs(),
  116. delim = ' ';
  117. while (string[stringPos] && string[stringPos] <= ' ')
  118. {
  119. stringPos++;
  120. }
  121. while (paramPos < paramCount && string[stringPos])
  122. {
  123. switch (format[formatPos++])
  124. {
  125. case '\0':
  126. {
  127. return 0;
  128. }
  129. case 'i', 'd':
  130. {
  131. new
  132. neg = 1,
  133. num = 0,
  134. ch = string[stringPos];
  135. if (ch == '-')
  136. {
  137. neg = -1;
  138. ch = string[++stringPos];
  139. }
  140. do
  141. {
  142. stringPos++;
  143. if ('0' <= ch <= '9')
  144. {
  145. num = (num * 10) + (ch - '0');
  146. }
  147. else
  148. {
  149. return -1;
  150. }
  151. }
  152. while ((ch = string[stringPos]) > ' ' && ch != delim);
  153. setarg(paramPos, 0, num * neg);
  154. }
  155. case 'h', 'x':
  156. {
  157. new
  158. num = 0,
  159. ch = string[stringPos];
  160. do
  161. {
  162. stringPos++;
  163. switch (ch)
  164. {
  165. case 'x', 'X':
  166. {
  167. num = 0;
  168. continue;
  169. }
  170. case '0' .. '9':
  171. {
  172. num = (num << 4) | (ch - '0');
  173. }
  174. case 'a' .. 'f':
  175. {
  176. num = (num << 4) | (ch - ('a' - 10));
  177. }
  178. case 'A' .. 'F':
  179. {
  180. num = (num << 4) | (ch - ('A' - 10));
  181. }
  182. default:
  183. {
  184. return -1;
  185. }
  186. }
  187. }
  188. while ((ch = string[stringPos]) > ' ' && ch != delim);
  189. setarg(paramPos, 0, num);
  190. }
  191. case 'c':
  192. {
  193. setarg(paramPos, 0, string[stringPos++]);
  194. }
  195. case 'f':
  196. {
  197.  
  198. new changestr[16], changepos = 0, strpos = stringPos;
  199. while(changepos < 16 && string[strpos] && string[strpos] != delim)
  200. {
  201. changestr[changepos++] = string[strpos++];
  202. }
  203. changestr[changepos] = '\0';
  204. setarg(paramPos,0,_:floatstr(changestr));
  205. }
  206. case 'p':
  207. {
  208. delim = format[formatPos++];
  209. continue;
  210. }
  211. case '\'':
  212. {
  213. new
  214. end = formatPos - 1,
  215. ch;
  216. while ((ch = format[++end]) && ch != '\'') {}
  217. if (!ch)
  218. {
  219. return -1;
  220. }
  221. format[end] = '\0';
  222. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  223. {
  224. if (format[end + 1])
  225. {
  226. return -1;
  227. }
  228. return 0;
  229. }
  230. format[end] = '\'';
  231. stringPos = ch + (end - formatPos);
  232. formatPos = end + 1;
  233. }
  234. case 'u':
  235. {
  236. new
  237. end = stringPos - 1,
  238. id = 0,
  239. bool:num = true,
  240. ch;
  241. while ((ch = string[++end]) && ch != delim)
  242. {
  243. if (num)
  244. {
  245. if ('0' <= ch <= '9')
  246. {
  247. id = (id * 10) + (ch - '0');
  248. }
  249. else
  250. {
  251. num = false;
  252. }
  253. }
  254. }
  255. if (num && IsPlayerConnected(id))
  256. {
  257. setarg(paramPos, 0, id);
  258. }
  259. else
  260. {
  261. #if !defined foreach
  262. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  263. #define __SSCANF_FOREACH__
  264. #endif
  265. string[end] = '\0';
  266. num = false;
  267. new
  268. name[MAX_PLAYER_NAME];
  269. id = end - stringPos;
  270. foreach (Player, playerid)
  271. {
  272. GetPlayerName(playerid, name, sizeof (name));
  273. if (!strcmp(name, string[stringPos], true, id))
  274. {
  275. setarg(paramPos, 0, playerid);
  276. num = true;
  277. break;
  278. }
  279. }
  280. if (!num)
  281. {
  282. setarg(paramPos, 0, INVALID_PLAYER_ID);
  283. }
  284. string[end] = ch;
  285. #if defined __SSCANF_FOREACH__
  286. #undef foreach
  287. #undef __SSCANF_FOREACH__
  288. #endif
  289. }
  290. stringPos = end;
  291. }
  292. case 's', 'z':
  293. {
  294. new
  295. i = 0,
  296. ch;
  297. if (format[formatPos])
  298. {
  299. while ((ch = string[stringPos++]) && ch != delim)
  300. {
  301. setarg(paramPos, i++, ch);
  302. }
  303. if (!i)
  304. {
  305. return -1;
  306. }
  307. }
  308. else
  309. {
  310. while ((ch = string[stringPos++]))
  311. {
  312. setarg(paramPos, i++, ch);
  313. }
  314. }
  315. stringPos--;
  316. setarg(paramPos, i, '\0');
  317. }
  318. default:
  319. {
  320. continue;
  321. }
  322. }
  323. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  324. {
  325. stringPos++;
  326. }
  327. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  328. {
  329. stringPos++;
  330. }
  331. paramPos++;
  332. }
  333. do
  334. {
  335. if ((delim = format[formatPos++]) > ' ')
  336. {
  337. if (delim == '\'')
  338. {
  339. while ((delim = format[formatPos++]) && delim != '\'') {}
  340. }
  341. else if (delim != 'z')
  342. {
  343. return delim;
  344. }
  345. }
  346. }
  347. while (delim > ' ');
  348. return 0;
  349. }
  350. //Spielername
  351. stock SpielerName(playerid)
  352. {
  353. new name[MAX_PLAYER_NAME];
  354. GetPlayerName(playerid,name,sizeof(name));
  355. return name;
  356. }
Advertisement
Add Comment
Please, Sign In to add comment