Hi kolton,
could you explane how the D2BotChannel.dbj works?
What i want to do:
if a counter, that counts game is full or game does not exist, reach 5 or something else -> bot should split the "lines"-array at the last line where the currentgamename appears and use the last part of the splitted array...
after that, the bot should check for new gamenames etc...
i tested some versions, but im not sure, where i have to wrote what...
i cant figure out, how the D2BotChannel is working...
in the moment i´m testing with this:
Code:
var gameName, gamePass, oldGame, error, keyswap, rdblocker, gameStart, ingame, muleTrigger, firstLogin, connectFail, chatActionsDone,
lastGameStatus = "ready",
gameCount = DataFile.getStats().runs + 1,
channelTick = getTickCount(),
retry = 0,
isUp = "no",
fListTick = 0,
countFull = 0,
countNExist = 0;
Code:
function splitLines(oldlines, gn) {
//D2Bot.printToConsole("splitLines: " + gn);
var argh = oldlines.join("////").split(gn);
if (argh.length > 0) {
var str = argh[argh.length-1]; // string
var arr = str.split("////"); // string -> array
} else {
var arr = oldlines;
}
/*
FileTools.writeText(me.name + "_lines.txt", lines.join("////"));
FileTools.writeText(me.name + "_gamename.txt", gameName);
FileTools.writeText(me.name + "_split.txt", str);
FileTools.writeText(me.name + "_split.txt", str);
FileTools.writeText(me.name + "_arr1.txt", arr[0]);
FileTools.writeText(me.name + "_arr2.txt", arr[arr.length-1]);
*/
return arr;
}
function getNewGame() {
var i, n, string, text, regex, fullText, lines;
lines = ControlAction.getText(4, 28, 410, 354, 298);
if (lines) {
lines = splitLines(lines, gameName);
countFull = 0;
countNExist = 0;
fullText = lines.join(" ").replace(/\s+/g, " ");
MainLoop:
for (n = 0; n < StarterConfig.Games.length; n += 1) {
regex = new RegExp("\\W*" + StarterConfig.Games[n].toLowerCase() + "\\d*", "gi");
gameName = fullText.match(regex);
if (gameName) {
gameName = gameName[gameName.length - 1].toString().replace(/^\W*/, ""); // use last match and trim it
gamePass = StarterConfig.Passwords[n];
}
}
}
}
Code:
function main() {
addEventListener('copydata', ReceiveCopyData);
addEventListener('scriptmsg', ScriptMsgEvent);
delay(rand(1, 2) * 1000);
D2Bot.requestGameInfo();
if (error === "@error") {
timeoutDelay("Crash Delay", StarterConfig.CrashDelay * 1e3);
D2Bot.updateRuns();
}
while (true) {
while (me.ingame) { // returns true before actually in game so we can't only use this check
if (me.gameReady) { // returns false when switching acts so we can't use while
isUp = "yes";
if (!ingame) {
if (me.gamepassword.toLowerCase() !== gamePass.toLowerCase()) {
print("leaving game");
quit();
}
print("Updating Status");
D2Bot.updateStatus("Game: " + me.gamename);
oldGame = me.gamename;
lastGameStatus = "ingame";
ingame = true;
gameStart = getTickCount();
countFull = 0;
countNExist = 0;
DataFile.updateStats("runs", gameCount);
}
}
delay(1000);
}
isUp = "no";
locationAction(getLocation());
delay(1000);
}
}
Code:
case 28: // Lobby - Game Does Not Exist
countNExist += 1;
D2Bot.printToConsole("Game doesn't exist: " + gameName + " [" + countNExist + "]");
//D2Bot.printToConsole("Game doesn't exist");
lastGameStatus = "ready";
if (countNExist > 2) {
getNewGame();
}
if (!locationTimeout(StarterConfig.GameDoesNotExistTimeout * 1e3, location)) {
ControlAction.click(6, 652, 469, 120, 20); // Join-Button
ControlAction.click(6, 433, 433, 96, 32); // (type, xstart, ystart, +xdiff, -ydiff)
}
break;
and
Code:
case 38: // Game is full
//D2Bot.printToConsole("Game is full");
countFull += 1;
D2Bot.printToConsole("Game is full: " + gameName + " [" + countFull + "]");
lastGameStatus = "ready";
if (countFull > 2) {
getNewGame();
}
delay(500);
ControlAction.click(6, 652, 469, 120, 20); // Join-Button
break;