Converting 2 Team template to 4 Teams

Hey All,

I'm using the 1st person team deathmatch template and I'm trying to get it to use 4 teams instead of 2.

So far I was able to get some of it working and to show the correct points at the top in the score UI.
I edited the ScoreboardControllerClient to show the correct team colors and scores and it works when you hit TAB while the round is still going on. However, when the round ends and it displays the score, the colors and scores don't match up.

For now, I have it set to end the game when a team gets 5 points.

Below are screenshots (The scores at the top of the screen are correct, but the scoreboard doesn't match it):

The red bot should have 3 kills and the blue one should have 2.

The red bot should have 1 kill and the green bot should have 5

This is how I edited ScoreboardControllerClient:

At the top of the file, under constants, it originally had:

local FRIENDLY_COLOR = Color.New(0.0, 0.25, 1.0)
local ENEMY_COLOR = Color.New(1.0, 0.0, 0.0)

I commented those out and added this(1 is red, 2 is blue, 3 is yellow, 4 is green):

local DEFAULT_TEAM_COLOR = Color.New(1.0,1.0,1.0)
local TEAM_COLOR_1 = Color.New(0.0,0.0,1.0)
local TEAM_COLOR_2 = Color.New(1.0,0.0,0.0)
local TEAM_COLOR_3 = Color.New(1.0,1.0,0.0)
local TEAM_COLOR_4 = Color.New(0.0,1.0,0.0)

Then toward the bottom of the script, inside of function Tick(deltaTime), there is a loop that looks like it sets the player info:

function Tick(deltaTime)
    if atRoundEnd and time() - roundEndTime > ROUND_END_DURATION then
        atRoundEnd = false
    end

    if bindingDown or atRoundEnd then
        CANVAS.visibility = Visibility.INHERIT

        local players = Game.GetPlayers() 
        table.sort(players, ComparePlayers)

        for i, player in ipairs(players) do
           	local teamColor = FRIENDLY_COLOR


            if player ~= LOCAL_PLAYER and Teams.AreTeamsEnemies(player.team, LOCAL_PLAYER.team) then
            	teamColor = ENEMY_COLOR
            end

            local line = playerLines[i]
            line:GetCustomProperty("Name"):WaitForObject().text = player.name
            line:GetCustomProperty("Name"):WaitForObject():SetColor(teamColor)
            line:GetCustomProperty("KillsText"):WaitForObject().text = tostring(player.kills)
            line:GetCustomProperty("DeathsText"):WaitForObject().text = tostring(player.deaths)
        end
    else
        CANVAS.visibility = Visibility.FORCE_OFF
    end
end

I changed this to the following (see inside the loop):

function Tick(deltaTime)
    if atRoundEnd and time() - roundEndTime > ROUND_END_DURATION then
        atRoundEnd = false
    end

    if bindingDown or atRoundEnd then
        CANVAS.visibility = Visibility.INHERIT

        local players = Game.GetPlayers() 
        table.sort(players, ComparePlayers)

        for i, player in ipairs(players) do

           	if player.team == 1 then
            	teamColor = TEAM_COLOR_1
            elseif player.team == 2 then
            	teamColor = TEAM_COLOR_2
            elseif player.team == 3 then
            	teamColor = TEAM_COLOR_3
            elseif player.team == 4 then
            	teamColor = TEAM_COLOR_4
            else
            	teamColor = DEFAULT_TEAM_COLOR
            end

            local line = playerLines[i]
            line:GetCustomProperty("Name"):WaitForObject().text = player.name
            line:GetCustomProperty("Name"):WaitForObject():SetColor(teamColor)
            line:GetCustomProperty("KillsText"):WaitForObject().text = tostring(player.kills)
            line:GetCustomProperty("DeathsText"):WaitForObject().text = tostring(player.deaths)
        end
    else
        CANVAS.visibility = Visibility.FORCE_OFF
    end
end

It works correctly when you pull up the scoreboard with TAB while the round is going on, but it's not right on the scoreboard at the end of the round. The scores and bot colors don't match up on all of them.

If anyone has any insight on what I need to do, please let me know. I'm kind of new at this stuff.

Thanks,
Phoebes :slight_smile: