scoreboard players reset #red_milk temp
scoreboard players reset #blue_milk temp
scoreboard players set #milk_winner temp -1

execute as @a[distance=..250,team=red] run scoreboard players operation #red_milk temp += @s drank_milk
execute as @a[distance=..250,team=blue] run scoreboard players operation #blue_milk temp += @s drank_milk

execute if score #red_milk temp = #blue_milk temp run scoreboard players set #milk_winner temp 0
execute unless score #milk_winner temp matches 0 if score #red_milk temp >= #blue_milk temp run scoreboard players set #milk_winner temp 1
execute unless score #milk_winner temp matches 0 if score #blue_milk temp >= #red_milk temp run scoreboard players set #milk_winner temp 2

# 0 = tie
# 1 = red wins
# 2 = blue wins

tellraw @a[distance=..250] ["",{"text":"The ","color":"aqua"},{"text":"Red Team","color":"red"},{"text":" drank ","color":"aqua"},{"score":{"name":"#red_milk","objective":"temp"},"bold":true,"color":"yellow"},{"text":" buckets of milk!","color":"aqua"}]
tellraw @a[distance=..250] ["",{"text":"The ","color":"aqua"},{"text":"Blue Team","color":"blue"},{"text":" drank ","color":"aqua"},{"score":{"name":"#blue_milk","objective":"temp"},"bold":true,"color":"yellow"},{"text":" buckets of milk!","color":"aqua"}]
tellraw @a[distance=..250] {"text":" ","color":"white"}
execute if score #milk_winner temp matches 0 run function pctf:logic/items/lucky_block/outcomes/global/milk/result/tie
execute if score #milk_winner temp matches 1 run function pctf:logic/items/lucky_block/outcomes/global/milk/result/red_wins
execute if score #milk_winner temp matches 2 run function pctf:logic/items/lucky_block/outcomes/global/milk/result/blue_wins
execute if score #milk_winner temp matches -1 run say milk error

kill @s