library Multiboard initializer init
globals
multiboard MULTIBOARD
integer array KILLS
string array PLAYER_COLOR
integer array PR
endglobals
function SetItem takes multiboard mboard, integer row, integer col, string text returns nothing
local multiboarditem mbi = MultiboardGetItem(mboard, row, col )
call MultiboardSetItemValue( mbi, text)
call MultiboardReleaseItem( mbi )
set mbi = null
endfunction
function SetWidth takes multiboard mboard, integer row, integer col, real width returns nothing
local multiboarditem mbi = MultiboardGetItem(mboard, row, col)
call MultiboardSetItemWidth( mbi, width )
call MultiboardReleaseItem(mbi)
set mbi = null
endfunction
function SetStyleValue takes multiboard mboard, integer row, integer col returns nothing
local multiboarditem mbi = MultiboardGetItem(mboard, row, col)
call MultiboardSetItemStyle( mbi, true, false )
call MultiboardReleaseItem(mbi)
set mbi = null
endfunction
function SetStyleIcon takes multiboard mboard, integer row, integer col returns nothing
local multiboarditem mbi = MultiboardGetItem(mboard, row, col)
call MultiboardSetItemStyle( mbi, false, true )
call MultiboardReleaseItem(mbi)
set mbi = null
endfunction
function SetStylePath takes multiboard mboard, integer row, integer col, string path returns nothing
local multiboarditem mbi = MultiboardGetItem(mboard, row, col)
call MultiboardSetItemIcon( mbi, path)
call MultiboardReleaseItem(mbi)
set mbi = null
endfunction
private function mbCreate takes nothing returns nothing
local integer r = 0
local integer c = 0
local integer ip = 0
call DestroyTimer(GetExpiredTimer())
set MULTIBOARD = CreateMultiboard()
call MultiboardSetColumnCount(MULTIBOARD, 4)
call MultiboardSetRowCount(MULTIBOARD, 12)
call MultiboardSetTitleText(MULTIBOARD, "Scoreboard")
loop
exitwhen c == 4
loop
exitwhen r == 12
call SetStyleValue(MULTIBOARD, r, c)
if c == 0 then
if r == 0 or r == 4 or r == 8 then
call SetItem(MULTIBOARD, r, c, "Team " + I2S(r/4 + 1))
else
call SetItem(MULTIBOARD, r, c, PLAYER_COLOR[ip] + GetPlayerName(Player(ip)) + "|r")
set ip = ip + 1
endif
call SetWidth(MULTIBOARD, r, c, .10)
elseif c == 1 then
if r == 0 or r == 4 or r == 8 then
call SetItem(MULTIBOARD, r, c, "Kills")
else
call SetItem(MULTIBOARD, r, c, "0")
endif
call SetWidth(MULTIBOARD, r, c, .05)
elseif c == 2 then
if r == 0 or r == 4 or r == 8 then
call SetItem(MULTIBOARD, r, c, "Gold")
else
call SetItem(MULTIBOARD, r, c, "0")
endif
call SetWidth(MULTIBOARD, r, c, .05)
elseif c == 3 then
if r == 0 or r == 4 or r == 8 then
call SetItem(MULTIBOARD, r, c, "Lumber")
else
call SetItem(MULTIBOARD, r, c, "0")
endif
call SetWidth(MULTIBOARD, r, c, .05)
endif
set r = r + 1
endloop
set c = c + 1
set r = 0
endloop
call MultiboardDisplay(MULTIBOARD, true)
endfunction
private function mbUpdateResources takes nothing returns nothing
local integer i = 0
local integer c = 2
loop
exitwhen c == 4
loop
exitwhen i == 9
if c == 2 then
call SetItem(MULTIBOARD, PR[i], c, I2S(GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_GOLD)))
elseif c == 3 then
call SetItem(MULTIBOARD, PR[i], c, I2S(GetPlayerState(Player(i), PLAYER_STATE_RESOURCE_LUMBER)))
endif
set i = i + 1
endloop
set i = 0
set c = c + 1
endloop
endfunction
private function mbKillsUpdate takes nothing returns boolean
local unit lvUnit = GetKillingUnit()
local player lvPlayer = GetOwningPlayer(lvUnit)
local integer i = 0
loop
exitwhen i == 9
if GetPlayerId(lvPlayer) == i then
set KILLS[i] = KILLS[i] + 1
call SetItem(MULTIBOARD, PR[i], 1, I2S(KILLS[i]))
endif
set i = i + 1
endloop
set lvUnit = null
set lvPlayer = null
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
exitwhen i == 13
set KILLS[i] = 0
set i = i + 1
endloop
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t, function mbKillsUpdate)
call TimerStart(CreateTimer(), .01, false, function mbCreate)
call TimerStart(CreateTimer(), .25, true, function mbUpdateResources)
set PLAYER_COLOR[0] = "|c00FF0303"
set PR[0] = 1
set PLAYER_COLOR[1] = "|c000042FF"
set PR[1] = 2
set PLAYER_COLOR[2] = "|c001CE6B9"
set PR[2] = 3
set PLAYER_COLOR[3] = "|c00540081"
set PR[3] = 5
set PLAYER_COLOR[4] = "|c00FFFC01"
set PR[4] = 6
set PLAYER_COLOR[5] = "|c00fEBA0E"
set PR[5] = 7
set PLAYER_COLOR[6] = "|c0020C000"
set PR[6] = 9
set PLAYER_COLOR[7] = "|c00E55BB0"
set PR[7] = 10
set PLAYER_COLOR[8] = "|c00959697"
set PR[8] = 11
set PLAYER_COLOR[9] = "|c007EBFF1"
set PLAYER_COLOR[10] = "|c00106246"
set PLAYER_COLOR[11] = "|c004E2A04"
set t = null
endfunction
endlibrary