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

Missile trigger - Only deal damag eto unit once

Status
Not open for further replies.
Level 7
Joined
Nov 19, 2015
Messages
283
So I have a missile system and I want to have a check that the unit that was damaged cannot be damaged again (only for certain missiles). Im using hashtables to store the missiles information.

I originally had unit groups but I want to make it MUI and thought of this

Hit = Hashtable - load boolean_hit of key(missile) of key(unit_hit)
If Hit = false then
deal damage
Hit = true
Save hit as key(missile) of key(unit_hit)

Firstly, does this work? Secondly I know there is probably a better way of doing this, so please advise me on a better method. I know clean up of the above idea is probs not easy.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Why does this sounds so familiar to me?
JASS:
        if HaveSavedHandle(udg_CMS_HASHTABLE, collidedId, missileId) then
            return false
        endif

There are two "real" ways of doing this.

1, Create a group for each missile and add the units to the group that are damaged.
To filter out the units that are damaged, you can check if they are inside the group.

2, Store a <anything> in a hashtable stored by the keys of the misile and the unit.
If the <anything> is in the hashtable, then the unit is already hit and thus may not be hit again.

In my missile system, I take it a step further.
I can create a duration of how long a unit cannot be hi by a missile after being hit by that missile.
So when the unit is hit, I store the timer in the hashtable and after <x> seconds, the value from the hashtable is cleared.

The cleanup is quite simple.
There is a method that clears a complete hashtable and a function that clears a complete column of a hashtable:
JASS:
native FlushParentHashtable takes hashtable table returns nothing
native FlushChildHashtable takes hashtable table, integer parentKey returns nothing

The first one is rarely used actually.
But the second one is the one that you need.
Inside the function where you destroy/remove the missile, you clear the column of the index of your missile.
That way, all the data will be successfully cleared.
(These functions also exist in GUI.)
 
Level 7
Joined
Nov 19, 2015
Messages
283
Sorry, I don't know any Jass. I know some basic custom script lines at most.
I really like the duration idea before it can be hit again. I wanted to do this but I thought it would end up creating too many timers.

Please correct me if I'm wrong.

Store boolean of key(missile_unit) of key(target_unit) in hashtable
If/then/else
Start timer [??]...

Timer[???] expires...
Clear child key(target_unit) in hastable

Im lost, how do I know which timer is what and when it expires.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well... why create it when I already did?
You can use mine if you really want that function, because to do that properly, you will have to write the system in JASS.

In GUI, you can just use the normal method I suppose.
Maybe even another periodic event to do the timer for this but I disrecommend that because of efficiency...

Just store the boolean in the hashtable and check if the boolean exists.
When you destroy the missile, you clear the hashtable's column that is used by that missile.

When you have learned some stuff about timers in JASS, then you could try to implement the cooldown feature but for now, I recommend you to make this work first.
 
Status
Not open for further replies.
Top