scope PlayerColors initializer Init
function SetPlayerColors takes nothing returns nothing
local integer i = 0
local group g = CreateGroup()
local group array G
local unit array u
local unit temp
local string array TXTC
local hashtable hash = InitHashtable()
set TXTC[0] = "|CFFFF0303"
set TXTC[1] = "|c000042FF"
set TXTC[2] = "|C0000FFFF"
set TXTC[3] = "|c00540081"
set TXTC[4] = "|c00FFFC01"
set TXTC[5] = "|c00FEBA0E"
set TXTC[6] = "|c0020C000"
set TXTC[7] = "|c00E55BB0"
set TXTC[8] = "|c00959697"
set TXTC[9] = "|CFF7EBFF1"
set TXTC[10] = "|CFF106246"
set TXTC[11] = "|CFF4E2A04"
// Here we make setup for changes below
loop
exitwhen i>11
set u[i] = CreateUnit(Player(15), 'hfoo', 0,0,0)
call SaveInteger(hash, 0, GetHandleId(u[i]), i)
call SaveStr(hash, 0, GetHandleId(u[i]), TXTC[i])
call GroupAddUnit(g, u[i])
set u[i] = null
set G[i] = CreateGroup()
call GroupEnumUnitsOfPlayer(G[i], Player(i), null)
set i = i + 1
endloop
set i = 0
// Here we change everything :)
loop
exitwhen i>11
set u[12] = GroupPickRandomUnit(g)
call GroupRemoveUnit(g, u[12])
// Player Color
call SetPlayerColor(Player(i), ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
// Player Name
call SetPlayerName(Player(i), LoadStr(hash, 0, GetHandleId(u[12])) + GetPlayerName(Player(i)))
// All Units Owned by Player Color
loop
set temp = FirstOfGroup(G[i])
exitwhen temp == null
call GroupRemoveUnit(G[i], temp)
call SetUnitColor(temp, ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
endloop
// Cleaning Leaks
call DestroyGroup(G[i])
set G[i] = null
call RemoveUnit(u[12])
set i = i + 1
endloop
// Cleaning Leaks
call DestroyGroup(g)
set g = null
set u[12] = null
call FlushParentHashtable(hash)
endfunction
function Init takes nothing returns nothing
call SetPlayerColors()
call FogModifierStart( CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false) )
endfunction
endscope