Detect Units In Range

zepho

New Member
Hey I've been wondering how to create the trigger where a dummy unit is created then by timers , periodically checks (using GroupEnumUnitsInRange function) units around the dummy then damages them by a certain amount. This check will not end until the dummy unit is dead. (let's say dummy unit has HP)

A trigger sample would be very much appreciated :)

Thanks in advance.
 

PurgeandFire

zxcvmkgdfg
In vJASS? Something like the following. Just note that I wrote this without compiling it, so there may be slight errors. It requires TimerUtils:
JASS:
scope DamageDummy
 
    globals
         private constant integer RAWCODE = 'A000'
         private constant integer DUMMY_RAWCODE = 'n000'
         private constant real RADIUS = 500
         private constant real DAMAGE = 30
         private constant real PERIOD = 0.5
 
         private group g = CreateGroup()
         private unit temp = null
    endglobals
 
    private struct DamageDummy
        unit caster
        unit dummy
 
        static method enum takes nothing returns boolean
             if IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(temp)) then
                 call UnitDamageTarget(temp, GetFilterUnit(), DAMAGE, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
                 /* if the unit is an enemy, damage him */
             endif
             return false
        endmethod
 
        static method onExpire takes nothing returns nothing
             local thistype this = GetTimerData(GetExpiredTimer())
             /* this is how you retrieve the data ^ */
             set temp = this.dummy
             /* use a temporary variable if you are grouping if you need to check something */
             /* in our case, we have to check if the grouped unit is an enemy */
             if GetWidgetLife(temp) > 0.405 then /* check if alive */
                 call GroupEnumUnitsInRange(g, RADIUS, GetUnitX(temp), GetUnitY(temp), Condition(function thistype.enum))
             else
                  /* if he is dead, release the timer (recycle) and destroy the instance */
                  call ReleaseTimer(GetExpiredTimer())
                  call this.destroy()
             endif
        endmethod
 
        static method onSpellEffect takes nothing returns boolean
            local thistype this 
            if GetSpellAbilityId() == RAWCODE then /* check if the spell = that spell */
                set this = thistype.allocate()
                set this.caster = GetTriggerUnit()
                set this.dummy = CreateUnit(GetTriggerPlayer(), DUMMY_RAWCODE, GetUnitX(this.caster), GetUnitY(this.caster), 270)
                /* create the dummy at the caster location */
                call TimerStart(NewTimer(this), PERIOD, true, function thistype.onExpire) 
                /* NewTimer(this) will attach the data to the timer (TimerUtils) */
            endif
            return false
        endmethod
 
        private static method onInit takes nothing returns nothing
            local trigger t = CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
            /* register when the spell is cast */
            call TriggerAddCondition(t, Condition(function thistype.onSpellEffect)) 
        endmethod
    endstruct
endscope


Something along those lines. Hopefully you'll get the picture. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • tom_mai78101 tom_mai78101:
    Hmm, about the Headline News, I noticed threads are being moved into the subforum (Health News, Environmental News, etc.). When that happens, the TH Forum Home page loses the articles, and instead would show old articles posted 1 or 2 weeks ago.
  • tom_mai78101 tom_mai78101:
    What do we do with the Home page?
  • Ghan Ghan:
    I added those forums to the filter for that widget.
    +1
  • tom_mai78101 tom_mai78101:
    Oh nice. They're back. Thanks.
  • tom_mai78101 tom_mai78101:
    Now I think it makes more sense for me to put news in their own subforums, without worry.
  • The Helper The Helper:
    Awesome Ghan thanks! I was purposely not moving the first 15 news articles in Headline news to the different subforums but I guess I don't have to do that now?
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday
  • tom_mai78101 tom_mai78101:
    I found out you can't delete nor hide redirect links to existing threads. It will just stay there. I have no choice now but to start moving thread redirects to News Archive.
  • The Helper The Helper:
    That is not the way that it works for me I can delete redirects you just have to hit refresh sometimes big deletes will take a while as long as moves\
  • The Helper The Helper:
    You don't have to do that you can just leave stuff there in headline news for up to a year it was already down to like 8 months there is no rush.

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top