Detect Units In Range


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.


In vJASS? Something like the following. Just note that I wrote this without compiling it, so there may be slight errors. It requires TimerUtils:
scope DamageDummy
         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
    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 */
             return false
        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))
                  /* if he is dead, release the timer (recycle) and destroy the instance */
                  call ReleaseTimer(GetExpiredTimer())
                  call this.destroy()
        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) */
            return false
        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)) 

Something along those lines. Hopefully you'll get the picture. :)
General chit-chat
Help Users

    Staff online

    Members online


    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.