kolton / d2bot-with-kolbot

d2bot game manager by D3STROY3R with kolbot libs by kolton for d2bs
345 stars 332 forks source link

MFHelper - clearlevel & clear commands - Error "Failed to use portal." #704

Open Ricola3D opened 6 years ago

Ricola3D commented 6 years ago

Environment:

Settings:

Scenario:

I added some logs to find the issue here in code:

MFHelper.js

} else if (command.indexOf("clearlevel") > -1) {
    print("MFHelper: Clear Level");

    area = player.area; // Ricola3D comment - Here player area = 17 (Burial Grounds)

    for (i = 0; i < 5; i += 1) {
        if (Pather.usePortal(player.area, player.name)) {
            break;
        }

        delay(1000); // Ricola3D comment - At first iteration player.area = 17, after second iteration player.area = 19 (mausoleum)
    }

    if (me.area === area) { // Ricola3D comment - area = 17, this is wrong
        Precast.doPrecast(false);
        Attack.clearLevel(Config.ClearType);
        Precast.doPrecast(true);

        if (!Pather.usePortal(null, player.name)) {
            Town.goToTown();
        }
    } else {
        print("Failed to use portal.");
    }
}

The issue is because of the value of area and player.area as explained in comments.

A dumb work around solution is to add a delay(1000); before copying player.area value in the area variable 👎

DarkHorseDre commented 6 years ago

Issue discussed and progress made in https://github.com/kolton/d2bot-with-kolbot/issues/280 - now linked.

semajtrip commented 5 years ago

I just ran into this same exact issue with the same setup. I debugged it and concluded that the player.area is being read too early in the function. A better fix is to move area = player.area; after the for loop for taking the portal. Code should look like this:

print("ÿc4MFHelperÿc0: Clear Level");

for (i = 0; i < 5; ++i) {
    if (Pather.usePortal(player.area, player.name)) {
        break;
    }
    delay(1000);
}

area = player.area;

Also replace i += 1 to ++i because who increments the loop variable like that?

I plan on submitting a pull request to fix this issue.

DarkHorseDre commented 5 years ago

@semajtrip good work - ensure you test on all scripts. timing within and between scripts tp calls causes issues. e.g. rakinishu before trist causes a problem as the leader opens tp, tells followers to kill (take tp), kills raki (followers tp back but often miss the tp before it closes) then jumps to trist, opens tp and calls to clear area.. this nearly always failed before the above edits.

also one of the act 1 scripts did the same. I think mausoleum also failed often.