• 🏆 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] How to not random into same hero?

Status
Not open for further replies.
Level 3
Joined
Jun 17, 2015
Messages
53
I made the trigger to random all hero in my map (based on http://world-editor-tutorials.thehelper.net/herotavern.php

But somehow i dont know i gave me and my enemy same hero, but now i cant find the way to fix it, can anyone show me please :goblin_cry:


  • GP All Random
    • Events
      • Player - Player 2 (Blue) types a chat message containing -ar as An exact match
    • Conditions
    • Actions
      • Game - Display to (All players) the text: All Random
      • Set Total_Heroes = 29
      • Set Random_Count = 29
      • -------- HUMAN --------
      • Set Hero[1] = Barbarian
      • Set Hero[2] = Holy Order
      • Set Hero[3] = Paladin
      • Set Hero[4] = Viking Explorer
      • Set Hero[5] = Chancellor
      • Set Hero[6] = Demon Hunter
      • Set Hero[7] = Gryphon Rider
      • -------- ORC --------
      • Set Hero[8] = Beastmaster
      • Set Hero[9] = Brewmaster
      • Set Hero[10] = Tauren Chieftain
      • Set Hero[11] = Scorpion
      • Set Hero[12] = Shadow Hunter
      • Set Hero[13] = Warchief
      • Set Hero[14] = Engineer
      • Set Hero[15] = Hellfire Demon
      • Set Hero[16] = Sorcerer
      • -------- UNDEAD --------
      • Set Hero[17] = Fallen Infernal
      • Set Hero[18] = Infector
      • Set Hero[19] = Lich King
      • Set Hero[20] = Shadow Walker
      • Set Hero[21] = Archlich
      • Set Hero[22] = Flamefury
      • Set Hero[23] = Nerubian Overmind
      • -------- NIGHT ELF --------
      • Set Hero[24] = Bladewing
      • Set Hero[25] = Blind Hunter
      • Set Hero[26] = Elder Druid
      • Set Hero[27] = Unbroken Sage
      • Set Hero[28] = Vengeance
      • Set Hero[29] = Warden Spy
        • Do Multiple ActionsFor each (Integer A) from 1 to 29, do (Actions)
          • Loop - Actions
            • Set Random_Data[(Integer A)] = (Integer A)
      • -------- SETUP --------
      • Set AALoc1 = (Center of Tarven <gen>)
      • Player Group - Pick every player in (All players matching (((Matching player) slot status) Equal to (==) Is playing)) and do (Actions)
        • Loop - Actions
          • Set Random_Hero = (Random integer number between 1 and Random_Count)
          • Unit - Create 1 Hero[Random_Data[Random_Hero]] for (Picked player) at AALoc1 facing Default building facing (270.0) degrees
          • Player - Make (Unit-type of (Last created unit)) Unavailable for training/construction by (Picked player)
          • Set Random_Data[Random_Hero] = Random_Count
          • Set Random_Count = (Random_Count - 1)
      • Custom script: call RemoveLocation( udg_AALoc1 )
      • Trigger - Turn off (This trigger)
 
Level 26
Joined
Sep 26, 2009
Messages
2,427
Simple fix is to re-arrange the array containing all those hero types after choosing a hero.

What you will need are two integer variable, unit-type array and unit-type variable. I will call the first integer variable MaxHero and the other simply Index; the unit-type array will be called HeroesArray and the unit-type variable ChosenHero.
First, you initialize the MaxHero to the number of heroes in HeroesArray. Then in the cycle you set Index = random number between 1 and MaxHero. Next, you set ChoosenHero = HeroesArray[Index]. This way, you pick the random hero.

Now comes the important part. You swap the chosen hero with the last AVAILABLE hero in the HeroesArray. To do that, you set HeroesArray[Index] = HeroesArray[MaxHero] - this way, you placed last available hero in the place of the just chosen hero.
Next, you place the chosen hero where was the last availabe hero to complete the swapping process. If you remember, I saved that chosen hero in the ChosenHero variable. So HeroesArray[MaxHero] = ChosenHero.
However the amount of heroes is still the same (we just swapped chosen hero with last availabe hero). Since the chosen hero shall no longer be available, we simply decrease the value of MaxHero by 1 - hence MaxHero = MaxHero - 1. In next iteration of the cycle, you will choose from one less hero, since MaxHero will have value lower by 1 in comparison to the previous iteration of the cycle.
And that's it. You repeat this process in the cycle until you're happy or until you run out of avaiable heroes.

The code is in the hidden tab.
  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set HeroesArray[1] = Paladin
      • Set HeroesArray[2] = Archmage
      • ...
      • ...
      • ...
      • Set HeroesArray[10] = Blood Mage
      • Set MaxHero = 10
  • Loop
    • Events
    • Conditions
    • Actions
      • -------- Choose random 4 heroes out of those 10 --------
      • For each (Integer loop_var) from 1 to 4, do (Actions)
        • Loop - Actions
          • -------- Pick random hero --------
          • Set Index = (Random integer number between 1 and MaxHero)
          • Set ChosenHero = HeroesArray[Index]
          • -------- ---------------------------------------------------------------------------- --------
          • -------- Swap last available hero with the picked one --------
          • Set HeroesArray[Index] = HeroesArray[MaxHero]
          • Set HeroesArray[MaxHero] = ChosenHero
          • -------- ---------------------------------------------------------------------------- --------
          • -------- Decrease the amount of available heroes by 1 --------
          • Set MaxHero = (MaxHero - 1)
          • -------- ---------------------------------------------------------------------------- --------
          • -------- Here you can do whatever you want with your ChosenHero --------
 
Status
Not open for further replies.
Top