• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Another trigger question--

Status
Not open for further replies.
Level 1
Joined
Jun 1, 2014
Messages
3
I'm not sure triggers can handle this... thought I would ask.

What if I want to -- for example, every time a peasant is trained, to have the game randomly select one peasant model among three different possible choices of peasant models. Maybe one model has blonde hair, one has brown hair, and the other has red hair. So throughout the course of the game, you get some variety...


The math part seems easy enough -- I'm thinking I could generate a random number and then compare the random number's value to some number to determine the appropriate course of action to take.

What about actually loading the models -- do you think this is something that can it be done with triggers?
 
There are two ways you can actually do that.
a) Use a head attachment to attach the three different hair models. You can use the Sphere ability, set Attachment Points to Head and Number to 1. You can also use Special Effect - Create a special effect on unit.

b) You can have three models of the three different villagers. Create 1 unit for each villager.

Triggering part:

  • Map Initialization
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set Villagers[1] = Villager (Red)
    • Set Villagers[2] = Villager (Brown)
    • Set Villagers[3] = Villager (Blonde)
Villagers[] is a Unit-type variable with Array option ticked.

  • Change unit
  • Events
    • Unit - A unit finishes training a unit
  • Conditions
    • ((Trained unit) is A peon-type unit) Equal to True
  • Actions
    • Set Int = (Random integer between 1 and 3)
    • Unit - Replace (Trained unit) with a Villagers[Int] using the New unit's default life and mana
Condition is a boolean comparison "Unit - Unit classification check".

If you want special effects attached, I will show you both with the Sphere ability and the Special Effects trigger action.

  • Map Initialization
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Set Villagers[1] = Villager (Red)
    • Set Villagers[2] = Villager (Brown)
    • Set Villagers[3] = Villager (Blonde)
In this case, Villagers[] is an Ability variable, with Array option ticked.

  • Change unit
  • Events
    • Unit - A unit finishes training a unit
  • Conditions
    • ((Trained unit) is A peon-type unit) Equal to True
  • Actions
    • Set Int = (Random integer between 1 and 3)
    • Unit - Add Villagers[Int] to (Trained Unit)
Finally, by attaching special effect manually (a bit more complicated, as you need a hashtable or an array'd variable)

  • Map Initialization
  • Events
    • Map Initialization
  • Conditions
  • Actions
    • Custom script = set udg_HairHash = InitHashtable()
    • Set Villagers[1] = war3mapImported\RedHair.mdx
    • Set Villagers[2] = war3mapImported\BrownHair.mdx
    • Set Villagers[3] = war3mapImported\BlondeHair.mdx
In this case, Villagers[] is a string variable, with Array option ticked.

  • Change unit
  • Events
    • Unit - A unit finishes training a unit
  • Conditions
    • ((Trained unit) is A peon-type unit) Equal to True
  • Actions
    • Set Int = (Random integer between 1 and 3)
    • Special Effect - Create a special effect attached to the head of (Trained unit) using Villagers[Int]
    • Hashtable - Save Handle of (Last created special effect) as 0 of Key(Trained unit) in HairHash
You also need a third trigger in this case, to remove the special effect upon unit's death.

  • EffectRemoval
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Triggering unit) is A peon-type unit) Equal to True
  • Actions
    • Set Key = (Key(Triggering unit))
    • Special Effect - Destroy (Load 0 of Key) from HairHash
    • Hashtable - Clear all child hashtables of child Key in HairHash
Key is a Handle type of variable.
 
Level 1
Joined
Jun 1, 2014
Messages
3
Wow!! Much thanks Pharaoh -- this is especially useful.

I'm glad you are so knowledgeable about this subject, because I don't think I could have figured either of these solutions out on my own.

But the way you have explained it -- it all makes sense now...

Thanks again
 
Status
Not open for further replies.
Top