Wazarr94 / haxball_bot_headless

Ready-to-go scripts and functions for the HaxBall Headless API !
MIT License
46 stars 74 forks source link

allow a simple restart instead of resetting teams when players.length == 2 * teamSize #32

Closed iwishiknewcoding closed 2 years ago

iwishiknewcoding commented 2 years ago

I'd like to modify the part where the teams are reset and re-placed randomly in case players.length == 2 * teamSize. Tbh it's more annoying than beneficial at least for the players I know.

Has anyone done it yet? If so, would you please share it? If no, is anyone wiling to help to achieve this correctly? I've tried modifying this part to the following:

startTimeout = setTimeout(() => {
                    room.startGame();
                }, 2000);

is this the correct way to go?

P.S. I'm also doing the same for this part and this part.

Wazarr94 commented 2 years ago

I can confirm what you're suggesting is the correct way to do it. I'm not sure about the lines you highlighted, but I can show an example based on what you're talking about.

Replace this code (L2483-2499 in the latest version):

if (players.length == 2 * teamSize) {
    chooseMode = false;
    resetButton();
    for (var i = 0; i < teamSize; i++) {
        clearTimeout(insertingTimeout);
        insertingPlayers = true;
        setTimeout(() => {
            randomButton();
        }, 200 * i);
    }
    insertingTimeout = setTimeout(() => {
        insertingPlayers = false;
    }, 200 * teamSize);
    startTimeout = setTimeout(() => {
        room.startGame();
    }, 2000);
}

to this:

if (players.length == 2 * teamSize) {
    chooseMode = false;
    startTimeout = setTimeout(() => {
        room.startGame();
    }, 2000);
}
Wazarr94 commented 2 years ago

A tad more on why I implemented this. Especially when we are 4 in an automatic room, I think there's nothing more annoying than having to play with that really bad teammate all the time, and altenarting teams make it more of a challenge rather than a burden. Of course, you might not share this opinion and you are free to make this change. I encourage ppl to read and understand the script and change what they want