DavidJCobb / ReachVariantEditor

A tool for editing Halo: Reach game variants.
24 stars 9 forks source link

Cannot force team change if teams are enabled #13

Closed noble-ux closed 3 years ago

noble-ux commented 3 years ago

Not so much of an issue but something I figured would be worth noting in case anyone else tries it. It appears that if teams are enabled on the variant's general settings then you cannot force players to a different team.

ie:

for each player do
    if current_player.team != team[4] then
        current_player.team = team[4]
    end
end

I ran across this limitation when I was adding in scripts to set up and balance a multi-team gamemode (since Reach's custom game browser on MCC does not have options for multiple teams at this time).

Enabling team changing also has no effect on this.

noble-ux commented 3 years ago

Here was the script I was attempting to test. It could work in FFA gamemodes (such as infection) but it's untested at this point:

-- Team balancing
--
-- since MCC custom games browser doesn't have the ability to manage multiple teams
-- this script should fix the issue by assigning teams itself before the start of the game

on pregame: do  -- fire once before the beginning of the game
    for each team do
        if current_team != neutral_team then
            for each player do
                if current_player.team == current_team then  -- count number of players on a team via the players
                    current_team.player_count += 1
                    total_count += 1  -- easy way to check total number of players without any additional for loops
                end
            end
        end
    end
    --
    --  Balance teams as much as possible by limiting team size based on players at the start of the match
    --
    if total_count <= 5 then
        max_team_size = 1
    end
    if total_count >= 6 and total_count <= 8 then
        max_team_size = 2
    end
    if total_count >= 9 and total_count <= 11 then
        max_team_size = 3
    end
    if total_count >= 12 then
        max_team_size = 4
    end
    --
    for each team do  -- check if team has too many players and select a team to move them to
        if current_team.player_count > max_team_size then
            for each player randomly do
                if current_player.team == current_team
                and current_team.player_count > max_team_size then
                    current_team.player_count -= 1
                    --
                    for each team do  -- find new team to move players to
                        if current_team != neutral_team
                        and current_team != current_player.team
                        and current_team.player_count < max_team_size
                        and current_player.was_moved == 0 then  -- prevents the inner for each team loop from moving players more than once
                            current_player.team = current_team
                            current_team.player_count += 1
                            current_player.was_moved = 1
                        end
                    end
                end
            end
        end
    end
end
DavidJCobb commented 3 years ago

The player.team documentation has been updated to mention this. Thank you.