local integer i = 0
    local integer j = 0
    local integer w = 0
    local string s
    local player p
    local integer t = 0
    local boolean add = false
    loop
        exitwhen i == 12
        if GetPlayerTeam(Player(i)) > t then
            set t = GetPlayerTeam(Player(i))
        endif
        set i = i+1
    endloop
    set MainMB = CreateMultiboard()
    call MultiboardSetTitleText(MainMB, Title)
    call MultiboardSetColumnCount(MainMB, 5)
    call MultiboardSetRowCount(MainMB, 1)
    call SetMBIProp( 1, 1, null,           null,          false, false )
    call SetMBIProp( 1, 2, Player_Text,    PlayerIcon,    true,  true  )
    call SetMBIProp( 1, 3, Buildings_Text, BuildingsIcon, true,  true  )
    call SetMBIProp( 1, 4, Kills_Text,     KillsIcon,     true,  true  )
    call SetMBIProp( 1, 5, Devotion_Text,  DevotionIcon,  true,  true  )
    set i = 0
    loop
        exitwhen i > t
        set s = "Team " + I2S(i+1)
        call MultiboardSetRowCount(MainMB, MultiboardGetRowCount(MainMB) + 1)
        set j = 1
        loop
            exitwhen j > 5
            if j == 1 then
                call SetMBIProp( MultiboardGetRowCount(MainMB), j, " ", null, true, false )
            else
                call SetMBIProp( MultiboardGetRowCount(MainMB), j, Sep, null, true, false )
            endif
            set j = j + 1
        endloop
        call SetMBIProp( MultiboardGetRowCount(MainMB), 2, s, null, true, false )
        if StringLength(s) > w then
            set w = StringLength(s)
        endif
        set j = 0
        set add = false
        loop
            exitwhen j == 12
            set p = Player(j)
            if GetPlayerTeam(p) > -1 and GetPlayerTeam(p) == i and GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerId(p) < 12 then
                set add = true
                call ForceAddPlayer(UserPlayers, p)
                // sets the row count
                call MultiboardSetRowCount(MainMB, MultiboardGetRowCount(MainMB) + 1)
                set stats(j).index = MultiboardGetRowCount(MainMB)
                // set race icon...
                call SetMBIProp(stats(j).index, 1, null, GetRaceIcon(p), false, true)
                // set player name
                if StringLength(GetPlayerName(p)) > w then
                    set w = StringLength(GetPlayerName(p))
                endif
                call SetMBIProp(stats(j).index, 2, ColorSys_SetPlayerColorText(p) + GetPlayerName(p), null, true, false)
                // set player buildings
                set stats(j).buildings = GetPlayerStructureCount(p, true)
                call SetMBIProp(stats(j).index, 3, I2S(stats(j).buildings), null, true, false)
                // set player kills
                call SetMBIProp(stats(j).index, 4, I2S(stats(j).kills), null, true, false)
                // set player devotion points
                call SetMBIProp(stats(j).index, 5, I2S(stats(j).devpoints), null, true, false)
                // Set ally visibility of stats
                call SetStatsVisibility(stats(j).index, p)
            endif
            set j = j + 1
        endloop
        if not add then
            call MultiboardSetRowCount(MainMB, MultiboardGetRowCount(MainMB) - 1)
        endif
        set i = i + 1
    endloop
    call SetColumnWidth( 1, 0.015 )
    call SetColumnWidth( 2, w * PercChar + 0.01 )
    call SetColumnWidth( 3, 0.07 )
    call SetColumnWidth( 4, 0.04 )
    call SetColumnWidth( 5, 0.06 )
    call MultiboardDisplay( MainMB, true )
    call MultiboardMinimize( MainMB, true )