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

[Solved] Random Hero Trigger Leak

Level 6
Joined
Aug 24, 2022
Messages
85
Hi for you, that is reading me. I'm in doubt about my random choice trigger and I'd like some help. For now. it is like this:

  • Random Player 1
    • Events
      • Player - Player 1 (Red) types a chat message containing -random as An exact match
    • Conditions
    • Actions
      • Set VariableSet Temp_Char_Randomed = (Random integer number between 1 and 21)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random_Characters[Temp_Char_Randomed] Not equal to No unit-type
        • Then - Actions
          • Unit - Create 1 Random_Characters[Temp_Char_Randomed] for (Triggering player) at Hero_Spawn_Point facing Default building facing degrees
          • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 0.00 seconds
          • Game - Display to (All players) the text: (Player_Colors[(Player number of (Triggering player))] + ( has randomed the + Characters[Temp_Char_Randomed]))
          • Unit - Kill (Random unit from (Units in Players Souls <gen> owned by (Triggering player)))
          • Set VariableSet Random_Characters[Temp_Char_Randomed] = No unit-type
          • Set VariableSet Temp_Char_Randomed = 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Trigger - Run (This trigger) (checking conditions)

My doubt is: How can I erase a hero from his variable, when another player picks a hero at the tavern?

If I let the trigger as this, I can have a duplicated hero inside the game (Heroes are unique, so this is a leak). I didn't figure out yet, so here I am.

Why am I trying to do this?

All tests that I've runned along my project, at least one player tried to randomize his hero selection. So, I think it's something to insert in the project.
 
Level 20
Joined
Feb 27, 2019
Messages
593
This is a randomize system I have learned.

Init
Set Random_Characters[1] = Paladin
Set Random_Characters[2] = Blademaster
Set Random_Characters[3] = Demon Hunter
Set Random_Max = 3

Choose random
Set Random_Int = Random integer number between 1 and Random_Max
Set Random_Characters[0] = Random_Characters[Random_Max]
Set Random_Characters[Random_Max] = Random_Characters[Random_Int]
Set Random_Characters[Random_Int] = Random_Characters[0]
Set Random_Max = Random_Max - 1

The point is simply to switch places of [Random_Int] and [Random_Max] and reduce Random_Max by 1 so that the unit-type cant be randomized again.
 
Level 6
Joined
Aug 24, 2022
Messages
85
This is a randomize system I have learned.

Init
Set Random_Characters[1] = Paladin
Set Random_Characters[2] = Blademaster
Set Random_Characters[3] = Demon Hunter
Set Random_Max = 3

Choose random
Set Random_Int = Random integer number between 1 and Random_Max
Set Random_Characters[0] = Random_Characters[Random_Max]
Set Random_Characters[Random_Max] = Random_Characters[Random_Int]
Set Random_Characters[Random_Int] = Random_Characters[0]
Set Random_Max = Random_Max - 1

The point is simply to switch places of [Random_Int] and [Random_Max] and reduce Random_Max by 1 so that the unit-type cant be randomized again.
Well, I tried like this, as you showed me, but it didn't work. Probably I did something wrong... BUT, your trigger gave me the answer I was looking for. I didn't know that arrays could start at "0", and I saw that in your trigger, the array 0 has no value. Afterwards this, I remembered about the "Point Value" for units, and how we can use them. So, I've used the point value to link the unit type to its variable, defined at the map inicialization.

When a player tip "-random", we have this one, changed just a little:
  • Random Player 1
    • Events
      • Player - Player 1 (Red) types a chat message containing -random as An exact match
    • Conditions
    • Actions
      • Set VariableSet Temp_Char_Randomed = (Random integer number between 1 and 21)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Playable_Characters[Temp_Char_Randomed] Not equal to Playable_Characters[0]
        • Then - Actions
          • Unit - Create 1 Playable_Characters[Temp_Char_Randomed] for (Triggering player) at Hero_Spawn_Point facing Default building facing degrees
          • Neutral Building - Remove Playable_Characters[(Point-value of (Last created unit))] from all marketplaces
          • Camera - Pan camera for (Triggering player) to (Position of (Last created unit)) over 0.00 seconds
          • Game - Display to (All players) the text: (Player_Colors[(Player number of (Triggering player))] + ( has randomed the + Characters_Names[Temp_Char_Randomed]))
          • Unit - Kill (Random unit from (Units in Players Souls <gen> owned by (Triggering player)))
          • Set VariableSet Playable_Characters[Temp_Char_Randomed] = Playable_Characters[0]
          • Set VariableSet Temp_Char_Randomed = 0
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Trigger - Run (This trigger) (checking conditions)
I've tested this one until the random options end, and I've found an endless loop that ends the game. So, to counter it, just turn off the trigger for the player that tip "-random". I have one trigger of this one for each player.

Units get removed if they are choosen by the random trigger.

And what about the player who pick a hero from the tavern? Well, I did this:
  • Pick Hero
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • ((Sold unit) is A Hero) Equal to True
    • Actions
      • -------- This assumes that your map uses a Tavern to purchase your Hero. If not, you must modify the Event/Event Responses to work for your hero selection system! --------
      • Game - Display to (All players) the text: (Player_Colors[(Player number of (Owner of (Sold unit)))] + ( has choosen the + Characters_Names[(Point-value of (Sold unit))]))
      • Neutral Building - Remove (Unit-type of (Sold unit)) from (Selling unit)
      • Unit Group - Add (Sold unit) to Player_Hero_Group
      • Set VariableSet Player_Hero_Alive = (Player_Hero_Alive + 1)
      • Set VariableSet Playable_Characters[(Point-value of (Sold unit))] = Playable_Characters[0]
      • Camera - Pan camera for (Owner of (Buying unit)) to (Center of Hero Spawn <gen>) over 0.00 seconds
Using the trigger that was already here, I've just put the "variable set" to make the playable character be 0.

I'd like to thank you for the help. The system works very well for now. I just need to test it on multiplayer, but I think it works very well.
 
Level 25
Joined
Sep 26, 2009
Messages
2,381
Years ago I made a picture for someone to help me explain how to pick random region without picking same region repeatedly. You can use the same logic, except you don't have regions but heroes. It should also show you what you did wrong in your Random Player trigger.

1702208811616.png
 
Top