Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.22 KB | None | 0 0
  1. //credit for this goes to D2od who knows way more than I do
  2.  
  3. // =============================================================================
  4. // Leader Account settings
  5. // =============================================================================
  6. var leaderAccountName = "altruinomics4";
  7. var leaderName = "Alpy";
  8.  
  9. // =============================================================================
  10. // Game password (leave blank if none)
  11. // =============================================================================
  12. var gamepassword = "";
  13.  
  14. // =============================================================================
  15. // UseCDKeyChangeTrick :
  16. // if true, the follow bot will say his gamename/gamepwd (set in the OOG) in chat before each game
  17. // in order to increment his number of runs (to switch CDKeys after xx runs)
  18. // if false, the follow bot will never change his CDKey
  19. // =============================================================================
  20. var UseCDKeyChangeTrick = false;
  21.  
  22. // =============================================================================
  23. // Debug : set to true if you are experiencing problems with your JoinBot
  24. // it will log in your OOG the lobby chat actions
  25. // =============================================================================
  26. var Debug = false;
  27.  
  28. ////////////////////////////////////////////////////////////////////////////////
  29. // Lobby chat settings :
  30. ////////////////////////////////////////////////////////////////////////////////
  31.  
  32. // Set to true to join the chat after each game (needed for JoinBot)
  33. var joinChatAfterGame = true;
  34.  
  35. // Message said when you first enter the chat
  36. var firstJoinMessage = "";
  37.  
  38. // Message said after each game
  39. var chatMessageAfterGame = "";
  40.  
  41. // if this is true, will join a random channel, otherwise it will use the channel below..
  42. var joinRandomChannel = false;
  43. // Name of the channel you want to join (leave blank if you want to stay in the default channel)
  44. var joinChannelInChat = "op lljk";
  45.  
  46.  
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // Delays:
  49. ////////////////////////////////////////////////////////////////////////////////
  50.  
  51. // Minimum game length, waits in the lobby if last game was too short
  52. // I recommend to keep a value > 300000 (milliseconds) to avoid bnet temporary ban
  53. var gameMinLength = 420000;
  54.  
  55. // realm delays (minutes)
  56. var unableToConnectRetry = 5;
  57. var realmDownRetry = 120;
  58. var disconnectedRetry = 5;
  59. var cdkeyInUseRetry = 5;
  60.  
  61. // interface delays (milliseconds)
  62. var connectingToBnetTimeout = 20000;
  63. var characterScreenTimeout = 10000;
  64. var pleaseWaitTimeout = 10000;
  65. var createGameThreshold = 10000;
  66. var createGameThresholdRandom = 1000;
  67. var createGameTimeout = 15000;
  68. var waitInLineTimeout = 15000;
  69. var characterSelectDelay = 1000;
  70. var loginDelay = 1000;
  71. var clickDelay = 500;
  72. var textDelay = 500;
  73. var clickDelayRandom = 500;
  74. var textDelayRandom = 500;
  75. var gameDoesNotExistDelayMin = 600000;
  76. var gameDoesNotExistDelayMax = 900000;
  77. var gameDoesNotExistTimeout = 30000;
  78. var waitBeforeEnterChatMin = 1000;
  79. var waitBeforeEnterChatMax = 2000;
  80. var waitInChatBeforeActionsMin = 2000;
  81. var waitInChatBeforeActionsMax = 3000;
  82.  
  83. // Only for JoinBot (friend list delay, milliseconds)
  84. var LeaderOfflineDelay = 30000;
  85. var LeaderInChatDelay = 10000;
  86. var GameIsFullDelay = 30000;
  87.  
  88. ////////////////////////////////////////////////////////////////////////////////
  89. ////////////////////////////////////////////////////////////////////////////////
  90. // DO NOT EDIT ANYTHING BELOW THIS
  91. ////////////////////////////////////////////////////////////////////////////////
  92. ////////////////////////////////////////////////////////////////////////////////
  93.  
  94. //D2NT Manager Command
  95.  
  96. const D2NT_MGR_LOADING = 1;
  97. const D2NT_MGR_READY = 2;
  98. const D2NT_MGR_LOGIN = 3;
  99. const D2NT_MGR_CREATE_GAME = 4;
  100. const D2NT_MGR_INGAME = 5;
  101. const D2NT_MGR_RESTART = 6;
  102. const D2NT_MGR_CHICKEN = 7;
  103. const D2NT_MGR_PRINT_STATUS = 8;
  104. const D2NT_MGR_PRINT_LOG = 9;
  105.  
  106. var lastGameMade = GetTickCount();
  107. var lastGameStatus = 0;
  108. var nextGameMake = 0;
  109. var inGameAt = 0;
  110. var chatActionsDone = false;
  111. var lastGameFailed = false;
  112. var sayChatMsgAfterGame = false;
  113.  
  114. Include("libs/controlInfo.ntl");
  115. Include("libs/common/NTColorConverter.ntl");
  116.  
  117. var controlData = new controlInfo();
  118.  
  119. var game = '';
  120. var _gamename = "";
  121. var _gamepassword = "";
  122. var _leaderOfflineTick = -LeaderOfflineDelay;
  123. var _leaderInChatTick = -LeaderInChatDelay;
  124. var _GameIsFullTick = -GameIsFullDelay;
  125.  
  126. function NTMain()
  127. {
  128. Delay(1000);
  129.  
  130. var _ingame = false;
  131.  
  132. controlData.clickDelay = clickDelay;
  133. controlData.textDelay = textDelay;
  134. controlData.clickDelayRandom = clickDelayRandom;
  135. controlData.textDelayRandom = textDelayRandom;
  136.  
  137. while(1)
  138. {
  139. if(me.ingame)
  140. {
  141. _gamename = me.gamename;
  142. _gamepassword = me.gamepassword;
  143.  
  144. if(!inGameAt)
  145. inGameAt = GetTickCount();
  146.  
  147. if(!_ingame)
  148. {
  149. RunGC(); // run garbage collector between each game
  150.  
  151. if(Load("NTBot/NTBotGame.ntj"))
  152. {
  153. _ingame = true;
  154.  
  155. if(me.playtype > 0)
  156. sendEventToOOG(D2NT_MGR_INGAME, "In Game[IP:" + me.gameserverip.split(".")[3] + "]", 0);
  157. else
  158. sendEventToOOG(D2NT_MGR_INGAME, "In Game", 0);
  159.  
  160. lastGameStatus = 2; // in game successful
  161.  
  162. // To exit game as soon as the leader quits
  163. //Load("NTBot/NTCheckLeader.ntj");
  164. // to party only the leader
  165. //Load("NTBot/tools/NTTools_AutoPartyJoinFriendGames.ntj");
  166. }
  167. }
  168.  
  169. Delay(1000);
  170. }
  171. else
  172. {
  173. if(_ingame)
  174. {
  175. _ingame = false;
  176. sayChatMsgAfterGame = true;
  177.  
  178. sendEventToOOG(D2NT_MGR_READY, "", 0);
  179. }
  180.  
  181. locationAction(controlData.getLocation());
  182.  
  183. Delay(500);
  184. }
  185. }
  186. }
  187.  
  188. function locationAction(location)
  189. {
  190. switch(location.id)
  191. {
  192. case 3: // Lobby Chat
  193. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  194.  
  195. if(!chatActionsDone)
  196. {
  197. Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  198.  
  199. if(joinRandomChannel || joinChannelInChat != "")
  200. {
  201. Say("/join " + (joinRandomChannel ? getRandomString(Random(3,10)) : joinChannelInChat));
  202. Delay(1000);
  203. }
  204.  
  205. if(firstJoinMessage)
  206. {
  207. Say(firstJoinMessage);
  208. Delay(200);
  209. }
  210.  
  211. chatActionsDone = true;
  212. }
  213.  
  214. if (chatMessageAfterGame && _gamename != "" && sayChatMsgAfterGame == true)
  215. {
  216. Say(chatMessageAfterGame);
  217. sayChatMsgAfterGame = false;
  218. Delay(200);
  219. }
  220.  
  221. game = '';
  222.  
  223. var _tick = GetTickCount();
  224. if ((_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick)
  225. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)
  226. && (_GameIsFullTick < 0 || (_GameIsFullTick + GameIsFullDelay) < _tick))
  227. {
  228. DebugInOOG('Locating the leader : '+leaderAccountName);
  229. Say('/f l');
  230. Delay(1500);
  231. }
  232.  
  233. if(chat = controlData.get(controlData.controls.lobby.chat.textBox.channelText))
  234. {
  235. var found_leader = false;
  236. lines = chat.GetText();
  237. for (var line_id = lines.length - 1; line_id > -1; line_id--)
  238. {
  239. if (found_leader) // useless... :/
  240. break;
  241.  
  242. if (lines[line_id].substring(0,1) == " ")
  243. continue;
  244.  
  245. // retrieving the whole message
  246. var msg = lines[line_id].replace(/^\s+|\s+$/, "");
  247. var msglines = 1;
  248. while (lines[line_id+msglines] != undefined && lines[line_id+msglines].substring(0,2) == " ")
  249. {
  250. msg += " " + lines[line_id+msglines].replace(/^\s+|\s+$/, "");
  251. msglines++;
  252. }
  253. if (msg.lastIndexOf(leaderName) >= 0)
  254. DebugInOOG("yc8found him :;"+msg);
  255.  
  256. // checking if the msg is a friendly whisper
  257. if (msg.lastIndexOf(leaderName + ' (*' +leaderAccountName+')') > -1)
  258. {
  259. var regGameNameWhispered=/^.*(game|partie|spiel|partita|partida).*(nomm[^\s]*|called|chiamata)\s*([\w\s-]*\w)\s*\.\s*$/gi;
  260. if (msg.match(regGameNameWhispered))
  261. game = msg.replace(regGameNameWhispered, "$3");
  262.  
  263. if (game != '')
  264. {
  265. found_leader = true;
  266. break;
  267. }
  268. }
  269.  
  270. // checking if the msg is from the friend list
  271. if (msg.lastIndexOf(': '+leaderAccountName+',') > -1)
  272. {
  273. found_leader = true;
  274. var regOffline=/^.*(offline|desconectado).*$/gi;
  275. var regInChat=/^.*(channel|canale?)\s*([\w\s-]*\w)\.?\s*$/gi;
  276. var regGameName=/^.*(game|partie|spiel|partita|partida)\s*([\w\s-]*\w)\s*\(priv[^\)]*\)\.\s*$/gi;
  277.  
  278. if (msg.match(regOffline)
  279. && (_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick))
  280. {
  281. DebugInOOG('Leader is offline, delay '+Math.round(LeaderOfflineDelay/1000)+' sec for next /f l.');
  282. _leaderOfflineTick = GetTickCount();
  283. }
  284. else if (msg.match(regInChat)
  285. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick))
  286. {
  287. DebugInOOG('Leader is in the chat "'+msg.replace(regInChat, "$2")+'", delay '+Math.round(LeaderInChatDelay/1000)+' sec for next /f l.');
  288. _leaderInChatTick = GetTickCount();
  289. }
  290. else if (msg.match(regGameName)
  291. && ((_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick)
  292. && (_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)))
  293. {
  294. game = msg.replace(regGameName, "$2");
  295. }
  296. else if ((_leaderInChatTick < 0 || (_leaderInChatTick + LeaderInChatDelay) < _tick)
  297. && (_leaderOfflineTick < 0 || (_leaderOfflineTick + LeaderOfflineDelay) < _tick))
  298. {
  299. // unhandled line, supposelly "In Realm"
  300. DebugInOOG('The leader was in the the lobby but not in chat, delay '+Math.round(LeaderInChatDelay/1000)+' sec for next /f l.');
  301. _leaderInChatTick = GetTickCount();
  302. }
  303.  
  304. break;
  305. }
  306. }
  307.  
  308. if (found_leader == false)
  309. DebugInOOG('I couldn\'t find the leader in my friend list!');
  310.  
  311. if (game!="")
  312. {
  313. if (UseCDKeyChangeTrick)
  314. {
  315. // increasing the number of runs in the OOG (for CDKey switch)
  316. // Problem : the gamename/gamepassword set in your OOG will be typed in the lobbyChat
  317. // this may output a red message in the lobby chat if you have a password set (not a real problem)
  318. // I recommend to set a gamename like "Run" and no gamepassword in your OOG. -> this will output "Run-01", "Run-02", etc in lobby chat before joining games
  319. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  320. Delay(1000);
  321. }
  322.  
  323. DebugInOOG('Leader is in the game "' + game + '"');
  324. controlData.click(controlData.controls.lobby.button.join);
  325. Delay(100);
  326. }
  327.  
  328. }
  329. else
  330. {
  331. DebugInOOG('I can\'t read the chat!');
  332. //DebugInOOG('You probably haven\'t added the lobby chat controlinfo coordinates!');
  333. Delay(30000);
  334. }
  335. break;
  336.  
  337. case 1: // Lobby
  338. if(location.id == 1 && joinChatAfterGame)
  339. {
  340. Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  341. controlData.click(controlData.controls.lobby.button.enterChat);
  342. break;
  343. }
  344. break;
  345.  
  346. case 2: // Waiting In Line
  347. if(GetTickCount()-lastGameMade > waitInLineTimeout)
  348. controlData.click(controlData.controls.lobby.inLine.button.cancel);
  349. break;
  350.  
  351. case 4: // Create Game
  352. if(!controlData.get(controlData.controls.lobby.create.editBox.gameName))
  353. {
  354. controlData.click(controlData.controls.lobby.button.join);
  355. Delay (500);
  356. controlData.click(controlData.controls.lobby.button.create);
  357. Delay (500);
  358. break;
  359. }
  360.  
  361. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  362.  
  363. locationTimeout(5000, location);
  364.  
  365. lastGameMade = GetTickCount();
  366. lastGameStatus = 1; // pending creation
  367. break;
  368.  
  369. case 5: // Join Game
  370. if (game)
  371. {
  372. controlData.setText( controlData.controls.lobby.join.editBox.gameName, game);
  373. Delay (100);
  374. controlData.setText( controlData.controls.lobby.join.editBox.password, gamepassword);
  375. Delay (100);
  376. controlData.click(controlData.controls.lobby.join.button.joinGame);
  377. RunGC(); // run garbage collector between each game
  378. locationTimeout(5000, location);
  379. lastGameStatus = 1; // pending join
  380. }
  381. else
  382. {
  383. DebugInOOG('No game to join : cancelling');
  384. me.Cancel(1);
  385. Delay(1000);
  386. }
  387. break;
  388.  
  389. case 6: // Ladder
  390. break;
  391.  
  392. case 7: // Channel List
  393. break;
  394.  
  395. case 8: // Main Menu
  396. if(controlData.getCurrentRealmIndex() == me.gatewayid)
  397. {
  398. outputGameLength();
  399. controlData.click(controlData.gameTypes[me.playtype]);
  400. }
  401. else
  402. controlData.click(controlData.controls.mainMenu.button.gateway);
  403. break;
  404.  
  405. case 9: // Login
  406. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  407. Delay(loginDelay);
  408.  
  409. controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  410.  
  411. sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  412.  
  413. locationTimeout(5000, location);
  414. break;
  415.  
  416. case 10: // Login Error (this is a fatal error, so stop)
  417. sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  418. Delay(3500);
  419. break;
  420.  
  421. case 11: // Unable To Connect
  422. timeoutDelay(unableToConnectRetry*60*1000, location)
  423. controlData.click(controlData.controls.login.unableToConnect.button.ok);
  424. break;
  425.  
  426. case 12: // Character Select
  427. var _time, _control;
  428.  
  429. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  430.  
  431. for(_time = 0 ; _time < characterScreenTimeout ; _time += 500)
  432. {
  433. _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  434. if(_control && _control.GetText() != undefined)
  435. break;
  436.  
  437. Delay(500);
  438. }
  439.  
  440. if(_time < characterScreenTimeout)
  441. {
  442. Delay(characterSelectDelay);
  443.  
  444. controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  445. controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  446.  
  447. // reset last game made, so it doesnt make a game immediately
  448. inGameAt = 0;
  449. setNextGameMake();
  450. }
  451. else
  452. {
  453. controlData.click(controlData.controls.characterSelect.button.exit);
  454. timeoutDelay(realmDownRetry*60*1000, location);
  455. }
  456. break;
  457.  
  458. case 13: // Realm Down - Character Select screen
  459. controlData.click(controlData.controls.characterSelect.button.exit);
  460. timeoutDelay(realmDownRetry*60*1000, location);
  461. break;
  462.  
  463. case 14: // Character Select - Disconnected
  464. timeoutDelay(disconnectedRetry*60*1000, location);
  465. controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  466. break;
  467.  
  468. case 15: // New Character
  469. break;
  470.  
  471. case 16: // Character Select - Please Wait popup
  472. if(!locationTimeout(pleaseWaitTimeout, location))
  473. controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  474. break;
  475.  
  476. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  477. controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  478. break;
  479.  
  480. case 18: // D2 Splash
  481. controlData.click(controlData.controls.d2Splash.textBox.copyright);
  482. break;
  483.  
  484. case 19: // Login - Cdkey In Use
  485. timeoutDelay(cdkeyInUseRetry*60*1000, location);
  486. controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  487. break;
  488.  
  489. case 20: // Single Player - Select Difficulty
  490. controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  491. break;
  492.  
  493. case 21: // Main Menu - Connecting
  494. if(!locationTimeout(connectingToBnetTimeout, location))
  495. controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  496. break;
  497.  
  498. case 22: // Login - Invalid Cdkey (classic or xpac)
  499. sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  500. Delay(3500);
  501. break;
  502.  
  503. case 23: // Character Select - Connecting
  504. if(!locationTimeout(characterScreenTimeout, location))
  505. controlData.click(controlData.controls.characterSelect.button.exit);
  506. break;
  507.  
  508. case 24: // Server Down - not much to do but wait..
  509. break;
  510.  
  511. case 25: // Lobby - Please Wait
  512. if(!locationTimeout(pleaseWaitTimeout, location))
  513. controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  514. break;
  515.  
  516. case 26: // Lobby - Game Name Exists
  517. sendEventToOOG(D2NT_MGR_PRINT_LOG, "yE00000Game already exists", 0);
  518.  
  519. inGameAt = 0;
  520. lastGameStatus = 0;
  521. setNextGameMake();
  522.  
  523. locationTimeout(15000, location);
  524. break;
  525.  
  526. case 27: // Gateway Select
  527. controlData.clickRealmEntry(me.gatewayid);
  528. controlData.click(controlData.controls.gateway.button.ok);
  529. break;
  530.  
  531. case 28: // Lobby - Game Does Not Exist
  532. inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  533. lastGameStatus = 0;
  534. setNextGameMake();
  535.  
  536. locationTimeout(gameDoesNotExistTimeout, location);
  537. break;
  538. default:
  539. DebugInOOG("Unhandled location : "+location.id);
  540. break;
  541. }
  542. DebugInOOG("Location : "+location.id);
  543. }
  544.  
  545. function sendEventToOOG(locationId, statusString, pendingTime)
  546. {
  547. return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  548. }
  549.  
  550. function setNextGameMake()
  551. {
  552. lastGameMade = GetTickCount();
  553. nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  554. inGameAt = 0;
  555. chatActionsDone = false;
  556. }
  557.  
  558. function outputGameLength()
  559. {
  560. if(inGameAt)
  561. {
  562. duration = GetTickCount() - inGameAt;
  563.  
  564. inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  565. }
  566. }
  567.  
  568. function locationTimeout(time, location)
  569. {
  570. endtime = GetTickCount() + time;
  571.  
  572. while(controlData.getLocation().id == location.id && endtime > GetTickCount())
  573. {
  574. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  575. Delay(500);
  576. }
  577.  
  578. return (controlData.getLocation().id != location.id);
  579. }
  580.  
  581. function timeoutDelay(time, location)
  582. {
  583. endtime = GetTickCount() + time;
  584.  
  585. while(endtime > GetTickCount())
  586. {
  587. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  588. Delay(1000);
  589. }
  590. }
  591.  
  592. function getRandomString(_length)
  593. {
  594. _retString = "";
  595. _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  596.  
  597. while(_length--)
  598. {
  599. _retString += _charSet.charAt(Random(0, _charSet.length-1));
  600. Delay(1);
  601. }
  602.  
  603. return _retString;
  604. }
  605. function DebugInOOG(logString)
  606. {
  607. if (Debug)
  608. return SendCopyData("D2NT Manager", null, 9<<16, "-- Debug : " + logString);
  609. else
  610. return false;
  611. }
Add Comment
Please, Sign In to add comment