• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Detect and remove corpses

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
Alright, I'm trying to create a spell that works just like Carrion Beetles. However I can't seem to target and remove corpses. The spell is a no target spell, just like carrion beetles.

The reason this is spell triggered is because I'm trying to modify 1 unit via triggers after summoning it, instead of creating 5 different units for each level.

I figured it cuold be done by getting all units in a range, putting them in a group, then checking which are at 0 or less HP, removing them and creating beetles at their position. This however didn't work.

JASS:
function Swarm_Actions takes nothing returns nothing
 local unit t
 local unit c = GetTriggerUnit()
 local group g = CreateGroup()
 local player cp = GetOwningPlayer(c)
 local integer i = 0
    loop
         set t = FirstOfGroup(g)
        if IsUnitEnemy(t, GetOwningPlayer(c)) then
            
        else
         call GroupRemoveUnit(g, t)
        endif
    exitwhen t == null or i == 1
        if GetWidgetLife(t) <= 0 then
            call CreateUnit(cp, 'swar', GetUnitX(t), GetUnitY(t), bj_UNIT_FACING)
            call GroupRemoveUnit(g,t)
            call RemoveUnit(t)
            set i = i + 1
        else
            call GroupRemoveUnit(g, t)
        endif
    endloop
 set c = null
 call DestroyGroup(g)
 set t = null
 set cp = null
endfunction

function Swarm_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'swar'
endfunction

//===========================================================================

function InitTrig_Swarm takes nothing returns nothing
    local trigger Swarm = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Swarm, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction( Swarm, function Swarm_Actions )
    call TriggerAddCondition(Swarm, function Swarm_Conditions)
endfunction
 
Alternitevly, if you use vJass or ever decide to you can use UnitAlive.

JASS:
native UnitAlive takes unit id returns boolean
function Swarm_Actions takes nothing returns nothing
 local unit t
 local unit c = GetTriggerUnit()
 local group g = CreateGroup()
 local player cp = GetOwningPlayer(c)
 local integer i = 0
    loop
         set t = FirstOfGroup(g)
        if IsUnitEnemy(t, GetOwningPlayer(c)) then

        else
         call GroupRemoveUnit(g, t)
        endif
    exitwhen t == null or i == 1
        if UnitAlive(t) then
            call CreateUnit(cp, 'swar', GetUnitX(t), GetUnitY(t), bj_UNIT_FACING)
            call GroupRemoveUnit(g,t)
            call RemoveUnit(t)
            set i = i + 1
        else
            call GroupRemoveUnit(g, t)
        endif
    endloop
 set c = null
 call DestroyGroup(g)
 set t = null
 set cp = null
endfunction

function Swarm_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'swar'
endfunction

//===========================================================================

function InitTrig_Swarm takes nothing returns nothing
    local trigger Swarm = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(Swarm, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction( Swarm, function Swarm_Actions )
    call TriggerAddCondition(Swarm, function Swarm_Conditions)
endfunction

Please note, that this will work if you have NewGen (with JassHelper enabled).
 
Status
Not open for further replies.
Top