Name | Type | is_array | initial_value |
ColorPlayerIdx | integer | Yes | |
FFA | boolean | No | |
Index | integer | No | |
IntNicknameStringCutoff | integer | No | 15 |
MaxColors | integer | No | |
MaxPlayers | integer | No | 4 |
ParsedNickname | string | No | |
PlayerColorIdx | integer | Yes | |
TeamColor | playercolor | Yes |
function RandomPlayerColor takes nothing returns nothing
local integer randomColor = GetRandomInt(0, udg_MaxColors)
local integer i = 0
loop
// Check if randomly picked color is in use
if udg_ColorPlayerIdx[randomColor] == 0 then
// It is not, assign it to this player
set udg_ColorPlayerIdx[randomColor] = udg_Index
set udg_PlayerColorIdx[udg_Index] = randomColor
call SetPlayerColor(ConvertedPlayer(udg_Index), udg_TeamColor[randomColor])
endif
exitwhen udg_PlayerColorIdx[udg_Index] > 0 or i > udg_MaxColors
// Color is in use
if randomColor < udg_MaxColors then
// Check next one
set randomColor = randomColor + 1
else
// Return to first color
set randomColor = 1
endif
// Infinite loop catch in case I did something dumb.
set i = i + 1
endloop
endfunction
function Trig_Randomize_Player_Colors_Actions takes nothing returns nothing
set udg_Index = 1
loop
exitwhen udg_Index > udg_MaxPlayers
call RandomPlayerColor()
set udg_Index = udg_Index + 1
endloop
endfunction
//===========================================================================
function InitTrig_Randomize_Player_Colors takes nothing returns nothing
set gg_trg_Randomize_Player_Colors = CreateTrigger( )
call TriggerAddAction( gg_trg_Randomize_Player_Colors, function Trig_Randomize_Player_Colors_Actions )
endfunction