• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

GetLocalPlayer() Multiboard problem

Status
Not open for further replies.
Level 15
Joined
Oct 16, 2010
Messages
941
I played an 8-man LAN match the other day to help test my next update to RVG, for some reason only one player can see their multiboard. Does anybody know why?

BTW - multiboards are created after hero selection where the Heroes[] array contains the hero of each player.

JASS:
//! zinc
library Multiboard requires Multibars, Stats
{
    public
    {
        multiboard Multiboards[];
        Multibar Multibars[12][4];
        integer LegionScore = 0;
        integer MoktalScore = 0;
        integer Minutes = 0;
        string GameMode = "";
        integer PlayerSlot[];
        constant string COLOR_STAT_TEXT = "828282";
    }
    
    private
    {
        constant integer BAR_SIZE = 4;
        
        constant string ICON_MAGIC = "ReplaceableTextures\\CommandButtons\\BTNMagic.blp";
        constant string ICON_MAGIC_DEFENSE = "ReplaceableTextures\\CommandButtons\\BTNMagicDefense.blp";
        constant string ICON_RESILIENCE = "ReplaceableTextures\\CommandButtons\\BTNResilience.blp";
        constant string ICON_MAGIC_CRIT_CHANCE = "ReplaceableTextures\\CommandButtons\\BTNMagicCrit.blp";
        constant string ICON_MAGIC_CRIT_POWER = "ReplaceableTextures\\CommandButtons\\BTNMagicCritPower.blp";
        constant string ICON_MELEE_CRIT_CHANCE = "ReplaceableTextures\\CommandButtons\\BTNMeleeCrit.blp";
        constant string ICON_MELEE_CRIT_POWER = "ReplaceableTextures\\CommandButtons\\BTNMeleeCritBonus.blp";
        constant string ICON_EVASION = "ReplaceableTextures\\CommandButtons\\BTNEvasion.blp";
    }

    
    function CreateBoard(integer x) -> multiboard
    {
        multiboard mb = CreateMultiboard();
        multiboarditem slot;
        unit hero = Heroes[x];
        integer row = 0;
        integer column = 0;
        integer z = 0;
        
        //General Data
        MultiboardSetRowCount(mb, 25);
        MultiboardSetColumnCount(mb, 7);
        MultiboardSetTitleText(mb, "|CffFFF68F[|r" + "|c00ff0303Legion|r" + "|CffFFF68F]:|r |CffFFF68F" + I2S(LegionScore) + "|r   |CffFFF68Fl   [|r|c0020c000Mok'tal|r|CffFFF68F]:|r |CffFFF68F" + I2S(MoktalScore) + "|r  |CffFFF68F-|r  |CffFFF68F" + I2S(Minutes) + "|r |CffFFF68Fmin.|r");
        MultiboardSetItemsStyle(mb, true, false);
        MultiboardSetItemsWidth(mb, .03);
        while (row <= 24)
        {
            slot = MultiboardGetItem(mb, row, column);
            MultiboardSetItemWidth(slot, .13);
            row = row + 1;
        }
        
        //Hero Data
        slot = MultiboardGetItem(mb, 0, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, GetPlayerName(Player(x)));
        MultiboardSetItemIcon(slot, HeroIcons[x]);
        
        slot = MultiboardGetItem(mb, 0, 1);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(1));
        
        slot = MultiboardGetItem(mb, 0, 3);
        if (GameMode != "") { MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + GameMode + "|r"); }
        else { MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "No Mode|r"); }
        MultiboardSetItemWidth(slot, .05);
        
        slot = MultiboardGetItem(mb, 0, 5);
        MultiboardSetItemWidth(slot, .07);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Stat Points:|r " + I2S(StatPoints[x]));
        
        //Hero Stats
        slot = MultiboardGetItem(mb, 2, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Magic:|r");
        MultiboardSetItemIcon(slot, ICON_MAGIC);
        slot = MultiboardGetItem(mb, 2, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetMagic(hero))));
        
        slot = MultiboardGetItem(mb, 3, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Magic Defense:|r");
        MultiboardSetItemIcon(slot, ICON_MAGIC_DEFENSE);
        slot = MultiboardGetItem(mb, 3, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetMagicDefense(hero))));
        
        slot = MultiboardGetItem(mb, 4, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Resilience:|r");
        MultiboardSetItemIcon(slot, ICON_RESILIENCE);
        slot = MultiboardGetItem(mb, 4, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetResilience(hero))) + "%");
        
        slot = MultiboardGetItem(mb, 5, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Magic Crit Chance:|r");
        MultiboardSetItemIcon(slot, ICON_MAGIC_CRIT_CHANCE);
        slot = MultiboardGetItem(mb, 5, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetMagicCritical(hero))) + "%");
        
        slot = MultiboardGetItem(mb, 6, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Magic Crit Power:|r");
        MultiboardSetItemIcon(slot, ICON_MAGIC_CRIT_POWER);
        slot = MultiboardGetItem(mb, 6, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I((GetMagicCriticalBonus(hero) - 1) * 100)) + "%");
        
        slot = MultiboardGetItem(mb, 7, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Melee Crit Chance:|r");
        MultiboardSetItemIcon(slot, ICON_MELEE_CRIT_CHANCE);
        slot = MultiboardGetItem(mb, 7, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetMeleeCritical(hero))) + "%");
        
        slot = MultiboardGetItem(mb, 8, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Melee Crit Power:|r");
        MultiboardSetItemIcon(slot, ICON_MELEE_CRIT_POWER);
        slot = MultiboardGetItem(mb, 8, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I((GetMeleeCriticalBonus(hero) - 1) * 100)) + "%");
        
        slot = MultiboardGetItem(mb, 9, 0);
        MultiboardSetItemStyle(slot, true, true);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Evasion:|r");
        MultiboardSetItemIcon(slot, ICON_EVASION);
        slot = MultiboardGetItem(mb, 9, 1);
        MultiboardSetItemWidth(slot, .04);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, I2S(R2I(GetEvasion(hero))) + "%");
        
        //Hero Bars
        slot = MultiboardGetItem(mb, 2, 3);
        MultiboardSetItemWidth(slot, .1);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Health:|r");
        Multibars[x][0] = Multibar.create(mb, 3, 3, BAR_SIZE, GetUnitState(hero, UNIT_STATE_MAX_LIFE), GetUnitState(hero, UNIT_STATE_LIFE), MULTIBAR_TYPE_HEALTH);
    
        slot = MultiboardGetItem(mb, 4, 3);
        MultiboardSetItemWidth(slot, .1);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Mana:|r");
        Multibars[x][1] = Multibar.create(mb, 3, 5, BAR_SIZE, GetUnitState(hero, UNIT_STATE_MAX_MANA), GetUnitState(hero, UNIT_STATE_MANA), MULTIBAR_TYPE_MANA);

        slot = MultiboardGetItem(mb, 6, 3);
        MultiboardSetItemWidth(slot, .1);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "Speed:|r");
        Multibars[x][2] = Multibar.create(mb, 3, 7, BAR_SIZE, 400, GetUnitMoveSpeed(hero), MULTIBAR_TYPE_EXPERIENCE);
        
        slot = MultiboardGetItem(mb, 8, 3);
        MultiboardSetItemWidth(slot, .1);
        MultiboardSetItemStyle(slot, true, false);
        MultiboardSetItemValue(slot, "|Cff" + COLOR_STAT_TEXT + "MP5:|r");
        Multibars[x][3] = Multibar.create(mb, 3, 9, BAR_SIZE, MAX_MP5, GetMP5(hero), MULTIBAR_TYPE_MP5);
        
        //Team Board
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 1), "|Cff" + COLOR_STAT_TEXT + "K|r");
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 2), "|Cff" + COLOR_STAT_TEXT + "D|r");
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 3), "|Cff" + COLOR_STAT_TEXT + "T|r");
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 4), "|Cff" + COLOR_STAT_TEXT + "LvL|r");
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 5), "|Cff" + COLOR_STAT_TEXT + "Ult|r");
        MultiboardSetItemWidth(MultiboardGetItem(mb, 11, 6), .5);
        MultiboardSetItemValue(MultiboardGetItem(mb, 11, 6), "|Cff" + COLOR_STAT_TEXT + "Respawn|r");
        
        row = 12;
        while ((row <= 24) && (z <= 11))
        {
            slot = MultiboardGetItem(mb, row, 0);
            if (z == 0)
            {
                MultiboardSetItemValue(slot, "|c00ff0303The Legion|r");
                PlayerSlot[z] = row;
                row = row + 1;
            }
            else if (z == 6)
            {
                row = row + 1;
                slot = MultiboardGetItem(mb, row, 0);
                MultiboardSetItemValue(slot, "|c0020c000The Mok'tal|r");
                PlayerSlot[z] = row;
                row = row + 1;
            }
            else if (Heroes[z] != null)
            {
                MultiboardSetItemStyle(slot, true, true);
                MultiboardSetItemIcon(slot, HeroIcons[z]);
                MultiboardSetItemValue(slot, GetPlayerName(Player(z)));
                PlayerSlot[z] = row;
                slot = MultiboardGetItem(mb, row, 4);
                MultiboardSetItemValue(slot, "1");
                row = row + 1;
            }
            z = z + 1;
        }
        
        MultiboardSetRowCount(mb, row);
        MultiboardDisplay(mb, false);
        return mb;
    }
    
    public function InitBoards()
    {
        integer x = 1;
        
        while (x <= 11)
        {
            if ((x != 6) && (Heroes[x] != null) && (GetPlayerController(Player(x)) != MAP_CONTROL_COMPUTER))
            {
                BJDebugMsg("Creating Multiboard For Player " + I2S(x));
                Multiboards[x] = CreateBoard(x);
            }
            x = x + 1;
        }
        
        x = 1;
        while (x <= 11)
        {
            if (Multiboards[x] != null)
            {
                if (GetPlayerId(GetLocalPlayer()) == x) { MultiboardDisplay(Multiboards[x], true); }
            }
        }
    }
}
//! endzinc
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Indeed, you're not incrementing "x" here:
JASS:
        x = 1;
        while (x <= 11)
        {
            if (Multiboards[x] != null)
            {
                if (GetPlayerId(GetLocalPlayer()) == x) { MultiboardDisplay(Multiboards[x], true); }
            }
        }
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
In fact you don't need the loop and check if a player slot is used by a player or not :

Thats is perfectly safe here, easier to use, and even more efficient :

JASS:
local integer id = GetPlayerId(GetLocalPlayer()) // ofc you can inline it , i did it for code readability
call MultiboardDisplay(Multiboards[ id ], true)

This code will run only on playing human computers.
 
Status
Not open for further replies.
Top