Advertisement
Badyx

Untitled

Jan 24th, 2019
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.66 KB | None | 0 0
  1. #include a_samp
  2. #include zcmd
  3. #include ../include/dialogs
  4. #include ../include/foreach
  5. #include ../include/pawnraknet
  6.  
  7. native PB_RegisterBot(name[]);
  8.  
  9. #define MAX_NAME (4096)
  10. #define MAX_ADMIN (32)
  11. #define MAX_LVL (128)
  12. #define MAX_PING (128)
  13. #define MAX_COLOR (128)
  14.  
  15. new Iterator:fNickC<MAX_NAME>;
  16.  
  17. new gSlotCount;
  18. new gRealCount;
  19. new gFakeCount;
  20. new gNickCount;
  21. new gPingCount;
  22. new gScoreCount;
  23. new gColorCount;
  24. new gAdminCount;
  25. new gTickCheckSl;
  26. new gTimerDelay;
  27. new gTimerDCount;
  28. new gTimerDLRand;
  29. new gTimerMaxTick;
  30. new gTimerLastTick;
  31.  
  32. new gSetting;
  33. new gAtHour[24];
  34. new gLvl[MAX_LVL];
  35. new gPing[MAX_PING];
  36. new gColor[MAX_COLOR];
  37. new gNick[MAX_NAME][25];
  38. new gAdmin[MAX_ADMIN][25];
  39. new gNickC[MAX_NAME char];
  40. new gNickCplId[MAX_NAME] = {-1, ...};
  41.  
  42. new playerLvl[MAX_PLAYERS];
  43. new playerPing[MAX_PLAYERS];
  44. new playerColor[MAX_PLAYERS];
  45. new playerPBot[MAX_PLAYERS];
  46. new playerNick[MAX_PLAYERS][25];
  47. new playerSetList[MAX_PLAYERS char];
  48. new playerRakNetScore[MAX_PLAYERS];
  49. new playerRakNetPing[MAX_PLAYERS];
  50.  
  51. stock GetTickDiff(newtick, oldtick)
  52. {
  53. if(oldtick >= 0 && newtick < 0 || oldtick > newtick) return ((cellmax - oldtick + 1) - (cellmin - newtick));
  54. return (newtick - oldtick);
  55. }
  56.  
  57. stock CompareText(string1[], string2[])
  58. {
  59. new id = strcmp(string1, string2);
  60. if(id != 0) return id;
  61. if(string1[0] && string2[0]) return 0;
  62. return 255;
  63. }
  64.  
  65. stock HexToInt(string[])
  66. {
  67. new curent = 1, result = 0;
  68. for(new i = (strlen(string) - 1); i >= 0; i--)
  69. {
  70. if(string[i] < 58) result = (result + curent * (string[i] - 48));
  71. else result = (result + curent * (string[i] - 65 + 10));
  72. curent = curent*16;
  73. }
  74. return result;
  75. }
  76.  
  77. stock ShowSetting0(playerid)
  78. {
  79. new string0[60] = "{FFFFFF}", string1[50] = "{FFFFFF}Menъ de configuraciуn bot: ";
  80. strcat(string1, (gSetting) ? ("{00CC00}Запущен") : ("{FF6600}Instalacion"));
  81. strcat(string0, (gSetting) ? ("Instalar") : ("Crear"));
  82. strcat(string0, "\nExplicar\nHorario\nESTADO");
  83. ShowPlayerDialog(playerid, 4460, DIALOG_STYLE_LIST, string1, string0, "Mostrar", "Cerrar");
  84. return 1;
  85. }
  86.  
  87. stock ShowSetting1(playerid)
  88. {
  89. new string[320] = "{FFFFFF}";
  90. for(new i; i < 24; i++) format(string, sizeof(string), "%s%i:00 - %i\n", string, i, gAtHour[i]);
  91. ShowPlayerDialog(playerid, 4461, DIALOG_STYLE_LIST, "{FFFFFF}Horario", string, "Mostrar", "Atrбs");
  92. return 1;
  93. }
  94.  
  95. stock LoadSetting()
  96. {
  97. new File:id, count, string[25];
  98. id = fopen("pawnbots/setting.ini", io_read);
  99. if(!id)
  100. {
  101. print("[PB] file 'setting.ini' error");
  102. return 0;
  103. }
  104. fread(id, string, sizeof(string));
  105. gSetting = strval(string);
  106. fclose(id);
  107.  
  108. id = fopen("pawnbots/online.ini", io_read);
  109. if(!id)
  110. {
  111. print("[PB] file 'online.ini' error");
  112. return 0;
  113. }
  114. count = 0;
  115. while(fread(id, string, sizeof(string)))
  116. {
  117. if(++count > 24) break;
  118. gAtHour[count - 1] = (strval(string) > (gSlotCount - 1)) ? (gSlotCount - 1) : strval(string);
  119. }
  120. fclose(id);
  121.  
  122. id = fopen("pawnbots/score.ini", io_read);
  123. if(!id)
  124. {
  125. print("[PB] file 'score.ini' error");
  126. return 0;
  127. }
  128. count = 0;
  129. while(fread(id, string, sizeof(string)))
  130. {
  131. if(++count > MAX_LVL) break;
  132. gLvl[count - 1] = strval(string);
  133. }
  134. gScoreCount = count;
  135. fclose(id);
  136.  
  137. id = fopen("pawnbots/ping.ini", io_read);
  138. count = 0;
  139. if(!id)
  140. {
  141. print("[PB] file 'ping.ini' error");
  142. return 0;
  143. }
  144. while(fread(id, string, sizeof(string)))
  145. {
  146. if(++count > MAX_PING) break;
  147. gPing[count - 1] = strval(string);
  148. }
  149. gPingCount = count;
  150. fclose(id);
  151.  
  152. id = fopen("pawnbots/color.ini", io_read);
  153. if(!id)
  154. {
  155. print("[PB] file 'color.ini' error");
  156. return 0;
  157. }
  158. count = 0;
  159. while(fread(id, string, sizeof(string)))
  160. {
  161. if(++count > MAX_COLOR) break;
  162. for(new i = (strlen(string) - 1); i >= 0; i--) switch(string[i])
  163. {
  164. case 'A'..'Z', 'a'..'z', '0'..'9': {}
  165. default: strdel(string, i, (i + 1));
  166. }
  167. gColor[count - 1] = HexToInt(string[2]);
  168. }
  169. gColorCount = count;
  170. fclose(id);
  171.  
  172. id = fopen("pawnbots/nick.ini", io_read);
  173. if(!id)
  174. {
  175. print("[PB] file 'nick.ini' error");
  176. return 0;
  177. }
  178. count = 0;
  179. while(fread(id, string, sizeof(string)))
  180. {
  181. if(++count > MAX_NAME) break;
  182. for(new i = (strlen(string) - 1); i >= 0; i--) switch(string[i])
  183. {
  184. case 'A'..'Z', 'a'..'z', '0'..'9', '_': {}
  185. default: strdel(string, i, (i + 1));
  186. }
  187. strmid(gNick[count - 1], string, 0, strlen(string), 25);
  188. }
  189. gNickCount = count;
  190. fclose(id);
  191.  
  192. id = fopen("pawnbots/admin.ini", io_read);
  193. if(!id)
  194. {
  195. print("[PB] file 'admin.ini' error");
  196. return 0;
  197. }
  198. count = 0;
  199. while(fread(id, string, sizeof(string)))
  200. {
  201. if(++count > MAX_ADMIN) break;
  202. for(new i = (strlen(string) - 1); i >= 0; i--) switch(string[i])
  203. {
  204. case 'A'..'Z', 'a'..'z', '0'..'9', '_': {}
  205. default: strdel(string, i, (i + 1));
  206. }
  207. strmid(gAdmin[count - 1], string, 0, strlen(string), 25);
  208. }
  209. gAdminCount = count;
  210. fclose(id);
  211. return 1;
  212. }
  213.  
  214. public OnPlayerText(playerid, text[])
  215. {
  216. if(!CompareText(text, ".menubot")) { switch(GetPlayerState(playerid))
  217. {
  218. case PLAYER_STATE_NONE, PLAYER_STATE_WASTED, PLAYER_STATE_SPECTATING: {}
  219. default: { for(new i = (gAdminCount - 1); i >= 0; i--) if(!CompareText(playerNick[playerid], gAdmin[i]))
  220. {
  221. ShowSetting0(playerid);
  222. return 0;
  223. }}
  224. }}
  225. return 1;
  226. }
  227.  
  228. CMD:badyxtest1(playerid, params[])
  229. {
  230. ShowSetting0(playerid);
  231. return 1;
  232. }
  233.  
  234. DLG(4463, playerid, response, listitem, inputtext[])
  235. {
  236. ShowSetting0(playerid);
  237. return 1;
  238. }
  239. DLG(4460, playerid, response, listitem, inputtext[])
  240. {
  241. if(!response) return 1;
  242. switch(listitem)
  243. {
  244. case 0:
  245. {
  246. gSetting = !gSetting;
  247. new File:id = fopen("pawnbots/setting.ini", io_write);
  248. if(!id)
  249. {
  250. print("[PB] file 'setting.ini' error");
  251. return 1;
  252. }
  253. new string[4];
  254. valstr(string, gSetting);
  255. fwrite(id, string);
  256. fclose(id);
  257. ShowSetting0(playerid);
  258. }
  259. case 1:
  260. {
  261. gSetting = 0;
  262. for(new i = (gSlotCount - 1); i >= 0; i--) { if(playerPBot[i] != -1) Kick(i); }
  263. LoadSetting();
  264. gSetting = 1;
  265. ShowSetting0(playerid);
  266. }
  267. case 2: ShowSetting1(playerid);
  268. case 3:
  269. {
  270. new string[136];
  271. format(string, sizeof(string), "{FFFFFF}Finalizaciуn del volumen de sobretensiones: %iмс.\nМаксимальное время выполнения: %iмс.\nНастоящих игроков: %i\nФейковых игроков: %i", gTimerLastTick, gTimerMaxTick, gRealCount, gFakeCount);
  272. ShowPlayerDialog(playerid, 4463, DIALOG_STYLE_MSGBOX, "{FFFFFF}Статистика", string, "Volver", "");
  273. }
  274. }
  275. return 1;
  276. }
  277. DLG(4461, playerid, response, listitem, inputtext[])
  278. {
  279. if(!response || listitem < 0 || listitem > 24)
  280. {
  281. ShowSetting0(playerid);
  282. return 1;
  283. }
  284. playerSetList{playerid} = listitem;
  285. new string[14] = "{FFFFFF}";
  286. valstr(string, listitem);
  287. strcat(string, ":00");
  288. ShowPlayerDialog(playerid, 4462, DIALOG_STYLE_INPUT, string, "{FFFFFF}", "Mostrar", "Volver");
  289. return 1;
  290. }
  291.  
  292. DLG(4462, playerid, response, listitem, inputtext[])
  293. {
  294. if(!response)
  295. {
  296. ShowSetting1(playerid);
  297. return 1;
  298. }
  299. new list = playerSetList{playerid}, vall = strval(inputtext);
  300. if(!strlen(inputtext) || vall < 0 || vall > (gSlotCount - 1))
  301. {
  302. new string[14] = "{FFFFFF}";
  303. valstr(string, list);
  304. strcat(string, ":00");
  305. ShowPlayerDialog(playerid, 4462, DIALOG_STYLE_INPUT, string, "{FFFFFF}", "Mostrar", "Volver");
  306. return 1;
  307. }
  308. for(new i = (strlen(inputtext) - 1); i >= 0; i--) if(inputtext[i] < '0' || inputtext[i] > '9')
  309. {
  310. new string[14] = "{FFFFFF}";
  311. valstr(string, list);
  312. strcat(string, ":00");
  313. ShowPlayerDialog(playerid, 4462, DIALOG_STYLE_INPUT, string, "{FFFFFF}", "Mostrar", "Volver");
  314. return 1;
  315. }
  316. gAtHour[list] = vall;
  317. ShowSetting1(playerid);
  318. new File:id = fopen("pawnbots/online.ini", io_write);
  319. if(!id)
  320. {
  321. print("[PB] file 'online.ini' error");
  322. return 1;
  323. }
  324. new string[122];
  325. for(new i; i < 24; i++) format(string, sizeof(string), "%s%i\n", string, gAtHour[i]);
  326. fwrite(id, string);
  327. fclose(id);
  328. return 1;
  329. }
  330.  
  331. public OnPlayerConnect(playerid)
  332. {
  333. playerPBot[playerid] = -1;
  334. GetPlayerName(playerid, playerNick[playerid], 25);
  335.  
  336. new id = -1;
  337. foreach(fNickC, slot) if(!CompareText(playerNick[playerid], gNick[slot])) { id = slot; break; }
  338. if(id != -1)
  339. {
  340. gNickCplId[id] = playerid;
  341. playerPBot[playerid] = id;
  342. playerLvl[playerid] = gLvl[random(gScoreCount)];
  343. playerPing[playerid] = gPing[random(gPingCount)];
  344. //playerColor[playerid] = gColor[random(gColorCount)];
  345. }
  346. else gRealCount++;
  347. return 1;
  348. }
  349.  
  350. public OnPlayerDisconnect(playerid, reason)
  351. {
  352. new id = playerPBot[playerid];
  353. if(id != -1)
  354. {
  355. gFakeCount--;
  356. gNickC{id} = 0;
  357. gNickCplId[id] = -1;
  358. Iter_Remove(fNickC, id);
  359. }
  360. else gRealCount--;
  361. return 1;
  362. }
  363.  
  364. public OnFilterScriptInit()
  365. {
  366. gSlotCount = GetMaxPlayers();
  367. Iter_Clear(fNickC);
  368. if(LoadSetting()) SetTimer("OnPBotUpdate", 2000, 1);
  369. return 1;
  370. }
  371.  
  372. public OnFilterScriptExit()
  373. {
  374. for(new i = (gSlotCount - 1); i >= 0; i--) { if(playerPBot[i] != -1) Kick(i); }
  375. return 1;
  376. }
  377.  
  378. forward IsPlayerPBot(playerid);
  379. public IsPlayerPBot(playerid) return (playerPBot[playerid] != -1);
  380.  
  381. forward OnPBotCheckNick(s, nick[]);
  382. public OnPBotCheckNick(s, nick[])
  383. {
  384. if(!IsPlayerConnected(gNickCplId[s]) || CompareText(playerNick[gNickCplId[s]], gNick[s])) { if(Iter_Contains(fNickC, s))
  385. {
  386. gFakeCount--;
  387. gNickC{s} = 0;
  388. gNickCplId[s] = -1;
  389. Iter_Remove(fNickC, s);
  390. printf("[PB] El nick '%s' estб ocupado", gNick[s]);
  391. }}
  392. return 1;
  393. }
  394.  
  395. forward OnPBotUpdate();
  396. public OnPBotUpdate()
  397. {
  398. new tick = GetTickCount();
  399. if(++gTickCheckSl >= 5)
  400. {
  401. gTickCheckSl = 0;
  402. foreach(fNickC, slot) { if(!IsPlayerConnected(gNickCplId[slot])) SetTimerEx("OnPBotCheckNick", 15000, 0, "is", slot, gNick[slot]); }
  403. }
  404. new string[136];
  405. foreach(Player, playerid)
  406. {
  407. if(playerPBot[playerid] != -1)
  408. {
  409. SetPlayerScore(playerid, playerLvl[playerid]);
  410. SetPlayerColor(playerid, playerColor[playerid]);
  411. continue;
  412. }
  413. if(IsDialogOpen(playerid, 4463))
  414. {
  415. format(string, sizeof(string), "{FFFFFF}Последние время выполнения: %iмс.\nМаксимальное время выполнения: %iмс.\nConfiguraciуn de permisos %i\nФейковых игроков: %i", gTimerLastTick, gTimerMaxTick, gRealCount, gFakeCount);
  416. ShowPlayerDialog(playerid, 4463, DIALOG_STYLE_MSGBOX, "{FFFFFF}Estado", string, "Volver", "");
  417. }
  418. }
  419. if(gTimerDelay) gTimerDelay--;
  420. else { if(gSetting)
  421. {
  422. new hour, count, id = -1, botcount = Iter_Count(fNickC);
  423. gettime(hour);
  424. if(gAtHour[hour] < botcount && botcount)
  425. {
  426. while(!gNickC{(id = random(gNickCount))}) if(++count >= 20)
  427. {
  428. for(new i = (gNickCount - 1); i >= 0; i--) if(gNickC{i}) { id = i; break; }
  429. break;
  430. }
  431. if(id != -1) { for(new i = (gSlotCount - 1); i >= 0; i--) if(playerPBot[id] != -1) { if(!CompareText(gNick[id], playerNick[i])) Kick(i); }}
  432. }
  433. if(gAtHour[hour] > botcount && botcount < gNickCount && (gFakeCount + gRealCount) < (gSlotCount - 1))
  434. {
  435. while(gNickC{(id = random(gNickCount))}) if(++count >= 20)
  436. {
  437. for(new i = (gNickCount - 1); i >= 0; i--) if(!gNickC{i}) { id = i; break; }
  438. break;
  439. }
  440. if(id != -1)
  441. {
  442. gFakeCount++;
  443. gNickC{id} = 1;
  444. Iter_Add(fNickC, id);
  445. PB_RegisterBot(gNick[id]);
  446. ConnectNPC(gNick[id], "pawnbots");
  447. }
  448. }
  449. if(++gTimerDCount >= gTimerDLRand)
  450. {
  451. gTimerDelay = (5 + random(6));
  452. gTimerDLRand = (2 + random(3));
  453. gTimerDCount = 0;
  454. }
  455. }}
  456. new diff = GetTickDiff(GetTickCount(), tick);
  457. gTimerLastTick = diff;
  458. if(diff > gTimerMaxTick) gTimerMaxTick = diff;
  459. return 1;
  460. }
  461.  
  462. ORPC:155(playerid, BitStream:bs)
  463. {
  464. new bytes;
  465. BS_GetNumberOfBytesUsed(bs, bytes);
  466. for(new i = (bytes / 10) - 1; i >= 0; i--)
  467. {
  468. new otherid, score, ping;
  469. BS_ReadValue(bs, PR_UINT16, otherid, PR_INT32, score, PR_UINT32, ping);
  470. if(!IsPlayerConnected(otherid)) continue;
  471. playerRakNetScore[otherid] = score;
  472. playerRakNetPing[otherid] = ping;
  473. }
  474. new BitStream:stream = BS_New();
  475. foreach(Player, otherid)
  476. {
  477. if(playerPBot[otherid] == -1) BS_WriteValue(stream, PR_UINT16, otherid, PR_INT32, playerRakNetScore[otherid], PR_UINT32, playerRakNetPing[otherid]);
  478. else BS_WriteValue(stream, PR_UINT16, otherid, PR_INT32, playerLvl[otherid], PR_UINT32, (playerPing[otherid] + random(10)));
  479. }
  480. BS_RPC(stream, playerid, 155, PR_LOW_PRIORITY, PR_RELIABLE_ORDERED);
  481. BS_Delete(stream);
  482. return 0;
  483. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement