• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] "Reseting" a Timer instead of creating a new one

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
My last post title was a little vague and yielded results with no definite explanation for me to apply the answers to.

I'm doin this for a timer that detects when a unit is in battle by placing them in a group when they deal damage and then removes the unit from the group when it is no longer in battle.

Anyways, what I'm trying to do now is get the timer I create to be reset, instead of creating a new timer :X I don't know how to access the timer once it's created though, so I can't pause it.

Any tips, help or suggestions is appreciated.

A note I'm using a damage detection system that's custom. Don't mind it, I doubt it's impacting the timer and it's actions in a way that would solve this issue.

Here is the inBattle detection system:

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 9
Joined
Aug 21, 2008
Messages
533
i m not sure, but i dont think you could do this with local timers. And i dont think you want to use global ones.
i would not use timers for this.
What you may do:

YOu need a perodic trigger which triggers every 0.03.(you may do less, but this value is exact enough)

Everytime a unit attacks it added to the group and you save somehow(i would suggest via hashtable) 3.00. in case of hash: SaveReal(hashtable,KeyString"Inbattletime",KeyhandleId"yourUnit")

Now back to the trigger. everytime it triggers, it picks all units, load their inbattletime and reduce it by 0.03. If it is 0, the unit will be removed from the group.

Every time the unit attacks gain in this time, the inbattletime will be set to 3 again so its like you wanted it to be.

So no timers but still everything you want:thumbs_up: if you got confussed by what i have written, just ask and i take more time to write it more understandable:grin:
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
That's a pretty good idea. I think I might be able to use that. I suppose if it works I could try attaching a timer to a unit using a hashtable, then destroying that timer when a unit is hit and creating it again at 3.00. This would possibly work. I'd have to test it out first.

I was hoping to do it a little more efficiently, but it might work.
 
Status
Not open for further replies.
Top