Destroying trigger after use

W!†A_cRaft

Ultra Cool Member
Reaction score
28
I am trying to make an ON-attack triggered spell.
When a unit attacks it stores the attacker and attacked unit to hash
Creates a trigger that registers an even Unit (target) takes damage
than check if the attacker is the on who damaged it
check if the target has Poison arrow buff (in order to determin was the damage done by an attack)
check is the damage done >1
and than execute the trigger.

I ran into a problem where, to be more specific after the whole thing is done the trigger will still stay and i dont know if it causes leaks or not, but it will be useless to have the thing checked every time those two units exchange damage. So i need to destroy a trigger i created in it's actions function, how do i do that? How do i refer to the trigger who's actions im doing?

Look at the trigger below.

JASS:
function ondamaged takes nothing returns nothing
    call SaveBoolean(udg_hash, GetHandleId(GetEventDamageSource()), StringHash("bool"), true)
    call UnitRemoveAbility(GetEventDamageSource(), 'A00A') //poison string
    call UnitRemoveAbility(GetEventDamageSource(), 'A00B') //sphere
    call UnitRemoveAbility(GetEventDamageSource(), 'A001') //sphere
    call UnitRemoveAbility(GetEventDamageSource(), 'A009') //+damage ability
    //here i need to despose of everything that is unnecessary, i dont know how.
endfunction

function damagecheck takes nothing returns boolean
    local unit u = LoadUnitHandle(udg_hash, GetHandleId(GetTriggerUnit()), StringHash("attacker"))
    local unit target = LoadUnitHandle(udg_hash, GetHandleId(GetTriggerUnit()), StringHash("self"))
    if (GetEventDamage() >= 1.0) then
        if(GetEventDamageSource() == u) then
            if(GetUnitAbilityLevel(target, 'B003') >=1) then
                return true
            else
            endif
        else
        endif
    else
    endif
    return false
endfunction

function Trig_Attacked_Actions takes nothing returns nothing
    local trigger t
    local boolean bool = LoadBoolean(udg_hash, GetHandleId(GetAttacker()), StringHash("bool"))
    if (not(bool)) then
        call SaveUnitHandle(udg_hash, GetHandleId(GetTriggerUnit()), StringHash("attacker"), GetAttacker())
        call SaveUnitHandle(udg_hash, GetHandleId(GetTriggerUnit()), StringHash("self"), GetTriggerUnit())
        set t = CreateTrigger()
        call TriggerRegisterUnitEvent(t, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
        call TriggerAddCondition(t, Condition(function damagecheck))
        call TriggerAddAction(t, function ondamaged)
    else
    endif
endfunction

//===========================================================================
function InitTrig_Attacked takes nothing returns nothing
    set gg_trg_Attacked = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Attacked, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Attacked, function Trig_Attacked_Actions )
endfunction
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
It will leaks event and actions, but it does not matter much about the event. Store the trigger action and remove it before destroying trigger. Remember to disable trigger before destroying it.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
but how do i destroy the trigger m8?
the way it is now the triggers are left there and everytiem i attack they fire off
resulting in:
1 for 1st attack
2 for second
3 for 3rd
4 for forth
etc

If i attack the same unit lets say 10 times i would have 10 triggers fireing of actions. that is why i need to destroy the trigger when actions are performed.
I managed to do it with call DestroyTrigger (GetTriggeringTrigger)

But than i realised that the trigger is created even if the conditions aren't passed and than actions dont happen so can i use the same line to dispose of the trigger within the conditions?

Because if i use it after return it does nothing
if i use it before return well
than there is no point in returning anything trigger is gone.
 

Tyrulan

Ultra Cool Member
Reaction score
37
Check the tutorial section for Jesus4Lyf's Damage system. The event is thrown when a unit takes damage, not when an attack order is given. (These could be easily exploited).

Destroying a trigger will not remove the space allocated for variables stored in it's code.

You need to handle all variables and objects first, then turning off or destroying the trigger if you like.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
My question is not if it will clear variables, nor if it will cause leaks.

My question is:
If i use Destroy trigger will i still have other commands that are in it executed. For example:

If I use this command line within the actions of my trigger


will my trigger still continue with it's regular actions passed this point, because it is destroyed.
 

Hatebreeder

So many apples
Reaction score
381
That trigger would execute once.
But then never again (well, apart from creating it again and registering yadayada).

Also, GetTriggeringTrigger is not a good Idea.
I'v e done something like this once. It destroys all instances of the same trigger :X so... Lets say you have it registered for 3 units; and one fires -> all others won't fire anymore. I don't know why, but it's like that...
 

saw792

Is known to say things. That is all.
Reaction score
280
You're going about this the completely wrong way. Just save yourself the effort + possibility of bugs that are difficult to debug and use a damage detection system such as Damage.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
problem is i completly do not understand how the system works and am not sure will i be able to use it correctly
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
didnt even bother to take a look at the demo map, sicne i read the system, understood lets say 50% of things that it is doing but i cannot understand the

TypeStackLevel
and TypeStackValue

dont have an idea what are they used for....
and sicne you use them in most of the system I dont thiunk i will manage to make it work


EDIT: I dont think the system would solve my problem would it? I must detect wheater the unit has been damaged by an attack or a certain unit that has certain buff, the way i understood it you can check if the attack is physical but you cannot check if it is an actual attack meaning that if I have a triggered spell that deals physical damage to the target it will still fire the trigger? Wont it?

EDIT: EDIT: jesus4Lyf mind sending me your MSN via Private message, i have a cupple of quick questions and dont want to troll the forums.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top