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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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