Wazarr94 / haxball_bot_headless

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

Critical Error #25

Closed huseyinsoyluu closed 2 years ago

huseyinsoyluu commented 2 years ago

when I open the room with the bot you shared in the last update, when I move or when I type something in the chat; It throws an error in the console.

When I type on chat something; Screenshot-20220405234302-566x497

When I try to move: Screenshot-20220405234428-563x805

for this bugs I can't test but in previous update; when I type !me it gives values as string(Goals: 1, Winrate: %10, GK: 5 etc) But I can't change like Goal count: 1, Win rate: %10, CS: 5

huseyinsoyluu commented 2 years ago

Also, in PM system; if a receiver is AFK, it gives error like: "Invalid player, make sure the name you entered is correct.". That's bcs you assign playerTargetIndex var as a players, not playersAll. and ofc playerTarget should equal to playersAll[playerTargetIndex] instead of players[playerTargetIndex]

https://github.com/Wazarr94/haxball_bot_headless/blob/3cfea961f3b81296cc123158a7aec3807c9083f0/HaxBot_public.js#L695

Wazarr94 commented 2 years ago

hi, sorry I should have tested more, I believe I only tested with one player, and the error occurs when the game is first stopped to change stadium and add the new player. It was a little typo in the Game class, so it was easy to fix. Well spotted for the PM to AFK, fixed it too.

I'm not sure to understand the remark about the me, could you rephrase it ?

Thanks a lot for the input, very appreciated.

huseyinsoyluu commented 2 years ago

Actually, my main problem, !me command output is: huseyinsoyluu: Games: 0, Wins: 0, Winrate: 0.00%, Goals: 0, Assists: 0, Saves: 0, Own Goals: 0 but I want like; (changing string values into my language) huseyinsoyluu: Match count: 0, Wins: 0, Winrate: 0.00%, Goal count: 0, Asist: 0, CS: 0, OG: 0

Wazarr94 commented 2 years ago

OK I understand, and I see why it's difficult to do.

I'm not gonna add it to the bot right now, because I may include this update in a cleaner fashion, but this is how you achieve what you want:

var statNameTranslation = {
    'games': 'matchCount',
    'goals': 'goalCount',
    'assists': 'asist',
    'saves': 'CS',
    'ownGoals': 'OG',
}

function printPlayerStats(stats) {
    let statsString = '';
    for (let [key, value] of Object.entries(stats)) {
        if (key == 'playerName') statsString += `${value}: `;
        else {
            let statName = statNameTranslation[key] ? statNameTranslation[key] : key;
            statName = statName.replace(/([A-Z])/g, ' $1').trim();
            statsString += `${statName.charAt(0).toUpperCase() + statName.slice(1)}: ${value}, `;
        }
    }
    statsString = statsString.substring(0, statsString.length - 2);
    return statsString;
}

This is what you get with this code: image

Unfortunately, the regex is done to work only with full words and in camelcase, so it handles poorly the OG and CS. The regex might be adapted to tolerate full uppercase translations, I will reply to this issue when I made the regex change, if you're interested. Gonna close this for now as everything was adressed.

Wazarr94 commented 2 years ago

Quick answer, the regex was easily found, and the previous function must be updated as follows:

function printPlayerStats(stats) {
    let statsString = '';
    for (let [key, value] of Object.entries(stats)) {
        if (key == 'playerName') statsString += `${value}: `;
        else {
            let statName = statNameTranslation[key] ? statNameTranslation[key] : key;
            let reCamelCase = /([A-Z](?=[a-z]+)|[A-Z]+(?![a-z]))/g;
            statName = statName.replace(reCamelCase, ' $1').trim();
            statsString += `${statName.charAt(0).toUpperCase() + statName.slice(1)}: ${value}, `;
        }
    }
    statsString = statsString.substring(0, statsString.length - 2);
    return statsString;
}

image

huseyinsoyluu commented 2 years ago

Hi again, according to this issue, we changed statName 's with string; but my problem with statsLeaderboardCommand function. It gives undefined in all keys like !match, !cs, wins etc.


var statNameTranslation = {
    games: "OynananMaç",
    wins: "Kazanımlar",
    winrate: "BaşarıOranı",
    goals: "GolSayısı",
    assists: "Asist",
    saves: "GolYenmeyenMaçlar",
    ownGoals: "KKGoller",
};

function statsLeaderboardCommand(player, message) {
    var key = message.split(/ +/)[0].substring(1).toLowerCase();
    printRankings(key, player.id);
}

Actually my commands for statsLeaderboardCommand are different with translations ie.

"!games" --> "!maç" "!wins" --> "!kazanım" "!goals" --> "!gol" "!assists" --> "!asist" "!saves" --> "!cs"

for summary wins command

    wins: {
        aliases: [],
        roles: Role.PLAYER,
        desc: `
        This command shows the top 5 players with the most wins in the room.`,
        function: statsLeaderboardCommand,
    },

equal to

kazanım: {
    aliases: ["kazanım", "winler", "wins"],
    roles: Role.PLAYER,
    desc: `
        This command shows the top 5 players with the most wins in the room.`,
    function: statsLeaderboardCommand,
},

kazanım command

There is no problem with storing info in localStorage if I'm not wrong gnome-shell-screenshot-58ckp2

@Wazarr94

Wazarr94 commented 2 years ago

Hi, I think you should proceed just like previously, but with a little twist, you have to translate from your language to english:

var commandStatNameTranslation = {
    maç: "games",
    kazanım: "wins",
    gol: "goals",
    asist: "assists",
    cs: "saves"
};

function statsLeaderboardCommand(player, message) {
    var key = message.split(/ +/)[0].substring(1).toLowerCase();
    let commandStatKey = commandStatNameTranslation[key] ? commandStatNameTranslation[key] : key;
    printRankings(commandStatKey, player.id);
}

Haven't tested but I'm sure it will work. Let me know if other things arise.

Joao-Vitaca commented 1 year ago

Hi, I think you should proceed just like previously, but with a little twist, you have to translate from your language to english:

var commandStatNameTranslation = {
  maç: "games",
  kazanım: "wins",
  gol: "goals",
  asist: "assists",
  cs: "saves"
};

function statsLeaderboardCommand(player, message) {
    var key = message.split(/ +/)[0].substring(1).toLowerCase();
    let commandStatKey = commandStatNameTranslation[key] ? commandStatNameTranslation[key] : key;
    printRankings(key, player.id);
}

Haven't tested but I'm sure it will work. Let me know if other things arise.

I made this modification but it's still the same

Wazarr94 commented 1 year ago

@Joao-Vitaca I made a typo in the last answer, I just edited it, that should fix it