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

MUI using hashtables

Status
Not open for further replies.
Level 7
Joined
Nov 19, 2015
Messages
283
So far I have a missile system that uses hashtables.

This is what I want but I don't know the best way to go about doing it.

I want a unit to be only damaged every 0.25 seconds as long as they are within range of the missile. Perhaps check that the timer = 0 before dealing damage. However I need it to be able to take damage from other missiles as well. So I need a individual timer to keep track of every missile that hit the unit.
 
Level 7
Joined
Nov 19, 2015
Messages
283
Fortunately, hashtables have 2 indices. Save a real representing that 0.25 time for each unit handle (child key) around each missile (parent key). Flush that child hashtable once the missile is done.

Thats what I am currently doing. The problem that I have is decreasing the 0.25 real. I don't know how to get the child/parent key.

If I add the units hit into a unit group and decrease the real, I don't know how to get the parent key of the missile.

If I decrease the value in the movement trigger I have the parent key but I only have the child key when it hits but not at other times.

EDIT: NVM I got it however it looks really messy. Know any better ways of doing this?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I still have to optimize my method, but the best method I have found so far is storing a real representing the current moment of collision in the hashtable.

I start a timer that is saved under the index of both the target and the missile that runs for 0.25 seconds (configurable) and it destroys itself when it expires.
If the timer exists, then the unit should not be damaged (collided because fuck damage).


Then, whenever you collide the missile with that target again, you check if the difference between the current timestamp and the timestamp stored in the hashtable are different by 0.25 or more.

For this to work, you need a timer that runs the entire game.
In my BasicFunctions, I have such a timer:
JASS:
library TimeFunctions initializer BF_INIT_TimeFunctions
    
    globals
        timer GT_TIMER = CreateTimer()
        real GT_ELAPSED_TIME = 0
    endglobals
    //Return the current elapsed gametime.
    function GetElapsedGameTime takes nothing returns real
        return GT_ELAPSED_TIME + TimerGetElapsed(GT_TIMER)
    endfunction
    function GT_AddHour takes nothing returns nothing
        set GT_ELAPSED_TIME = GT_ELAPSED_TIME +3600.
    endfunction
    function BF_INIT_TimeFunctions takes nothing returns nothing
        call TimerStart(GT_TIMER, 3600, true, function GT_AddHour)
    endfunction
    
endlibrary

Calling the custom script "GetElapsedGameTime()" will return a real value accurate on 2 digits (dunno why but that seems to be timer stuff) which you can store in a real variable each iteration.
 
Level 7
Joined
Nov 19, 2015
Messages
283
Wow, thats a neat idea comparing time stamps. I could even just compare the expiration timer of the missile between hits and check if its greater than 0.25. I might use this idea for future spells. Seems easier than having so many timers going at once.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
That may not be such a good idea because you may want to have things that change the duration of a missile... right?

Timestamps are often very usefull tricks to do something extremely simple what would be a pain if you would do it on any other way.
Too few people use it though :/
 
Level 7
Joined
Nov 19, 2015
Messages
283
That may not be such a good idea because you may want to have things that change the duration of a missile... right?

Timestamps are often very usefull tricks to do something extremely simple what would be a pain if you would do it on any other way.
Too few people use it though :/

I don't have anything that changes the duration of the missile. I'm pretty sure you can even change the expiration timer, you can just pause/unpause. If you remove it, the unit dies (mirror image).
 
Status
Not open for further replies.
Top