Advertisement
Guest User

Untitled

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