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

Help with Hash!

Status
Not open for further replies.
Level 15
Joined
Aug 11, 2009
Messages
1,606
Ok,i have the following triggers in my map.I know it leaks,it is just fast made to see if it is working.I guess i do something wrong cause it doesn't work exactly as planned.Any suggestions?Here are the triggers:
  • BuffFelOrcTowers
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Effect_Hash = (Last created hashtable)
  • MSFelOrcTowers
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • ((Triggering unit) is A structure) Equal to True
                  • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
                  • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Human\MagicSentry\MagicSentryCaster.mdl
              • Hashtable - Save Handle Of(Last created special effect) as (Key (Last created special effect)) of (Key (Picked unit)) in Effect_Hash
            • Else - Actions
  • RemoveBuffTowers
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
      • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
      • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
    • Actions
      • Special Effect - Destroy (Load (Team number of Player 1 (Red)) of (Key (Picked unit)) in Effect_Hash)
      • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Effect_Hash
 
1. Two triggers have the Map Initialization event. Problem: the second depends on the first. Which of them happens first? You'd better make the first one run the second.

2. The second trigger uses (Triggering Unit) in its condition while no unit triggers the event. Therefore, (Triggering unit) == null.

3. Your use of hashtables makes no sense xD You should use keys that do not depend on the effect itself - your objective is to "get" it later, isn't it? So how are you going to get them if you actually "need" it to do so?

You could use the unit's key and then a number, meaning something like:
1 of unit = effect
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • Hashtable - Save Handle Of(Last created special effect) as (Key effect_1) of (Key (Picked unit)) in Effect_Hash
^Use "Hashtable - Get string ID" for effect_1

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • And - All (Conditions) are true
        • Conditions
          • ((Triggering unit) is A structure) Equal to True
          • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
          • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Triggering unit) is A structure) Equal to True
      • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
      • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
^Those work the same way, use the lower version.
 
Level 15
Joined
Aug 11, 2009
Messages
1,606
How about this?
  • BuffFelOrcTowers
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Effect_Hash = (Last created hashtable)
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to True
              • (Owner of (Picked unit)) Equal to Player 8 (Pink)
              • (Unit-type of (Picked unit)) Equal to Fel Orc Watch Tower
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Human\MagicSentry\MagicSentryCaster.mdl
              • Hashtable - Save Handle Of(Last created special effect) as (Key Effect1) of (Key (Picked unit)) in Effect_Hash
            • Else - Actions
  • RemoveBuffTowers
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A structure) Equal to True
      • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
      • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
    • Actions
      • Special Effect - Destroy (Load (Key Effect1) of (Key (Picked unit)) in Effect_Hash)
      • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Effect_Hash
Is this ok?
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
The hashtable usage looks ok.

  • Set Temp_Group = (Units within 128.00 of Temp_Loc_2 matching ((((Matching unit) is alive) Equal to True) and ((((Owner of (Matching unit)) is an enemy of (Owner of (Picked unit)...
I'd pick the group like this instead of usin if/then/else.

And the
  • ((Picked unit) is A structure) Equal to True
is redundant, since you have

  • (Unit-type of (Picked unit)) Equal to Fel Orc Watch Tower
 
Level 15
Joined
Aug 11, 2009
Messages
1,606
Ok,so this is the final trigger.
How about it?
  • BuffFelOrcTowers
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set Effect_Hash = (Last created hashtable)
      • Set BuffTGroup = (Units owned by Player 8 (Pink) of type Fel Orc Watch Tower)
      • Unit Group - Pick every unit in BuffTGroup and do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Human\MagicSentry\MagicSentryCaster.mdl
          • Hashtable - Save Handle Of(Last created special effect) as (Key Effect1) of (Key (Picked unit)) in Effect_Hash
          • Custom script: call DestroyGroup(udg_BuffTGroup)
  • RemoveBuffTowers
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 8 (Pink)
      • (Unit-type of (Triggering unit)) Equal to Fel Orc Watch Tower
    • Actions
      • Special Effect - Destroy (Load (Key Effect1) of (Key (Picked unit)) in Effect_Hash)
      • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Effect_Hash
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Move the custom script out of the loop.

  • Unit Group - Pick every unit in BuffTGroup and do (Actions)
    • Loop - Actions
      • Special Effect - Create a special effect attached to the overhead of (Picked unit) using Abilities\Spells\Human\MagicSentry\MagicSentryCaster.mdl
      • Hashtable - Save Handle Of(Last created special effect) as (Key Effect1) of (Key (Picked unit)) in Effect_Hash
    • Custom script: call DestroyGroup(udg_BuffTGroup)

Use triggering unit instead of picked unit, forgot to mention that earlier.
  • Actions
    • Special Effect - Destroy (Load (Key Effect1) of (Key (Triggering unit)) in Effect_Hash)
    • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in Effect_Hash
 
Status
Not open for further replies.
Top