1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Math problem regarding Multiboard

Discussion in 'Triggers & Scripts' started by Saishy, Feb 14, 2009.

  1. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    I was trying to make my multiboard show the kills and things like that, but I forgot to set a variable to what row is each player...

    So I went to my multiboard trigger and start thinking....
    But... I can't... I can't think a way to get something like

    Multiboard_Spot[PlayerNumber] = RowX

    The maim problem is that the players might not be like: 1, 2, 3, 4. They could be 1, 4, 5, 7, 8...
    Edit: Now I also see that if player 3 is not playing and player 5 is, the game will crash...

    And in my game Team 1 is: 1, 3, 5, 7, 9, 11
    Team 2: 2, 4, 6, 8, 10, 12

    Any help is appreciate!

    • Multiboard
      • Events
        • Time - Elapsed game time is 16.00 seconds
      • Conditions
      • Actions
        • Set Player_Count_team1 = (Number of players in (All players matching ((((Matching player) controller) Equal to User) and ((((Matching player) slot status) Equal to Is playing) and (((Matching player) is an ally of Player 1 (Red)) Equal to True)))))
        • Set Player_Count_team2 = (Number of players in (All players matching ((((Matching player) controller) Equal to User) and ((((Matching player) slot status) Equal to Is playing) and (((Matching player) is an ally of Player 2 (Blue)) Equal to True)))))
        • Multiboard - Create a multiboard with 5 columns and (5 + (Player_Count_team1 + Player_Count_team2)) rows, titled Anime Brawl
        • Multiboard - Set the text for (Last created multiboard) item in column 3, row 1 to (|cffff0000 + (Kill_Name + |r))
        • Multiboard - Set the text for (Last created multiboard) item in column 4, row 1 to (|cff0000ff + (Death_Name + |r))
        • Multiboard - Set the text for (Last created multiboard) item in column 5, row 1 to (|CFF949694 + (Assist_Name + |r))
        • Multiboard - Set the text for (Last created multiboard) item in column 1, row 2 to Team 1
        • Multiboard - Set the text for (Last created multiboard) item in column 1, row (3 + Player_Count_team1) to Team 2
        • Multiboard - Set the text for (Last created multiboard) item in column 1, row (4 + (Player_Count_team1 + Player_Count_team2)) to Time
        • Multiboard - Set the text for (Last created multiboard) item in column 1, row (5 + (Player_Count_team1 + Player_Count_team2)) to Game Mode
        • Multiboard - Set the text for (Last created multiboard) item in column 2, row (5 + (Player_Count_team1 + Player_Count_team2)) to Game_Mode
        • Multiboard - Set the text for (Last created multiboard) item in column 3, row (5 + (Player_Count_team1 + Player_Count_team2)) to (String(Game_Mode_Int))
        • Multiboard - Set the display style for (Last created multiboard) item in column 1, row 2 to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 1, row (3 + Player_Count_team1) to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 1, row (4 + (Player_Count_team1 + Player_Count_team2)) to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 1, row (5 + (Player_Count_team1 + Player_Count_team2)) to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 1, row 1 to Hide text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 2, row 1 to Hide text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 2, row 0 to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 3, row 0 to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 4, row 0 to Show text and Hide icons
        • Multiboard - Set the display style for (Last created multiboard) item in column 5, row 0 to Show text and Hide icons
        • Multiboard - Set the width for (Last created multiboard) item in column 1, row 0 to 8.00% of the total screen width
        • Multiboard - Set the width for (Last created multiboard) item in column 2, row 0 to 3.00% of the total screen width
        • Multiboard - Set the width for (Last created multiboard) item in column 3, row 0 to 3.20% of the total screen width
        • Multiboard - Set the width for (Last created multiboard) item in column 4, row 0 to 4.00% of the total screen width
        • Multiboard - Set the width for (Last created multiboard) item in column 5, row 0 to 3.50% of the total screen width
        • For each (Integer A) from 1 to Player_Count_team1, do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Player_Count_team1 Greater than or equal to 1
              • Then - Actions
                • Multiboard - Set the text for (Last created multiboard) item in column 1, row ((Integer A) + 2) to (Player_Colors[((2 x (Integer A)) - 1)] + ((Name of (Player(((2 x (Integer A)) - 1)))) + |r))
              • Else - Actions
        • For each (Integer B) from 1 to Player_Count_team2, do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Player_Count_team2 Greater than or equal to 1
              • Then - Actions
                • Multiboard - Set the text for (Last created multiboard) item in column 1, row ((Integer B) + (3 + Player_Count_team1)) to (Player_Colors[((Integer B) x 2)] + ((Name of (Player(((Integer B) x 2)))) + |r))
              • Else - Actions
        • Multiboard - Show (Last created multiboard)
     
  2. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    Honestly, you'd be better off doing this in JASS, each time you access a slot (row & column) on a Multiboard it creates a leak, that needs to be cleaned up.

    It uses MultiboardGetItem(multiboard, row, column) to get a slot, which returns a multiboarditem type variable, that allows access to a given slot. These multiboarditem variables aren't automatically cleaned by Wc3, so you have to manually do it... hence, JASS would be best for this.

    I could write a trigger for you, but you'd have to wait a couple of days for it, the real world beckons :p
     
  3. Mannoroth

    Mannoroth

    Joined:
    Nov 23, 2007
    Messages:
    113
    Resources:
    0
    Resources:
    0
    Not sure if you figured this out yet but you might consider something like this.

    As Lord_Bones points out this is much easier in Jass. I don't really work with the trigger editor so hopefully you can just convert this over or just copy it to your main map script and create the variables for it and use it. Just as a side note, this would be a lot less code in vJass if you are thinking of working you way through Jass.

    Anyway, you can create the following global variables (I've tried to use the names the GUI creates so you can copy the code if you want).


    Code (vJASS):
    integer         array   udg_mbPlayerRows
    integer         array udg_mbTeamRows
    integer         array udg_mbTeams
    integer         array udg_mbTeamPlayerCount
    integer         array udg_mbPlayers

    integer         udg_mbTeamCount         = 0


    Then use something like the following code:
    Code (vJASS):

    //===========================================================================
    function IsPlaying takes integer whichPlayer returns boolean
       return (GetPlayerSlotState(Player(whichPlayer)) == PLAYER_SLOT_STATE_PLAYING)
    endfunction

    //===========================================================================
    function MbSetItemVal takes multiboard mb, integer row, integer col, string val returns nothing
       local multiboarditem mbitem = MultiboardGetItem(mb, row, col)
       call MultiboardSetItemValue(mbitem, val)
       call MultiboardReleaseItem(mbitem)
       set mbitem = null
    endfunction

    //===========================================================================
    // Draws the multiboard team/player titles and stores the rows at which they
    // were displayed
    //===========================================================================
    function MbSetPlayerRows takes nothing returns integer
       local integer     teamIndex
       local integer     playerIndex
       local integer     playerCount
       local integer     row
       local integer     arrayOffset

       set udg_mbTeamCount = 0
       set teamIndex = 0
       // start team/player row just below first title row
       set row = 1
       loop
          exitwhen teamIndex >= 12
          set playerIndex = 0
          set playerCount = 0
          set arrayOffset = teamIndex * 12
          loop
             exitwhen playerIndex >= 12
             if ( IsPlaying(playerIndex) ) then
                if ( GetPlayerTeam(Player(playerIndex)) == teamIndex ) then
                   if ( playerCount == 0 ) then
                      // current team has at least 1 player - add to udg_mbTeams array
                      // Save team index in sequencial order
                      set udg_mbTeams[udg_mbTeamCount] = teamIndex
                      // Save team row
                      set udg_mbTeamRows[teamIndex]    = row
                      set udg_mbTeamCount = udg_mbTeamCount + 1
                      // row reserved for team name, start players of team on next row
                      set row = row + 1
                   endif
                   // Save player index in sequential order for his team
                   set udg_mbPlayers[arrayOffset + playerCount] = playerIndex
                   // add player row to array, offest by team index
                   set udg_mbPlayerRows[playerIndex] = row
                   set row = row + 1
                   set playerCount = playerCount + 1
                endif
             endif
             set playerIndex = playerIndex + 1
          endloop
          if ( playerCount > 0 ) then
             set udg_mbTeamPlayerCount[teamIndex] = playerCount
          endif
          set teamIndex = teamIndex + 1
       endloop
       // return rowcount for multiboard SetRowCount()
       return row
    endfunction

    //===========================================================================
    function MbDrawPlayerTitles takes multiboard mb returns nothing
       local integer              t = 0
       local integer              p
       local integer              teamIndex
       local integer              playerIndex

       loop
         
          exitwhen t >= udg_mbTeamCount
         
           set teamIndex = udg_mbTeams[t]
          call MbSetItemVal(mb, udg_mbTeamRows[teamIndex], 0, "Team " + I2S(teamIndex+1))
    //    call BJDebugMsg("Team " + I2S(teamIndex+1))
          set p = 0
         
          loop
             exitwhen p >= udg_mbTeamPlayerCount[teamIndex]
             
             set playerIndex = udg_mbPlayers[teamIndex * 12 + p]
    //       call BJDebugMsg(GetPlayerName(Player(playerIndex)))
             call MbSetItemVal(mb, udg_mbPlayerRows[playerIndex], 0, GetPlayerName(Player(playerIndex)))
             set p = p + 1
             
          endloop
          set t = t + 1
       
       endloop
    endfunction

    //===========================================================================
    function MbGetPlayerRow takes player p returns integer
       return udg_mbPlayerRows[GetPlayerId(p)]
    endfunction

    //===========================================================================
    function MbGetPlayerTeamRow takes player p returns integer
       return udg_mbTeamRows[GetPlayerTeam(p)]
    endfunction

     


    You can then call the MbSetPlayerRows() function prior to setting up your multiboard, use MbDrawPlayerTitles() to draw the team/player titles, then the last two functions to obtain the team/player rows to display data.

    Hope that helps (I know it ain't pretty but I only had time to plug something here to hopefully get you started).

    Edit: Sorry, I can't get the jass code to line up with either tabs or spaces so some of it is out of whack. :/
     
  4. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    I already did a jass trigger to set each player slot.

    Thanks anyway.