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

[JASS] Stacking for in battle detection

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
Here is my current damage detection system:

http://www.wc3c.net/showpost.php?p=1024305&postcount=2

Right now what happens is if a unit recieves or deals damage, he will be place in a group for 3 seconds, then removed.

Only problem is, right now it doesn't stack. If the unit takes damage he's removed 3 seconds after the first initial damage, even if he's damaged 2 seconds later, he'll be removed from the group in 1 second.

I'm wondering how I can fix this. I haven't had to worry about stacking effects yet.

This is important since some of the AI I'm creating relies on inBattle detection, as well as the custom healing. It's obviously buggy without stacking.

Thanks :D

JASS:
scope InBattleDetector initializer Init 

globals
    group inBattle
endglobals

private struct Data

    unit c
    unit d

    static method create takes unit battler, unit hurtingbattler returns Data
     local Data D = Data.allocate()
      set D.c = battler
      set D.d = hurtingbattler
     return D
    endmethod
    
endstruct

private function Timer takes nothing returns nothing
 local timer tim = GetExpiredTimer()
 local Data D = Data(GetTimerData(tim))
    call GroupRemoveUnit(inBattle, D.c)
    call GroupRemoveUnit(inBattle, D.d)
 call ReleaseTimer(tim)
 call D.destroy()
endfunction

private function Conditions takes nothing returns boolean
    local timer tim = NewTimer()
    local real d = GetEventDamage()
    local Data D = Data.create(GetTriggerUnit(), GetEventDamageSource())
    set inBattle = CreateGroup()
    if d > 0 then
        call GroupAddUnit(inBattle, D.c)
        call GroupAddUnit(inBattle, D.d)
        call SetTimerData(tim,D)
        call TimerStart(tim, 3.0, false, function Timer)
    endif
    return false
endfunction

private function Init takes nothing returns nothing
    call AddDamageCondition(Condition(function Conditions))
endfunction

endscope
 
Level 7
Joined
Oct 14, 2008
Messages
340
I didn't look over everything completely, but maybe instead of making a new timer every time the unit takes damage, designate that unit a single timer, and reset it when he takes damage again.
 
Haven't tested it but you can try using these:
JASS:
native PauseTimer           takes timer whichTimer returns nothing
native TimerStart           takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing

Not really "resetting" it. But you know... =P Not sure if the timer will stay frozen or not if it gets started again.
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Well I was thinking that instead of doing a timer every time it recieves or deals damage, it'll place the unit in the group and pause the timer until the unit hasn't recieved damage for a while.

I'm not sure how to pause that specific timer though. Actually it's that I don't know how to call that timer back up when the unit gets hit and then tell it to pause. Any help or suggestions? I know there's a way to check if there's info on something, but I don't know the specifics. :\
 
Status
Not open for further replies.
Top