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

[Trigger] Random Hero and All Random problems

Status
Not open for further replies.
Level 3
Joined
Jun 19, 2014
Messages
26
Hello again, I'm almost finishing the beta version of my simple hero arena and some problems appeared when I created the All Random mode and the Random command:

1st - The trigger has the chance to create two or more times the same hero.
2nd - The trigger has a small chance not to create a hero.
3rd - Lag issues with -ar (all random) command.

Here is the code:
  • Random
    • Events
      • Player - Player 1 (Red) types a chat message containing -random as An exact match
      • Player - Player 2 (Blue) types a chat message containing -random as An exact match
      • Player - Player 3 (Teal) types a chat message containing -random as An exact match
      • Player - Player 4 (Purple) types a chat message containing -random as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -random as An exact match
      • Player - Player 6 (Orange) types a chat message containing -random as An exact match
      • Player - Player 7 (Green) types a chat message containing -random as An exact match
      • Player - Player 8 (Pink) types a chat message containing -random as An exact match
      • Player - Player 9 (Gray) types a chat message containing -random as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -random as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -random as An exact match
      • Player - Player 12 (Brown) types a chat message containing -random as An exact match
    • Conditions
      • (Number of units in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True))) Equal to 0
    • Actions
      • Set Random_Hero = (Random integer number between 1 and Random_count)
      • Set TempInt = (Player number of (Triggering player))
      • Set Rd_Spawn = Reg_Spawn[TempInt]
      • Unit - Create 1 Hero_Array[Random_data[Random_Hero]] for (Triggering player) at (Center of Academia <gen>) facing Default building facing degrees
      • Game - Display to (All players) for 8.00 seconds the text: ((Name of (Triggering player)) + ( has randomed |CFFFFCC00 + (Name of (Last created unit))))
      • Player - Set name of (Triggering player) to ((Name of (Triggering player)) + (( + (Color_Array[TempInt] + ()) + ((Name of (Last created unit)) + )|r)))
      • Unit - Move (Last created unit) instantly to (Center of Rd_Spawn)
      • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 1.00 seconds
      • Selection - Select (Last created unit) for (Triggering player)
      • Hero - Create Health Potion and give it to (Last created unit)
      • Hero - Create Mana Potion and give it to (Last created unit)
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • 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)
Also, the -ar trigger, which is the basically the same as random but with the addition of a loop.
  • All Random
    • Events
      • Player - Player 1 (Red) types a chat message containing -ar as An exact match
    • Conditions
    • Actions
      • Trigger - Turn off Timer 1 <gen>
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) slot status) Equal to Is playing
            • Then - Actions
              • Set Random_Hero = (Random integer number between 1 and Random_count)
              • Set TempInt = (Player number of (Picked player))
              • Set Rd_Spawn = Reg_Spawn[TempInt]
              • Unit - Create 1 Hero_Array[Random_data[Random_Hero]] for (Picked player) at (Center of Academia <gen>) facing Default building facing degrees
              • Game - Display to (All players) for 8.00 seconds the text: ((Name of (Picked player)) + ( has randomed |CFFFFCC00 + (Name of (Last created unit))))
              • Player - Set name of (Picked player) to ((Name of (Picked player)) + (( + (Color_Array[TempInt] + ()) + ((Name of (Last created unit)) + )|r)))
              • Unit - Move (Last created unit) instantly to (Center of Rd_Spawn)
              • Camera - Pan camera for (Picked player) to (Position of (Last created unit)) over 1.00 seconds
              • Selection - Select (Last created unit) for (Picked player)
              • Hero - Create Health Potion and give it to (Last created unit)
              • Hero - Create Mana Potion and give it to (Last created unit)
              • Set Random_data[Random_Hero] = Random_count
              • Set Random_count = (Random_count - 1)
            • Else - Actions
      • Trigger - Turn off (This trigger)
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
For picking unique heroes:
Make an array of heroes and when you pick some hero, deindex that hero.

Code:
Hero[1] = Blademaster
Hero[2] = Death Knight
Hero[3] = Paladin
Hero[4] = Warden
Set MaxInt = 4 (the highest index used)
Pick random integer from 1 to MaxInt (in this case, from 1 to 4). Let's say you get integer 2. Then you spawn Hero[2] and deindex => You set Hero[2] = Hero[MaxInt] and decrease value of MaxInt by 1. You get this:
Code:
Hero[1] = Blademaster
Hero[2] = [s]Death Knight[/s] <-- [COLOR="Yellow"]Warden[/COLOR]
Hero[3] = Paladin
[s]Hero[4] = Warden[/s] (can no longer be accessed, as the index MaxInt got decreased)
Let's say you get integer 3. Then you spawn Hero[3], swap Hero[3] with Hero[maxInt] (which is number 3 as well, so nothing changes) and decrease value of MaxInt by 1. You'll end up with this list:
Code:
Hero[1] = Blademaster
Hero[2] = Warden
and so on.
 
Level 3
Joined
Jun 19, 2014
Messages
26
Well, I did this. But I made a mistake, forgive me please... I forgot to set the Hero_Array[3] so, I had a null value in the array...
 
Status
Not open for further replies.
Top