haxball / haxball-issues

114 stars 42 forks source link

teamgoal errore #1799

Closed peppewarrior1 closed 1 year ago

peppewarrior1 commented 1 year ago
BROWSER LOG ERROR [2023-04-06T15:52:00.608Z] [public2] [ERROR HHM]:  Error during execution of handler onTeamGoal for plugin /home/haxroomie/biglassicbot.js
BROWSER LOG ERROR [2023-04-06T15:52:00.611Z] [public2] [ERROR HHM]:
BROWSER LOG ERROR [2023-04-06T15:52:00.612Z] [public2] TypeError: Cannot read properties of undefined (reading 'team')
    at getGoalString (eval at _executePlugin (https://hhm.surge.sh/releases/hhm-1.0.2.js:1:1), <anonymous>:3951:23)
    at room.onTeamGoal (eval at _executePlugin (https://hhm.surge.sh/releases/hhm-1.0.2.js:1:1), <anonymous>:5100:22)
    at TrappedRoomManager._executeHandlerFunction (https://hhm.surge.sh/releases/hhm-1.0.2.js:18361:48)
    at TrappedRoomManager.executeHandler (https://hhm.surge.sh/releases/hhm-1.0.2.js:18328:12)
    at TrappedRoomManager.onExecuteEventHandlers (https://hhm.surge.sh/releases/hhm-1.0.2.js:18939:16)
    at room.<computed> (https://hhm.surge.sh/releases/hhm-1.0.2.js:516:41)
    at Aa.u.zf (https://www.haxball.com/PFj3geCw/__cache_static__/g/headless-min.js:65:21)
    at J.Ba (https://www.haxball.com/PFj3geCw/__cache_static__/g/headless-min.js:72:162)
    at Aa.Ba (https://www.haxball.com/PFj3geCw/__cache_static__/g/headless-min.js:100:462)
    at Fa.dg (https://www.haxball.com/PFj3geCw/__cache_static__/g/headless-min.js:44:376)

It gives me this strange error only when I use haxroomie.... Why?

room.onTeamGoal = function (team) {
    const scores = room.getScores();
    game.scores = scores;
    playSituation = Situation.GOAL;
    ballSpeed = getBallSpeed();
    var goalString = getGoalString(team);
    for (let player of teamRed) {
        var playerComp = getPlayerComp(player);
        team == Team.RED ? playerComp.goalsScoredTeam++ : playerComp.goalsConcededTeam++;
    }
    for (let player of teamBlue) {
        var playerComp = getPlayerComp(player);
        team == Team.BLUE ? playerComp.goalsScoredTeam++ : playerComp.goalsConcededTeam++;
    }
    room.sendAnnouncement(
        goalString,
        null,
        team == Team.RED ? redColor : blueColor,
        null,
        HaxNotification.CHAT
    );
    if (roomWebhook != '') {
        fetch(roomWebhook, {
            method: 'POST',
            body: JSON.stringify({
                content: `[${getDate()}] ${goalString}`,
                username: roomName,
            }),
            headers: {
                'Content-Type': 'application/json',
            },
        }).then((res) => res);
    }
    if ((scores.scoreLimit != 0 && (scores.red == scores.scoreLimit || scores.blue == scores.scoreLimit)) || goldenGoal) {
        endGame(team);
        goldenGoal = false;
        stopTimeout = setTimeout(() => {
            room.stopGame();
        }, 1000);
    }
};

function getGoalString(team) {
    var goalString;
    var scores = game.scores;
    var goalAttribution = getGoalAttribution(team);
    var teamgoal = room.getPlayerList();
    if (goalAttribution[0] != null) {
        if (goalAttribution[0].team == team) {
            if (goalAttribution[1] != null && goalAttribution[1].team == team) {
                if (BakhmutMode == true) {
                    goalString = `⚽ ${getTimeGame(scores.time)} Bombardamento di ${goalAttribution[0].name} ! Con l'aiuto di ${goalAttribution[1].name}. Velocità del missile : ${ballSpeed.toFixed(2)}km/h.`;
                    game.goals.push(
                        new Goal(
                            scores.time,
                            team,
                            goalAttribution[0],
                            goalAttribution[1]
                        )
                    );
                    for (let i = 0; i < teamgoal.length; i++) {
                        if (players[i].team == team) room.setPlayerAvatar(teamgoal[i].id, "🔫");
                    }
                    for (let i = 0; i < teamgoal.length; i++) {
                        if (players[i].team != team) room.setPlayerAvatar(teamgoal[i].id, "💥");
                    }
                    console("BRO SI PRONT?", teamgoal)
                    room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 30} );
                    room.setPlayerDiscProperties(goalAttribution[1].id, {radius: 20} );
                    setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)
                    setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[1].id, {radius: 15}) }, 1.8 * 1000)
                    setTimeout(() => {
                        for (let i = 0; i < teamgoal.length; i++) {
                           room.setPlayerAvatar(teamgoal[i].id, null);
                        }
                    }, 1.8 * 1000);         
                } else {
                    goalString = `⚽ ${getTimeGame(scores.time)} Goal di ${goalAttribution[0].name} ! Assist di ${goalAttribution[1].name}. Velocità del goal : ${ballSpeed.toFixed(2)}km/h.`;
                    game.goals.push(
                        new Goal(
                            scores.time,
                            team,
                            goalAttribution[0],
                            goalAttribution[1]
                        )
                    );
                    room.setPlayerAvatar(goalAttribution[0].id, "⚽")
                    room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 30} );
                    room.setPlayerAvatar(goalAttribution[1].id, "🅰️")
                    room.setPlayerDiscProperties(goalAttribution[1].id, {radius: 20} );
                    setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)
                    setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[1].id, {radius: 15}) }, 1.8 * 1000)
                    setTimeout(() => { room.setPlayerAvatar(goalAttribution[0].id, null) }, 1.8 * 1000)
                    setTimeout(() => { room.setPlayerAvatar(goalAttribution[1].id, null) }, 1.8 * 1000)
                }
            } else {
                if (BakhmutMode == true) {
                        goalString = `⚽ ${getTimeGame(scores.time)} Bombardamento di ${goalAttribution[0].name} ! Velocità del missile : ${ballSpeed.toFixed(2)}km/h.`;
                        game.goals.push(
                            new Goal(scores.time, team, goalAttribution[0], null)
                        );
                        for (let i = 0; i < teamgoal.length; i++) {
                            if (players[i].team == team) room.setPlayerAvatar(teamgoal[i].id, "🔫");
                        }
                        for (let i = 0; i < teamgoal.length; i++) {
                            if (players[i].team != team) room.setPlayerAvatar(teamgoal[i].id, "💥");
                        }
                        room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 30} );
                        setTimeout(() => {
                            for (let i = 0; i < teamgoal.length; i++) {
                               room.setPlayerAvatar(teamgoal[i].id, null);
                            }
                        }, 1.8 * 1000);
                        setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)                 
                } else {
                    goalString = `⚽ ${getTimeGame(scores.time)} Goal di ${goalAttribution[0].name} ! Velocità del goal : ${ballSpeed.toFixed(2)}km/h.`;
                    game.goals.push(
                        new Goal(scores.time, team, goalAttribution[0], null)
                    );
                    room.setPlayerAvatar(goalAttribution[0].id, "⚽")
                    room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 30} );
                    setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)
                    setTimeout(() => { room.setPlayerAvatar(goalAttribution[0].id, null) }, 1.8 * 1000)
                }
            }
        } else {
            if (BakhmutMode == true) {
                goalString = `😂 ${getTimeGame(scores.time)} Auto bombardamento di ${goalAttribution[0].name} ! Velocità del missile : ${ballSpeed.toFixed(2)}km/h.`;
                game.goals.push(
                    new Goal(scores.time, team, goalAttribution[0], null)
                );
                for (let i = 0; i < teamgoal.length; i++) {
                    if (players[i].team == team) room.setPlayerAvatar(teamgoal[i].id, "🔫");
                }
                for (let i = 0; i < teamgoal.length; i++) {
                    if (players[i].team != team) room.setPlayerAvatar(teamgoal[i].id, "💥");
                }
                room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 7.5} );
                setTimeout(() => {
                    for (let i = 0; i < teamgoal.length; i++) {
                        room.setPlayerAvatar(teamgoal[i].id, null);
                    }
                }, 1.8 * 1000);
                setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)         
            } else {
                goalString = `😂 ${getTimeGame(scores.time)} Autogoal di ${goalAttribution[0].name} ! Velocità del goal : ${ballSpeed.toFixed(2)}km/h.`;
                game.goals.push(
                    new Goal(scores.time, team, goalAttribution[0], null)
                );
                room.setPlayerAvatar(goalAttribution[0].id, "🐸")
                room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 7.5} );
                setTimeout(() => { room.setPlayerDiscProperties(goalAttribution[0].id, {radius: 15}) }, 1.8 * 1000)
                setTimeout(() => { room.setPlayerAvatar(goalAttribution[0].id, null) }, 1.8 * 1000)
            }
        }
    } else {
        if (BakhmutMode == true){
            if (team == "RED") {
                goalString = `⚽ ${getTimeGame(scores.time)} Bombardamento riuscito per la RUSSIA! Velocità del missile : ${ballSpeed.toFixed(2)}km/h.`;
            }
            else {
                goalString = `⚽ ${getTimeGame(scores.time)} Bombardamento riuscito per l'UCRAINA! Velocità del missile : ${ballSpeed.toFixed(2)}km/h.`;
            }
            for (let i = 0; i < teamgoal.length; i++) {
                if (players[i].team == team) room.setPlayerAvatar(teamgoal[i].id, "🔫");
            }
            for (let i = 0; i < teamgoal.length; i++) {
                if (players[i].team != team) room.setPlayerAvatar(teamgoal[i].id, "💥");
            }
            setTimeout(() => {
                for (let i = 0; i < teamgoal.length; i++) {
                    room.setPlayerAvatar(teamgoal[i].id, null);
                }
            }, 1.8 * 1000);
            game.goals.push(
                new Goal(scores.time, team, null, null)
            );
        } else {
            goalString = `⚽ ${getTimeGame(scores.time)} Goal per la squadra ${team == Team.RED ? 'red' : 'blue'} ! Velocità del goal : ${ballSpeed.toFixed(2)}km/h.`;
            game.goals.push(
                new Goal(scores.time, team, null, null)
            );
        }
    }

    return goalString;
}
peppewarrior1 commented 1 year ago

@furkanardagul @thenorthstar