• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Problems with Randomizing Heroes

Status
Not open for further replies.
Level 18
Joined
Oct 17, 2012
Messages
824
The problem is that when I restart this trigger to give each player a new hero, some players may not get a hero.

  • Random Hero
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set RH_PlayerChooser[1] = Player 1 (Red)
      • Set RH_PlayerChooser[2] = Player 2 (Blue)
      • Set RH_PlayerChooser[3] = Player 3 (Teal)
      • Set RH_PlayerChooser[4] = Player 4 (Purple)
      • Set RH_PlayerChooser[5] = Player 5 (Yellow)
      • Set RH_PlayerChooser[6] = Player 6 (Orange)
      • Set RH_PlayerChooser[7] = Player 7 (Green)
      • Set RH_PlayerChooser[8] = Player 8 (Pink)
      • Set RH_PlayerChooser[9] = Player 9 (Gray)
      • Set RH_PlayerChooser[10] = Player 10 (Light Blue)
      • Set RH_PlayerChooser[11] = Player 11 (Dark Green)
      • Set RH_PlayerChooser[12] = Player 12 (Brown)
        • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 1 to 6, do (Actions)
          • Loop - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (RH_PlayerChooser[RH_PlayerNumber] slot status) Equal to (==) Is playing
              • Then - Actions
                • Player Group - Add RH_PlayerChooser[RH_PlayerNumber] to DS_Team
              • Else - Actions
        • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 7 to 12, do (Actions)
          • Loop - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (RH_PlayerChooser[RH_PlayerNumber] slot status) Equal to (==) Is playing
              • Then - Actions
                • Player Group - Add RH_PlayerChooser[RH_PlayerNumber] to DS_Team2
              • Else - Actions
      • Player Group - Make DS_Team treat DS_Team as an Ally with shared vision
      • Player Group - Make DS_Team2 treat DS_Team2 as an Ally with shared vision
      • -------- Heroes --------
      • Set RH_Hero[1] = Warden 0005 <gen>
      • Set RH_Hero[2] = Blood Mage 0012 <gen>
      • Set RH_Hero[3] = Demon Hunter 0002 <gen>
      • Set RH_Hero[4] = Sylvanas Windrunner 0001 <gen>
      • Set RH_Hero[5] = Archmage 0004 <gen>
      • Set RH_Hero[6] = Keeper of the Grove 0003 <gen>
      • Set RH_Hero[7] = Mountain King 0013 <gen>
      • Set RH_Hero[8] = Paladin 0006 <gen>
      • Set RH_Hero[9] = Blademaster 0014 <gen>
      • Set RH_Hero[10] = Shadow Hunter 0015 <gen>
      • Set RH_Hero[11] = Lich 0016 <gen>
      • Set RH_Hero[12] = Crypt Lord 0017 <gen>
      • Set RH_Hero[13] = Dreadlord 0024 <gen>
      • Set RH_Hero[14] = Chen Stormstout 0025 <gen>
      • Set RH_Hero[15] = Rexxar 0026 <gen>
      • Set RH_Int = 15
        • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 1 to 12, do (Actions)
          • Loop - Actions
            • Set RH_RandomInt = (Random integer number between 1 and RH_Int)
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • DS_Hero[RH_PlayerNumber] Not equal to (!=) No unit
                • Then - Actions
                  • Unit - Change ownership of DS_Hero[RH_PlayerNumber] to Neutral Passive and Change color
                  • Set DS_Hero[RH_PlayerNumber] = No unit
                • Else - Actions
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (RH_PlayerChooser[RH_PlayerNumber] slot status) Equal to (==) Is playing
                • Then - Actions
                  • Set DS_Hero[RH_PlayerNumber] = RH_Hero[RH_RandomInt]
                  • Unit - Change ownership of DS_Hero[RH_PlayerNumber] to RH_PlayerChooser[RH_PlayerNumber] and Change color
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (RH_PlayerChooser[RH_PlayerNumber] is in DS_Team) Equal to (==) True
                      • Then - Actions
                        • Set RH_StartingLocation = (Random point in StartingArea <gen>)
                        • Unit - Move DS_Hero[RH_PlayerNumber] instantly to RH_StartingLocation
                        • Camera - Pan camera for Player 1 (Red) to RH_StartingLocation over 0.00 seconds
                        • Custom script: call RemoveLocation(udg_RH_StartingLocation)
                      • Else - Actions
                        • Set RH_StartingLocation2 = (Random point in StartingArea Copy <gen>)
                        • Unit - Move DS_Hero[RH_PlayerNumber] instantly to RH_StartingLocation2
                        • Camera - Pan camera for Player 1 (Red) to RH_StartingLocation2 over 0.00 seconds
                        • Custom script: call RemoveLocation(udg_RH_StartingLocation2)
                • Else - Actions
            • Set RH_Hero[RH_RandomInt] = RH_Hero[RH_Int]
            • Set RH_Int = (RH_Int - 1)
 
Level 18
Joined
Oct 17, 2012
Messages
824
Well, I already found a solution, though it is similar to your suggestion. Thanks for the advice, anyway.

Here's what I found out:

When I change ownership of the previous hero to neutral passive, so that players do not get more than one hero, right before I give them a new hero, bugs, such as the overwriting of heroes, pop out.

However, when I change ownership of all previously used heroes at once in another trigger, bugs do not appear.

  • Random Hero
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set RH_Player[1] = Player 1 (Red)
      • Set RH_Player[2] = Player 2 (Blue)
      • Set RH_Player[3] = Player 3 (Teal)
      • Set RH_Player[4] = Player 4 (Purple)
      • Set RH_Player[5] = Player 5 (Yellow)
      • Set RH_Player[6] = Player 6 (Orange)
      • Set RH_Player[7] = Player 7 (Green)
      • Set RH_Player[8] = Player 8 (Pink)
      • Set RH_Player[9] = Player 9 (Gray)
      • Set RH_Player[10] = Player 10 (Light Blue)
      • Set RH_Player[11] = Player 11 (Dark Green)
      • Set RH_Player[12] = Player 12 (Brown)
      • -------- Heroes --------
      • Set RH_Hero[1] = Warden 0005 <gen>
      • Set RH_Hero[2] = Blood Mage 0012 <gen>
      • Set RH_Hero[3] = Demon Hunter 0002 <gen>
      • Set RH_Hero[4] = Sylvanas Windrunner 0001 <gen>
      • Set RH_Hero[5] = Archmage 0004 <gen>
      • Set RH_Hero[6] = Keeper of the Grove 0003 <gen>
      • Set RH_Hero[7] = Mountain King 0013 <gen>
      • Set RH_Hero[8] = Paladin 0006 <gen>
      • Set RH_Hero[9] = Blademaster 0014 <gen>
      • Set RH_Hero[10] = Shadow Hunter 0015 <gen>
      • Set RH_Hero[11] = Lich 0016 <gen>
      • Set RH_Hero[12] = Crypt Lord 0017 <gen>
      • Set RH_Hero[13] = Dreadlord 0024 <gen>
      • Set RH_Hero[14] = Chen Stormstout 0025 <gen>
      • Set RH_Hero[15] = Rexxar 0026 <gen>
      • Set RH_Int = 15
        • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 1 to 6, do (Actions)
          • Loop - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (RH_Player[RH_PlayerNumber] slot status) Equal to (==) Is playing
              • Then - Actions
                • Player Group - Add RH_Player[RH_PlayerNumber] to DS_Team
                • Set RH_RandomInt = (Random integer number between 1 and RH_Int)
                • Set DS_Hero[RH_PlayerNumber] = RH_Hero[RH_RandomInt]
                • Unit - Change ownership of DS_Hero[RH_PlayerNumber] to RH_Player[RH_PlayerNumber] and Change color
                • Set RH_StartingLocation = (Random point in StartingArea <gen>)
                • Unit - Move DS_Hero[RH_PlayerNumber] instantly to RH_StartingLocation
                • Camera - Pan camera for Player 1 (Red) to RH_StartingLocation over 0.00 seconds
                • Custom script: call RemoveLocation(udg_RH_StartingLocation)
                • Set RH_Hero[RH_RandomInt] = RH_Hero[RH_Int]
                • Set RH_Int = (RH_Int - 1)
              • Else - Actions
        • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 7 to 12, do (Actions)
          • Loop - Actions
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (RH_Player[RH_PlayerNumber] slot status) Equal to (==) Is playing
              • Then - Actions
                • Player Group - Add RH_Player[RH_PlayerNumber] to DS_Team2
                • Set RH_RandomInt = (Random integer number between 1 and RH_Int)
                • Set DS_Hero[RH_PlayerNumber] = RH_Hero[RH_RandomInt]
                • Unit - Change ownership of DS_Hero[RH_PlayerNumber] to RH_Player[RH_PlayerNumber] and Change color
                • Set RH_StartingLocation2 = (Random point in StartingArea Copy <gen>)
                • Unit - Move DS_Hero[RH_PlayerNumber] instantly to RH_StartingLocation2
                • Camera - Pan camera for Player 1 (Red) to RH_StartingLocation2 over 0.00 seconds
                • Custom script: call RemoveLocation(udg_RH_StartingLocation2)
                • Set RH_Hero[RH_RandomInt] = RH_Hero[RH_Int]
                • Set RH_Int = (RH_Int - 1)
              • Else - Actions
      • Player Group - Make DS_Team treat DS_Team as an Ally with shared vision
      • Player Group - Make DS_Team2 treat DS_Team2 as an Ally with shared vision
  • Restart
    • Events
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer RH_PlayerNumber) from 1 to 12, do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (RH_Player[RH_PlayerNumber] slot status) Equal to (==) Is playing
            • Then - Actions
              • Set RH_StartingLocation = (Random point in Hero Pick Location <gen>)
              • Unit - Change ownership of DS_Hero[RH_PlayerNumber] to Neutral Passive and Change color
              • Unit - Move DS_Hero[RH_PlayerNumber] instantly to RH_StartingLocation
              • Set DS_Hero[RH_PlayerNumber] = No unit
              • Custom script: call RemoveLocation(udg_RH_StartingLocation)
            • Else - Actions
      • Wait 5.00 seconds
      • Trigger - Run Random Hero <gen> (ignoring conditions)
 
Status
Not open for further replies.
Top