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

Hashtable Test...

Status
Not open for further replies.
Level 29
Joined
Mar 10, 2009
Messages
5,016
Hello, I'm learning hastables, please could someone tell me if this is the correct setup/basics of a hashtable?...

I've tested it and it worked as a MUI spell...

One problem, if the unit cast it twice or more to the same unit, then it wont destroy the previous effect, so what went wrong?...

NOTE: dont mind the GAme Display coz its my way of testing things :)


  • ER
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Bloodlust (Neutral Hostile 1)
    • Actions
      • Game - Display to (All players) the text: TRIGGER ON
      • Trigger - Turn on Timer <gen>
      • Set HTInt = 5
      • Special Effect - Create a special effect attached to the overhead of (Target unit of ability being cast) using abilities\weapons\DemolisherMissile\DemolisherMissile.mdl
      • Hashtable - Save Handle Of(Last created special effect) as (Key Sfx) of (Key (Target unit of ability being cast)) in HT
      • Hashtable - Save HTInt as (Key Timer) of (Key (Target unit of ability being cast)) in HT
      • Unit Group - Add (Target unit of ability being cast) to Ugrp
  • Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Ugrp and do (Actions)
        • Loop - Actions
          • Set HTInt = (Load (Key Timer) of (Key (Picked unit)) from HT)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HTInt Greater than 0
            • Then - Actions
              • Hashtable - Save (HTInt - 1) as (Key Timer) of (Key (Picked unit)) in HT
              • Game - Display to (All players) the text: (String(HTInt))
            • Else - Actions
              • Special Effect - Destroy (Load (Key Sfx) of (Key (Picked unit)) in HT)
              • Unit Group - Remove (Picked unit) from Ugrp
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in HT
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ugrp is empty) Equal to True
        • Then - Actions
          • Game - Display to (All players) the text: TRIGGER OFF
          • Trigger - Turn off (This trigger)
        • Else - Actions
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
The caster's ID will not change.

First you set Sfx[X] (where X is the ID of the caster) to something, and before it could be destroyed you set Sfx[X] to another special effect.
The first effect is now lost in the nothingness of warcraft and can never be recalled.

To avoid this problem, you can do this:

- Create a dummy unit (no sight, no food cost, locust, no shadow, no model etc).
- Create that dummy unit once the spell is cast.
- Save ALL VALUES for the DUMMY unit, then save the caster as well (in the hashtable).
- When the spell is done, remove the dummy unit and clear the hashtable like usual.

Because the dummy will always have a different ID, the spell will always work (theoretically), no matter how many times you cast it at once.

I (jokingly) call this method MCI (Multi-cast Instanceable), because it can be cast as many times you want (while MUI makes sure every unit can cast it once, MCI makes sure every unit can cast it multiple times at the same time).

If you've got any problems implementing this, or feel there could be an easier method (or whatever is on your mind), don't hesitate to reply.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
tnx ap0, I'ts nice to have an answer from someone like you...yeah sometimes I use dummy units as the 'caster' itself but I did not thought of that matter using hashtables, lol!...

well, I will try you suggestion and i will post it here for the benefit of others who are learning as well...meanwhile have a +rep

EDIT:

btw, like I said, the spell i made will not work if cast on the same unit twice or more, but it works for different units even cast at the same time...
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Yes, I know :D (actually I was a bit mistaken, but the point is still the same).

It doesn't work on the same unit twice because the targeted unit's ID remains the same.
Creating a dummy will create a different ID every time you cast it, thus there can never be a mixup.
(By ID, I mean the thing you save as "Key of (Targeted unit)" by the way).


If you're not sure about what I mean with ID, or my solution doesn't seem to work, tell me ^^
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Or you could checks whether the effect handle exist in a hashtable, and then not create another effect, just refresh the timer on new cast. There's a boolean for the check. Boolean - handle exists or something like that.

The second trigger:
  • Timer
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Ugrp and do (Actions)
        • Loop - Actions
          • Set HTInt = (Load (Key Timer) of (Key (Picked unit)) from HT)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HTInt Greater than 0
            • Then - Actions
              • Hashtable - Save (HTInt - 1) as (Key Timer) of (Key (Picked unit)) in HT
              • Game - Display to (All players) the text: (String(HTInt))
            • Else - Actions
              • Special Effect - Destroy (Load (Key Sfx) of (Key (Picked unit)) in HT)
              • Unit Group - Remove (Picked unit) from Ugrp
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in HT
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Ugrp is empty) Equal to True
                • Then - Actions
                  • Game - Display to (All players) the text: TRIGGER OFF
                  • Trigger - Turn off (This trigger)
                • Else - Actions
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
@Maker

its the same patern as the #1 post and still it wont destroy the previous effect...

@Apo

I tried to save dummy unit based on thier custom values but still the same since the 'target' and the added to group
and picked unit is not the dummy unit, so it does not work...
or maybe I am missing something?

VIA...

  • Hashtable - Save Handle Of(Last created special effect) as (Key (Target unit of ability being cast)) of (Custom value of Dummy) in HT
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
@Maker

its the same patern as the #1 post and still it wont destroy the previous effect...

@Apo

I tried to save dummy unit based on thier custom values but still the same since the 'target' and the added to group
and picked unit is not the dummy unit, so it does not work...
or maybe I am missing something?

VIA...

  • Hashtable - Save Handle Of(Last created special effect) as (Key (Target unit of ability being cast)) of (Custom value of Dummy) in HT

Not custom value =___________=

Custom value is always 0 unless you set it otherwise.
Just use "Key of (last created unit)", where (last created unit) refers to the dummy you just created.
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
Tnx ap0, its OK now...Maker already solved this, now I learned more...I didnt know that there is a booelan to check if the said handle exist like Maker did...

2 more questions, anyone from both of you...

1. Do hashtables always need unit group, then remove the unit, then clear the child afterwards?...

2. Is this the same?

TRIGGER 1
  • Set HTInt = 5
  • Hashtable - Save HTInt as (Key Timer) of (Key (Target unit of ability being cast)) in HT
TRIGGER 2
  • Hashtable - Save 5 as (Key Timer) of (Key (Target unit of ability being cast)) in HT
the reason why I am asking #2 is that if they have the same function, then
there's no need to create a normal variable and store it 'AGAIN' in a hastable...


THANKS AGAIN IN ADVANCE!
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
1) Not necessarily, the unit group is just because one of the arrays of the hashtable is a unit ID (such as 'key of triggering unit') 'and to access those unit ID's, you loop through a unit group.
You always need to clear the hashtable at the end though.

2) Yup, it is.
If you use that variable a lot, you'd better turn it into a real variable (if it requires more mathematical functions it's easier), otherwise you can save it without creating a variable (like your second method).
I don't create variables for simple things like 0.00, triggering unit, 5, ... (I do however create an integer variable for the key of the triggering unit).
 
Status
Not open for further replies.
Top