1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. The results are out! Check them out.
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Stacking for in battle detection

Discussion in 'Triggers & Scripts' started by Titanhex, Feb 18, 2010.

  1. Titanhex

    Titanhex

    Joined:
    Jul 26, 2008
    Messages:
    1,007
    Resources:
    2
    Maps:
    2
    Resources:
    2
    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

    inBattle
    Code (vJASS):
    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
     
  2. Maximilianx

    Maximilianx

    Joined:
    Oct 14, 2008
    Messages:
    334
    Resources:
    0
    Resources:
    0
    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.
     
  3. Titanhex

    Titanhex

    Joined:
    Jul 26, 2008
    Messages:
    1,007
    Resources:
    2
    Maps:
    2
    Resources:
    2
    The only thing is how do I resert timers?
     
  4. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Haven't tested it but you can try using these:
    Code (vJASS):
    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.
     
  5. Titanhex

    Titanhex

    Joined:
    Jul 26, 2008
    Messages:
    1,007
    Resources:
    2
    Maps:
    2
    Resources:
    2
    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. :\
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,034
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    You don't need to pausetimer to run the same timer. a single TimerStart will do the trick.
     
  7. Drenferalis

    Drenferalis

    Joined:
    Dec 30, 2009
    Messages:
    59
    Resources:
    0
    Resources:
    0
    For clarification will TimerStart() set the duration of the timer back, add to it, or continue using the old duration?
     
  8. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,427
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    It will set the duration of the timer to whatever you input as the timeout. It won't add or subtract. =)