• 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.

[Trigger] Trigger only working one time

Status
Not open for further replies.
Level 2
Joined
Jun 25, 2006
Messages
18
I can't figure it out. The below trigger works, once. Then it doesn't work again. What it does is when a certain unit dies, it heals all units around it. Simple, but it only works one time, then won't fire again. Can anyone see what I'm doing wrong?

JASS:
struct dispurse
    group toheal = CreateGroup()
    player owner
    timer t = CreateTimer()
    method onDestroy takes nothing returns nothing
        call DestroyGroup(.toheal)
        call PauseTimer(.t)
        call FlushHandleLocals(.t)
        call DestroyTimer(.t)
    endmethod
endstruct
function HealDispurseCond takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit())=='eC38' or GetUnitTypeId(GetTriggerUnit())=='e00P'
endfunction
function HealDispurseHeal takes nothing returns nothing
    local timer t        = GetExpiredTimer()
    local dispurse data  = dispurse(GetHandleInt(t,"struct"))
    local unit u         = FirstOfGroup(data.toheal)
    local unit v
    local player p
    local real x
    local real y
    set p = GetOwningPlayer(u)
    if CountUnitsInGroup(data.toheal) > 0 then
        if IsPlayerAlly(data.owner, p) then
            set x = GetUnitX(u)
            set y = GetUnitY(u)
            set v = CreateUnit(data.owner, 'h062', x, y, 270)
            call UnitAddAbility(v, 'A06E')
            call IssueTargetOrder(v, "heal", u)
            call UnitApplyTimedLife(v, 'BTLF', 1)
        endif
        call GroupRemoveUnit(data.toheal, u)
    else
        call data.destroy()
    endif
    set t = null
    set u = null
    set v = null
    set p = null
endfunction
function HealDispurse takes nothing returns nothing
    local dispurse data = dispurse.create()
    local unit u        = GetDyingUnit()
    local player p      = GetOwningPlayer(u)
    local real x        = GetUnitX(u)
    local real y        = GetUnitY(u)
    call GroupEnumUnitsInRange(data.toheal, x, y, 500, null)
    set data.owner = p    
    call SetHandleInt(data.t, "struct", data)
    call TimerStart(data.t, .01, true, function HealDispurseHeal)
    set u = null
    set p = null
endfunction
function InitTrig_HealDispurse takes nothing returns nothing
    local integer i = 6
    set gg_trg_HealDispurse = CreateTrigger()
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEvent(gg_trg_HealDispurse, Player(i), EVENT_PLAYER_UNIT_DEATH, null)
        set i = i + 1
    endloop
    call TriggerAddCondition(gg_trg_HealDispurse, Condition(function HealDispurseCond))
    call TriggerAddAction(gg_trg_HealDispurse, function HealDispurse)
endfunction


Edit: I ran some tests with text messages, to see what's all working. Everything is working correctly, the dummy is being created for every instance of timer tick, the ability is being added, but maybe heal is not being cast? I'm so confused and I have other "spells" that suffer the same issue that target multiple units from a group. Like, mass sleep, mass shackle, mass bloodlust, etc.. all work only one during the game and use a similar trigger like the one above but only work one time...

Edit2: I replaced using heal with holy light now it works everytime, so I guess my issue is resolved.
 
Last edited:
Level 2
Joined
Jun 25, 2006
Messages
18
Just a question, why are using a timer? It's simpler and more efficient to use a loop (then you wouldn't have to bother with structs and attached ints).

Unless you don't want all the healing to happen at the same time? (but then again 0.01 seconds is hardly noticeable)

I use a timer because loops create a slowdown when it deals with many units. I decided to do this a better way, instead of a dummy and heal spell i just scripted the actual heal.

JASS:
function HealDispurseHeal takes nothing returns nothing
    local timer t        = GetExpiredTimer()
    local dispurse data  = dispurse(GetHandleInt(t,"struct"))
    local unit u         = FirstOfGroup(data.toheal)
    local player p       = GetOwningPlayer(u)
    if CountUnitsInGroup(data.toheal) > 0 then
        if IsPlayerAlly(data.owner, p) and GetWidgetLife(u) > 0 then
            call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) + 75.00)
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl", u, "origin"))
        endif
        call GroupRemoveUnit(data.toheal, u)
    else
        call data.destroy()
    endif
    set t = null
    set u = null
    set p = null
endfunction
 
Status
Not open for further replies.
Top