Guest User

Untitled

a guest
Feb 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.99 KB | None | 0 0
  1. // ====================================================================================================
  2. // v THIS IS THE JUNK YOU'LL WANT TO EDIT v
  3. // Frendless leech starter setting (set to run with op gotv channel bot by default there will be no help on changing this)
  4. // ====================================================================================================
  5. var gamenames = ["Syko baal-"]; // Game name to search for (CASE-SENSITIVE)
  6.  
  7. var gamepasswords = ["Q"]; // Password for that game.
  8.  
  9. var maxRetriesPerGame = 6; // The # of times to try rejoining a *unique* game
  10. var maxRetries = 6; // The # of *different* games to try joining, if all attempts fail, bot will exit to character selection screen and rejoin lobby
  11.  
  12. // ====================================================================================================
  13.  
  14. var gameMinLength = 180000; // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
  15. var unableToConnectRetry = 1; // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  16. var realmDownRetry = 260; // time in minutes to retry connecting on a realm down (default is 120 minutes)
  17. var disconnectedRetry = 5; // time in minutes to retry on a disconnection (usually ip ban related)
  18. var cdkeyInUseRetry = 1; // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  19. var connectingToBnetTimeout = 20000; // time in milliseconds to wait for a login to time out and click cancel and retry
  20. var characterScreenTimeout = 5000; // time in milliseconds to wait for character screen to appear
  21. var pleaseWaitTimeout = 10000; // time in milliseconds to wait for a please wait popup
  22. var createGameThreshold = 10000; // time in milliseconds to wait between making games
  23. var createGameThresholdRandom = 5000; // time in milliseconds to randomly add +/- to the game create time
  24. var createGameTimeout = 15000; // time in milliseconds to register a failed to create game
  25. var waitInLineTimeout = 60000; // time in milliseconds to wait in lines for a create game (60 second default)
  26. var characterSelectDelay = 1000; // time in milliseconds to wait before selecting a character on the char screen
  27. var loginDelay = 1000; // time in milliseconds to wait before submitting login information
  28. var clickDelay = 500; // wait X milliseconds before next action after a click event
  29. var textDelay = 500; // wait X milliseconds before next action after inserting text into a textbox
  30. var clickDelayRandom = 500; // random amount of time to add to a click
  31. var textDelayRandom = 500; // random amount of time to add to a text set
  32. var gameDoesNotExistDelayMin = 1000; // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  33. var gameDoesNotExistDelayMax = 3000; // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  34. var gameDoesNotExistTimeout = 50; // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  35. var waitBeforeEnterChatMin = 1000; // min how long to wait before entering chat
  36. var waitBeforeEnterChatMax = 2000; // max how long to wait before entering chat
  37. var waitInChatBeforeActionsMin = 1000; // min how long to wait before joining channel
  38. var waitInChatBeforeActionsMax = 2000; // max how long to wait before joining channel
  39.  
  40. // DONT EDIT ANYTHING BELOW THIS
  41. var extrafilters = ["my games are priv, password is Q (all drops are yours) ng is ", ""]; // The 2nd filter should be whatever the bot manager says right after the game name
  42. // If the 2nd filter is empty, the rest of the line is used as the game name
  43. var joinChannelInChat = "clan ant"; // leave blank to not join a private channel
  44.  
  45. // D2NT Manager Command
  46. const D2NT_MGR_LOADING = 1;
  47. const D2NT_MGR_READY = 2;
  48. const D2NT_MGR_LOGIN = 3;
  49. const D2NT_MGR_CREATE_GAME = 4;
  50. const D2NT_MGR_INGAME = 5;
  51. const D2NT_MGR_RESTART = 6;
  52. const D2NT_MGR_CHICKEN = 7;
  53. const D2NT_MGR_PRINT_STATUS = 8;
  54. const D2NT_MGR_PRINT_LOG = 9;
  55.  
  56. var lastGameMade = GetTickCount();
  57. var nextGameMake = 0;
  58. var inGameAt = 0;
  59. var chatActionsDone = false;
  60. var lastGameStatus = 0; // 0 = OK, 1 = Processing, 2 = Ready for retry
  61. var game = "";
  62. var gamepassword = "";
  63. var retry = 0;
  64. var fullretry = maxRetries;
  65. var samegame = new Array(gamenames.length); // Empty array for however many runs you might be following (default 6)
  66.  
  67. Include("libs/controlInfo.ntl");
  68. Include("libs/common/NTColorConverter.ntl");
  69.  
  70. var controlData = new controlInfo();
  71.  
  72. function NTMain()
  73. {
  74. Delay(1000);
  75.  
  76. var _ingame = false;
  77.  
  78. controlData.clickDelay = clickDelay;
  79. controlData.textDelay = textDelay;
  80. controlData.clickDelayRandom = clickDelayRandom;
  81. controlData.textDelayRandom = textDelayRandom;
  82.  
  83. while (1)
  84. {
  85. if (me.ingame)
  86. {
  87. if (!inGameAt)
  88. inGameAt = GetTickCount();
  89.  
  90. if (!_ingame)
  91. {
  92. RunGC(); // run garbage collector between each game
  93.  
  94. if (Load("NTBot/NTBotGame.ntj"))
  95. {
  96. _ingame = true;
  97.  
  98. if (me.playtype > 0)
  99. sendEventToOOG(D2NT_MGR_INGAME, "In Game.. [IP:" + me.gameserverip.split(".")[3] + "]", 0);
  100. else
  101. sendEventToOOG(D2NT_MGR_INGAME, "In Game..", 0);
  102.  
  103. fullretry = maxRetries;
  104. lastGameStatus = 0;
  105. game = "";
  106. }
  107. }
  108.  
  109. Delay(1000);
  110. }
  111. else
  112. {
  113. Delay(500);
  114. if (_ingame)
  115. {
  116. _ingame = false;
  117.  
  118. // --------------------------
  119. // Prevent NT from closing D2
  120. // --------------------------
  121.  
  122. // Wait for lobby or lobby chat
  123. var _location;
  124. do
  125. {
  126. _location = controlData.getLocation();
  127. Delay(50);
  128. }
  129. while (_location.id != 3 && _location.id != 1);
  130.  
  131. if (_location.id == 3) // Lobby Chat
  132. {
  133. // We need to go somewhere besides the lobby chat so NT can type crap and think its creating a game
  134. Delay(100);
  135. Say("/join " + getRandomString(Random(3,10)));
  136. Delay(1000);
  137. }
  138. sendEventToOOG(D2NT_MGR_CREATE_GAME, _location.name, 0);
  139. outputGameLength();
  140. setNextGameMake();
  141. // --------------------------
  142.  
  143. sendEventToOOG(D2NT_MGR_READY, "", 0);
  144. }
  145.  
  146. locationAction(controlData.getLocation());
  147.  
  148. Delay(500);
  149. }
  150. }
  151. }
  152.  
  153. function locationAction(location)
  154. {
  155. switch (location.id)
  156. {
  157. case 3: // Lobby Chat
  158.  
  159. // Not retrying anymore, clear the game name so that if user tries to do it themself, bot won't fill in with old game
  160. if (lastGameStatus == 0 || retry == 0)
  161. {
  162. // Clear these flags just in case
  163. retry = 0;
  164. game = "";
  165. }
  166.  
  167. // Handle non-existent or full games:
  168. // When the join button is hit, lastGameStatus = 1.
  169. // When in-game, lastGameStatus = 0.
  170. // So this gets executed when NTMain() doesn't reset the flag to 0.
  171. if (lastGameStatus == 1)
  172. {
  173. if (fullretry == 0) // If we have tried [maxRetries] different games ([maxRetriesPerGame] retries for each game)
  174. {
  175. lastGameStatus = 0;
  176. fullretry = maxRetries;
  177.  
  178. // We need to close out of chat and come back
  179. sendEventToOOG(D2NT_MGR_PRINT_LOG, COLOR_1 + "Game doesn't exist or its full. Rejoining chat.", 0);
  180. controlData.click(controlData.controls.lobby.button.quit);
  181. }
  182. else
  183. {
  184. lastGameStatus = 2; // Ready for retry
  185.  
  186. if (retry == 0) // If we just failed [maxRetriesPerGame] times for joining this game
  187. fullretry--; // Update flag
  188.  
  189. sendEventToOOG(D2NT_MGR_PRINT_LOG, COLOR_1 + "Game doesn't exist or its full. " + retry + " retries left.", 0);
  190.  
  191. inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  192. setNextGameMake();
  193. chatActionsDone = true; // Undo the flag set by setNextGameMake()
  194.  
  195. locationTimeout(gameDoesNotExistTimeout, location);
  196. }
  197. break;
  198. }
  199.  
  200. if (!chatActionsDone || GetTickCount() > nextGameMake + 180000) // Need to join channel or its been 3 minutes and no action, possibly kicked from channel, rejoin
  201. {
  202. if (GetTickCount() > nextGameMake + 180000) // Reset this so that we don't keep joining channel over and over
  203. nextGameMake = GetTickCount();
  204.  
  205. chatActionsDone = true;
  206. Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  207.  
  208. Say("/join " + joinChannelInChat);
  209. Delay(1000);
  210. sendEventToOOG(D2NT_MGR_PRINT_LOG, "Looking for games..", 0);
  211. }
  212.  
  213. // Time for action?
  214. if (GetTickCount() >= nextGameMake)
  215. {
  216. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  217.  
  218. // If we can retry and there is a game to retry
  219. if (retry > 0 && game != "" && lastGameStatus == 2)
  220. {
  221. controlData.click(controlData.controls.lobby.button.join);
  222. retry--;
  223. break;
  224. }
  225.  
  226. var chat = controlData.get(controlData.controls.lobby.chat.textBox.channelText);
  227. if (chat)
  228. {
  229. var linewithname = "";
  230. lines = chat.GetText();
  231. if (lines)
  232. {
  233. for (var line = 0; line < lines.length; line++)
  234. {
  235. linewithname = lines[line];
  236.  
  237. for (var _filterindex = 0; _filterindex < extrafilters.length; _filterindex += 2)
  238. {
  239. // Check filters
  240. if (linewithname.lastIndexOf(extrafilters[_filterindex]) != -1 && linewithname.lastIndexOf(extrafilters[_filterindex+1]) != -1)
  241. {
  242. for (var _gameindex = 0; _gameindex < gamenames.length; _gameindex++)
  243. {
  244. // Check for game name
  245. var index = linewithname.lastIndexOf(gamenames[_gameindex]);
  246. if (index > -1)
  247. {
  248. game = linewithname.substring(index, linewithname.lastIndexOf(extrafilters[_filterindex+1]));
  249. gamepassword = gamepasswords[_gameindex];
  250.  
  251. if (game != "" && game != samegame[_gameindex])
  252. {
  253. sendEventToOOG(D2NT_MGR_PRINT_LOG, "Joining " + game + "..", 0);
  254. samegame[_gameindex] = game;
  255. controlData.click(controlData.controls.lobby.button.join);
  256. retry = maxRetriesPerGame;
  257. break;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. else
  268. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((nextGameMake-GetTickCount())/1000) + "s)", 0);
  269. break;
  270.  
  271. case 1: // Lobby
  272.  
  273. // Enter chat
  274. Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  275. controlData.click(controlData.controls.lobby.button.enterChat);
  276. break;
  277.  
  278. case 2: // Waiting In Line
  279. if (GetTickCount()-lastGameMade > waitInLineTimeout)
  280. controlData.click(controlData.controls.lobby.inLine.button.cancel);
  281. break;
  282.  
  283. case 4: // Create Game
  284. break;
  285.  
  286. case 5: // Join Game
  287. if (game != "")
  288. {
  289. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  290.  
  291. controlData.setText( controlData.controls.lobby.join.editBox.gameName, game);
  292. Delay (1250);
  293. controlData.setText( controlData.controls.lobby.join.editBox.password, gamepassword);
  294. Delay (1250);
  295. controlData.click(controlData.controls.lobby.join.button.joinGame);
  296. }
  297.  
  298. lastGameMade = GetTickCount();
  299. lastGameStatus = 1;
  300. break;
  301.  
  302. case 6: // Ladder
  303. break;
  304.  
  305. case 7: // Channel List
  306. break;
  307.  
  308. case 8: // Main Menu
  309. if (controlData.getCurrentRealmIndex() == me.gatewayid)
  310. {
  311. outputGameLength();
  312. controlData.click(controlData.gameTypes[me.playtype]);
  313. }
  314. else
  315. controlData.click(controlData.controls.mainMenu.button.gateway);
  316. break;
  317.  
  318. case 9: // Login
  319. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  320. Delay(loginDelay);
  321.  
  322. controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  323.  
  324. sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  325.  
  326. locationTimeout(5000, location);
  327. break;
  328.  
  329. case 10: // Login Error (this is a fatal error, so stop)
  330. sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  331. Delay(3500);
  332. break;
  333.  
  334. case 11: // Unable To Connect
  335. timeoutDelay(unableToConnectRetry*60*1000, location)
  336. controlData.click(controlData.controls.login.unableToConnect.button.ok);
  337. break;
  338.  
  339. case 12: // Character Select
  340. var _time, _control;
  341.  
  342. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  343.  
  344. for (_time = 0; _time < characterScreenTimeout; _time += 500)
  345. {
  346. _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  347. if (_control && _control.GetText() != undefined)
  348. break;
  349.  
  350. Delay(500);
  351. }
  352.  
  353. if (_time < characterScreenTimeout)
  354. {
  355. Delay(characterSelectDelay);
  356.  
  357. controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  358. controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  359.  
  360. // reset last game made, so it doesnt make a game immediately
  361. inGameAt = 0;
  362. setNextGameMake();
  363. }
  364. else
  365. {
  366. controlData.click(controlData.controls.characterSelect.button.exit);
  367. timeoutDelay(realmDownRetry*60*1000, location);
  368. }
  369. break;
  370.  
  371. case 13: // Realm Down - Character Select screen
  372. controlData.click(controlData.controls.characterSelect.button.exit);
  373. timeoutDelay(realmDownRetry*60*1000, location);
  374. break;
  375.  
  376. case 14: // Character Select - Disconnected
  377. timeoutDelay(disconnectedRetry*60*1000, location);
  378. controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  379. break;
  380.  
  381. case 15: // New Character
  382. break;
  383.  
  384. case 16: // Character Select - Please Wait popup
  385. if (!locationTimeout(pleaseWaitTimeout, location))
  386. controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  387. break;
  388.  
  389. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  390. controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  391. break;
  392.  
  393. case 18: // D2 Splash
  394. controlData.click(controlData.controls.d2Splash.textBox.copyright);
  395. break;
  396.  
  397. case 19: // Login - Cdkey In Use
  398. timeoutDelay(cdkeyInUseRetry*60*1000, location);
  399. controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  400. break;
  401.  
  402. case 20: // Single Player - Select Difficulty
  403. controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  404. break;
  405.  
  406. case 21: // Main Menu - Connecting
  407. if (!locationTimeout(connectingToBnetTimeout, location))
  408. controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  409. break;
  410.  
  411. case 22: // Login - Invalid Cdkey (classic or xpac)
  412. sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  413. Delay(3500);
  414. break;
  415.  
  416. case 23: // Character Select - Connecting
  417. if (!locationTimeout(characterScreenTimeout, location))
  418. controlData.click(controlData.controls.characterSelect.button.exit);
  419. break;
  420.  
  421. case 24: // Server Down - not much to do but wait..
  422. break;
  423.  
  424. case 25: // Lobby - Please Wait
  425. if (!locationTimeout(pleaseWaitTimeout, location))
  426. controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  427. break;
  428.  
  429. case 26: // Lobby - Game Name Exists
  430. sendEventToOOG(D2NT_MGR_PRINT_LOG, COLOR_1 + "Game already exists.", 0);
  431.  
  432. inGameAt = 0;
  433. setNextGameMake();
  434.  
  435. locationTimeout(15000, location);
  436. break;
  437.  
  438. case 27: // Gateway Select
  439. controlData.clickRealmEntry(me.gatewayid);
  440. controlData.click(controlData.controls.gateway.button.ok);
  441. break;
  442.  
  443. case 28: // Lobby - Game Does Not Exist
  444. // This is handled in the lobby chat
  445.  
  446. // Get rid of the message (DNE/Full game) so the lobby chat can handle
  447. controlData.click(controlData.controls.lobby.button.create);
  448. Delay(200);
  449. controlData.click(controlData.controls.lobby.create.button.cancel);
  450. break;
  451.  
  452. default:
  453. break;
  454. }
  455. }
  456.  
  457. function sendEventToOOG(locationId, statusString, pendingTime)
  458. {
  459. return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  460. }
  461.  
  462. function setNextGameMake()
  463. {
  464. lastGameMade = GetTickCount();
  465. nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  466. inGameAt = 0;
  467. chatActionsDone = false;
  468. }
  469.  
  470. function outputGameLength()
  471. {
  472. if (inGameAt)
  473. {
  474. duration = GetTickCount() - inGameAt;
  475.  
  476. inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  477. }
  478. }
  479.  
  480. function locationTimeout(time, location)
  481. {
  482. endtime = GetTickCount() + time;
  483.  
  484. while (controlData.getLocation().id == location.id && endtime > GetTickCount())
  485. {
  486. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  487. Delay(500);
  488. }
  489.  
  490. return (controlData.getLocation().id != location.id);
  491. }
  492.  
  493. function timeoutDelay(time, location)
  494. {
  495. endtime = GetTickCount() + time;
  496.  
  497. while (endtime > GetTickCount())
  498. {
  499. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  500. Delay(1000);
  501. }
  502. }
  503.  
  504. function getRandomString(_length)
  505. {
  506. _retString = "";
  507. _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  508.  
  509. while (_length--)
  510. {
  511. _retString += _charSet.charAt(Random(0, _charSet.length-1));
  512. Delay(1);
  513. }
  514.  
  515. return _retString;
  516. }
Add Comment
Please, Sign In to add comment