• 🏆 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] Using triggers to add special effects to units

Status
Not open for further replies.
Level 6
Joined
Feb 10, 2011
Messages
188
Hello I am creating a map and I want to make some cavemen like units, the way I intend to do this by importing a spear and some armor into my game and attaching it via triggers to the units when they are created, will this create a leak? if so how do i stop it

here is the trigger.

Code:
Untitled Trigger 001
    Events
        Unit - A unit Finishes training a unit
    Conditions
        (Unit-type of (Trained unit)) Equal to Peasant
    Actions
        Special Effect - Create a special effect attached to the lefthand of (Triggering unit) using Abilities\Spells\Other\TalkToMe\TalkToMe.mdl
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
It should not be leak, because you want those effects (weapons/armors, etc.) shown the whole time the unit is in game.

I'm not sure how WC3 handles effects attached to units, if it destroys them when the unit is removed from game or not. However to be perfectly sure, you can add each effect you make into a Hashtable. When caveman is created, attach armor/weapon to him and add those effects to hashtable. When caveman dies, load those effects from hashtable and destroy them.
You can use unit's handle ID as parent key and strings like "Armor" or "Weapon" as child keys for the effects.
 
Level 6
Joined
Feb 10, 2011
Messages
188
Ok this is my first time using hashtables, Im not really to sure how to tell if this is working. Can you tell me if its correct?
  • Weapons
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Unit-type of (Trained unit)) Equal to Neanderthal Axe
        • Then - Actions
          • Special Effect - Create a special effect attached to the right hand of (Trained unit) using war3mapImported\StoneAxe.mdx
          • Set hashStoneAxe = (Trained unit)
          • Hashtable - Save Handle OfhashStoneAxe as 1 of (Key (String((Unit-type of (Trained unit))))) in hashTable1
        • Else - Actions
  • Weapons Die
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in weaponsGroup) Equal to True
        • Then - Actions
          • Hashtable - Clear all child hashtables of child (Key (String((Unit-type of (Trained unit))))) in hashTable1
        • Else - Actions
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
No.
You have to save the special effect in the hashtable with key (unit) and key (pre-set-integer)
The pre-set-integer is a unique integer for each hashtable. You can set it to 0 for now.
Lets imagine that you want the units to have a spear and a shield and a helmet.
Then you have to save 3 special effects in the hashtable.
Because you cant save 3 special effects in one cell, and you dont want to create a new hashtable for every special effect, you make 3 integers that are unique to each other.
integer SpecialEffectSpear = 0
integer SpecialEffectShield = 1
integer SpecialEffectHelmet = 2

Now you can save special effects with key (unit) and one of those integers.
(This is very good to do when you have a WIP which uses a massive hashtable.)


So you do "Save (Last created special effect) in (hashtable) with key (handle id of (trained unit)) and key (SpecialEffectSpear)"

When the unit dies, you do this:
(Destroy Special Effect)
Destroy (Load Special Effect from (hashtable) with key (handle id of (triggering unit)) and key (SpecialEffectSpear))
Then you clear the hashtable cell.
 
Level 6
Joined
Feb 10, 2011
Messages
188
alright so i Just tried doing this im having trouble with 2 things first, when you do the handle ID of trained unit, how can I do this. I see it is done in tutorials to, but I do not see the options to pick trained unit.

on the death trigger u said do (Destroy Special Effect), how do i destroy the right special effect? cause i wouldn't be able to do last created.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
  • Custom script: set udg_id = GetHandleId(GetTriggerUnit())
  • Custom script: set udg_id = GetHandleId(GetTrainedUnit())
This sets into the integer variable 'id' the handle id of Triggering unit and Trained Unit.
You can use the variable 'id' as key to save or load the special effect.
 
Status
Not open for further replies.
Top