• 🏆 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!

[Solved] How can i prevent same unit type for this system?

Status
Not open for further replies.
Level 17
Joined
Jun 2, 2009
Messages
1,141
Hello everyone. I have created AI system for my map and i can give them random heroes. But the problem is, they can pick the same heroes. How can i prevent this? Here is my system.

  • Events
    • Time - Elapsed game time is 2.00 seconds
  • Conditions
  • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Player((Integer A))) controller) Equal to Computer
            • BotHeroSecti[(Integer A)] Equal to False
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Player number of (Player((Integer A)))) Less than or equal to 6
              • Then - Actions
                • Set BotHeroSecti[(Integer A)] = True
                • Unit - Create 1 BotHerolar[(Random integer number between 1 and 54)] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
                • Set zU_AIHero[(Integer A)] = (Last created unit)
                • Unit Group - Add (Last created unit) to HerolarALL
                • Unit Group - Add (Last created unit) to HerolarDevilAll
                • Unit Group - Add (Last created unit) to HerolarBotALL
                • Unit Group - Add (Last created unit) to HerolarBotDevil
                • Player Group - Add (Player((Integer A))) to ClanDevilPlayers
                • Player Group - Add (Player((Integer A))) to ClanDevilBotlar
                • Player Group - Add (Player((Integer A))) to Botlar
                • Unit - Set the custom value of (Last created unit) to 0
                • Set HeroCountDevil = (HeroCountDevil + 1)
Here is the Hero list.

  • Unit - Create 1 BotHerolar[(Random integer number between 1 and 54)] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
I am also remove it from marketplaces. And i don't know how can i use remove from marketplaces action.

Players are selecting heroes from taverns by clicking
Bots are selecting heroes from random list.

1-) Remove selected hero from marketplaces
2-) Prevent bots to pick same heroes.
 

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
512
Here is a solution. It does not look pretty in GUI, but it should work. You create a loop, and have the script stuck in that loop until it finds a random number that hasn't been picked yet.

Add this block before the Create Unit line:

  • For each (Integer loopInt) from 0 to 1, do (Actions)
    • Loop - Actions
      • Set randomInt = (Random integer number between 1 and 54)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • heroIsChosen[randomInt] Equal to False
        • Then - Actions
          • Set loopInt = 1
        • Else - Actions
          • Set loopInt = 0
Replace the "Random integer number between 1 and 54" in the Create Unit line with your randomInt variable, then after that line add
  • Set heroIsChosen[randomInt] = True
and make sure to declare heroIsChosen as a boolean array with size 54.
 
Level 17
Joined
Jun 2, 2009
Messages
1,141
@Cyclotrutan Clever. But i am not familiar with this. Could you please tell me where do i put this? By the way i make it 15 for the testing purpose.

  • HeroSectirme
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • For each (Integer LoopInt) from 0 to 1, do (Actions)
        • Loop - Actions
          • Set randomInt = (Random integer number between 1 and 15)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HeroChoosen[randomInt] Equal to False
            • Then - Actions
              • Set LoopInt = 1
            • Else - Actions
              • Set LoopInt = 0
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to Computer
              • BotHeroSecti[(Integer A)] Equal to False
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player number of (Player((Integer A)))) Less than or equal to 6
                • Then - Actions
                  • Set BotHeroSecti[(Integer A)] = True
                  • Set Random_Hero = (Random integer number between 1 and MaxHeroesBot)
                  • Unit - Create 1 BotHerolar[(Random integer number between 1 and 3)] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
                  • Unit - Create 1 HeroTypes[Random_Hero] for (Player((Integer A))) at (Center of Region 099 <gen>) facing Default building facing degrees
                  • Neutral Building - Remove (Unit-type of (Last created unit)) from all marketplaces
                  • Set zU_AIHero[(Integer A)] = (Last created unit)
                  • Hero - Modify Strength of (Last created unit): Add 10
                  • Hero - Modify Agility of (Last created unit): Add 10
                  • Hero - Modify Intelligence of (Last created unit): Add 10
                  • Unit Group - Add (Last created unit) to HerolarALL
                  • Unit Group - Add (Last created unit) to HerolarDevilAll
                  • Unit Group - Add (Last created unit) to HerolarBotALL
                  • Unit Group - Add (Last created unit) to HerolarBotDevil
                  • Player Group - Add (Player((Integer A))) to ClanDevilPlayers
                  • Player Group - Add (Player((Integer A))) to ClanDevilBotlar
                  • Player Group - Add (Player((Integer A))) to Botlar
                  • Unit - Set the custom value of (Last created unit) to 0
                  • Set HeroCountDevil = (HeroCountDevil + 1)
                • Else - Actions
                  • Set BotHeroSecti[(Integer A)] = True
                  • Unit - Create 1 BotHerolar[(Random integer number between 1 and 3)] for (Player((Integer A))) at (Center of GameGuideReaper <gen>) facing Default building facing degrees
                  • Set zU_AIHero[(Integer A)] = (Last created unit)
                  • Hero - Modify Strength of (Last created unit): Add 10
                  • Hero - Modify Agility of (Last created unit): Add 10
                  • Hero - Modify Intelligence of (Last created unit): Add 10
                  • Unit Group - Add (Last created unit) to HerolarALL
                  • Unit Group - Add (Last created unit) to HerolarReaperALL
                  • Unit Group - Add (Last created unit) to HerolarBotALL
                  • Unit Group - Add (Last created unit) to HerolarBotReaperr
                  • Player Group - Add (Player((Integer A))) to ClanReaperPlayers
                  • Player Group - Add (Player((Integer A))) to ClanReaperBotlar
                  • Player Group - Add (Player((Integer A))) to Botlar
                  • Unit - Set the custom value of (Last created unit) to 0
                  • Set HeroCountReaper = (HeroCountReaper + 1)
            • Else - Actions
By the way i am also remove selected hero from taverns. Because many of my skills can be used only 1 hero.
 
Last edited:

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
512
Here you go:

  • Events
    • Time - Elapsed game time is 2.00 seconds
  • Conditions
  • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Player((Integer A))) controller) Equal to Computer
            • BotHeroSecti[(Integer A)] Equal to False
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Player number of (Player((Integer A)))) Less than or equal to 6
              • Then - Actions
                • For each (Integer loopInt) from 0 to 1, do (Actions)
                  • Loop - Actions
                    • Set randomInt = (Random integer number between 1 and 54)
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • heroIsChosen[randomInt] Equal to False
                      • Then - Actions
                        • Set loopInt = 1
                      • Else - Actions
                        • Set loopInt = 0
                • Set BotHeroSecti[(Integer A)] = True
                • Unit - Create 1 BotHerolar[randomInt] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
                • Set zU_AIHero[(Integer A)] = (Last created unit)
                • Set heroIsChosen[randomInt] = True
                • Unit Group - Add (Last created unit) to HerolarALL
                • Unit Group - Add (Last created unit) to HerolarDevilAll
                • Unit Group - Add (Last created unit) to HerolarBotALL
                • Unit Group - Add (Last created unit) to HerolarBotDevil
                • Player Group - Add (Player((Integer A))) to ClanDevilPlayers
                • Player Group - Add (Player((Integer A))) to ClanDevilBotlar
                • Player Group - Add (Player((Integer A))) to Botlar
                • Unit - Set the custom value of (Last created unit) to 0
                • Set HeroCountDevil = (HeroCountDevil + 1)
 
Level 17
Joined
Jun 2, 2009
Messages
1,141
Here you go:

  • Events
    • Time - Elapsed game time is 2.00 seconds
  • Conditions
  • Actions
    • For each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Player((Integer A))) controller) Equal to Computer
            • BotHeroSecti[(Integer A)] Equal to False
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Player number of (Player((Integer A)))) Less than or equal to 6
              • Then - Actions
                • For each (Integer loopInt) from 0 to 1, do (Actions)
                  • Loop - Actions
                    • Set randomInt = (Random integer number between 1 and 54)
                    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • heroIsChosen[randomInt] Equal to False
                      • Then - Actions
                        • Set loopInt = 1
                      • Else - Actions
                        • Set loopInt = 0
                • Set BotHeroSecti[(Integer A)] = True
                • Unit - Create 1 BotHerolar[randomInt] for (Player((Integer A))) at (Center of GameGuideDevil <gen>) facing Default building facing degrees
                • Set zU_AIHero[(Integer A)] = (Last created unit)
                • Set heroIsChosen[randomInt] = True
                • Unit Group - Add (Last created unit) to HerolarALL
                • Unit Group - Add (Last created unit) to HerolarDevilAll
                • Unit Group - Add (Last created unit) to HerolarBotALL
                • Unit Group - Add (Last created unit) to HerolarBotDevil
                • Player Group - Add (Player((Integer A))) to ClanDevilPlayers
                • Player Group - Add (Player((Integer A))) to ClanDevilBotlar
                • Player Group - Add (Player((Integer A))) to Botlar
                • Unit - Set the custom value of (Last created unit) to 0
                • Set HeroCountDevil = (HeroCountDevil + 1)
Thank you so much. Now i am going to test. Another question i have asked do you know how can i remove the selected hero from all taverns? Because AI and hero cannot pick the same hero. Is it gonna work or not, i will test it now.

  • Neutral Building - Remove BotHerolar[randomInt] from all marketplaces
 
Level 17
Joined
Jun 2, 2009
Messages
1,141
Does
  • Neutral Building - Remove (Unit-type of (Last created unit)) from all marketplaces
not work? I'm not that familiar with this function.
Sadly not worked. But i have a theory. I believe we should add this heroes via triggers into market places for the make it work. I will test it today and let you know the results.
Edit: No. I have never put heroes on marketplaces manually. But this trigger works?


  • Give Random Hero
    • Events
    • Conditions
    • Actions
      • -------- random hero --------
      • Set Random_Hero = (Random integer number between 1 and Total_Heroes)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HeroChoosen[Random_Hero] Equal to False
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Player number of Trig_Player) Less than or equal to 12
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player number of (Owner of (Triggering unit))) Less than or equal to 6
                • Then - Actions
                  • Unit - Create 1 HeroTypes[Random_Hero] for Trig_Player at (Trig_Player start location) facing Default building facing degrees
                  • Set HeroCountDevil = (HeroCountDevil + 1)
                • Else - Actions
                  • Unit - Create 1 HeroTypes[Random_Hero] for Trig_Player at (Trig_Player start location) facing Default building facing degrees
                  • Set HeroCountReaper = (PlayerCountReaper + 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • mod_sp Equal to True
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Trig_Player is in ClanDevilPlayers) Equal to True
                    • Then - Actions
                      • Unit - Move (Last created unit) instantly to (Center of Altars <gen>)
                      • Set HeroCountDevil = (HeroCountDevil + 1)
                    • Else - Actions
                      • Unit - Move (Last created unit) instantly to (Center of Altars <gen>)
                      • Set HeroCountReaper = (PlayerCountReaper + 1)
                • Else - Actions
              • Camera - Pan camera for (Triggering player) to (Position of Circle[(Player number of (Triggering player))]) over 0.90 seconds
              • Selection - Select (Last created unit) for (Owner of (Last created unit))
            • Else - Actions
              • Unit - Create 1 HeroTypes[Random_Hero] for Trig_Player at (Center of (Playable map area)) facing Default building facing degrees
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • mod_test Equal to False
            • Then - Actions
              • Player - Limit training of Heroes to 0 for Trig_Player
              • Neutral Building - Remove HeroTypes[Random_Hero] from all marketplaces
              • Player Group - Pick every player in (All players) and do (Actions)
                • Loop - Actions
                  • Player - Make HeroTypes[Random_Hero] Unavailable for training/construction by (Picked player)
            • Else - Actions
          • Set HeroChoosen[Random_Hero] = True
        • Else - Actions
          • Trigger - Run (This trigger) (checking conditions)
Now i will try this.

Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
Player - Make HeroTypes[Random_Hero] Unavailable for training/construction by (Picked player)

Update: YES IT SEEMS IT IS WORKING. I will reply this post when i verify 100%
 
Last edited:

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,890
The first solution posted isn't ideal. This one doesn't force unnecessary loops.
  • Trigger
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • -------- everything in your loop here before creating the unit. --------
          • Set VariableSet RandomInt = (Random integer number between 1 and MaxRandomHeroes)
          • Unit - Create 1 UnitType[RandomInt] for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
          • -------- same stuff as you have right now, then add this. --------
          • Set VariableSet UnitType[RandomInt] = UnitType[MaxRandomHeroes]
          • Set VariableSet MaxRandomHeroes = (MaxRandomHeroes - 1)
It simply removes the used unit type from the hero list.
 

Antares

Spell Reviewer
Level 21
Joined
Dec 13, 2009
Messages
512
The first solution posted isn't ideal. This one doesn't force unnecessary loops.
With "UnitType" variable being "BotHerolar". If that list can be rearranged without messing things up, your solution is better.
(I just copied my approach, for which the loop solution was easier. But it's probably not the case here.)
 
Level 39
Joined
Feb 27, 2007
Messages
5,022
The list cannot be rearranged like that without breaking some of JFAMAP’s multiboard functions in his map. There’s some icon and unit name arrays/functions being used in the map. At least as I understand it from the snippets I’ve seen. In the interest of not fucking with those arrays it's probably better to just brute force the randomization until all AI heroes are unique.
 
Last edited:
Status
Not open for further replies.
Top