Trigger with event inside another trigger

Monovertex

Formerly Smith_S9
Reaction score
1,461
Okay, I have this code:

Code:
function Malediction_Aura_Actions takes nothing returns nothing
 local trigger Death = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ( Death, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( Death, Condition( function Death_Conditions ) )
    call TriggerAddAction( Death, function Death_Actions )
endfunction

//===========================================================================
function InitTrig_Malediction_Aura takes nothing returns nothing
    local trigger Malediction_Aura = CreateTrigger(  )

    call TriggerRegisterAnyUnitEventBJ( Malediction_Aura, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( Malediction_Aura, Condition( function Malediction_Aura_Conditions ) )
    call TriggerAddAction( Malediction_Aura, function Malediction_Aura_Actions )
endfunction

This is not the full code. The problem is that the trigger Death doesn't fires. The problem isn't the condition and I didn't destroyed the trigger, either. Also, I cannot create the trigger in InitTrig_Malediction_Aura because of...some things (long story :D ). So, anyone can clear me up why this doesn't work? Thanks in advance. :)
 

SFilip

Gone but not forgotten
Reaction score
634
Code:
function InitTrig_Malediction_Aura takes nothing returns nothing
    local trigger Malediction_Aura = CreateTrigger(  )
local? that's not really wise...

anyway mind posting Death_Conditions and Death_Actions? the problem might be there...
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
@Chocobo: I said that that is not the entire code.

Here it is. I'll post it all...

Code:
//***|Raw Codes|***

function Malediction_Aura_Raw_Code takes nothing returns integer
 return 'A00B'
endfunction

function Malediction_Aura_Dummy_Ability takes nothing returns integer
 return 'A00C'
endfunction

function Death_Malediction_Buff takes nothing returns integer
 return 'B004'
endfunction

//Additional Data------------------------------------------------------------

function Death_AoE takes nothing returns real
 return 500.00 //Desired initial AoE of the unit's death
endfunction

function Death_AoE_Growth takes nothing returns real
 return 150.00 //AoE growth per level
endfunction

function Death_Final_AoE takes unit whichUnit returns real
 return (Death_AoE()+Death_AoE_Growth()*GetUnitAbilityLevel(whichUnit, Malediction_Aura_Raw_Code()) -Death_AoE_Growth())
endfunction

function Death_Mana_Taken takes unit whichUnit returns real
 return I2R(30*GetUnitAbilityLevel(whichUnit, Malediction_Aura_Raw_Code()))
endfunction

function Death_Life_Taken takes unit whichUnit returns real
 return 0.10*GetUnitAbilityLevel(whichUnit, Malediction_Aura_Raw_Code())
endfunction

//Conditions-----------------------------------------------------------------

function Malediction_Aura_Conditions takes nothing returns boolean
 return GetUnitAbilityLevel(GetTriggerUnit(), Malediction_Aura_Raw_Code()) > 0 and IsUnitType(GetAttacker(), UNIT_TYPE_MAGIC_IMMUNE) == false
endfunction

function Death_Conditions takes nothing returns boolean
 return UnitHasBuffBJ(GetTriggerUnit(), Death_Malediction_Buff()) == true
endfunction

//Filters--------------------------------------------------------------------

function Death_Enemy_Immune_Unit_Filter takes nothing returns boolean
 return ( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == true ) and ( IsUnitType(GetFilterUnit(), UNIT_TYPE_MAGIC_IMMUNE)==false ) and IsUnitAliveBJ(GetFilterUnit()) == true
endfunction

//Actions--------------------------------------------------------------------

function Death_Actions takes nothing returns nothing
//***Locals***
 local unit victim = GetTriggerUnit()
 local unit cast = GetHandleUnit(GetTriggeringTrigger(), "cast")
 local unit var
 local group g1 = CreateGroup()
 
 local real x = GetWidgetX(victim)
 local real y = GetWidgetY(victim)

//***Actions***
    call AddSpecialEffectTarget("Objects\\Spawnmodels\\Undead\\UndeadDissipate\\UndeadDissipate.mdl", victim, "origin")

    call GroupEnumUnitsInRange(g1, x, y, Death_Final_AoE(cast), Condition(function Death_Enemy_Immune_Unit_Filter))

  loop
    set var = FirstOfGroup(g1)
    exitwhen var == null
    call AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl", var, "origin")

    set x = Death_Mana_Taken(cast)

if x > GetUnitState(var, UNIT_STATE_MANA) then
    set x = GetUnitState(var, UNIT_STATE_MANA)
else
endif

    call SetUnitState(var, UNIT_STATE_MANA, GetUnitState(var, UNIT_STATE_MANA)-x)
    call ManaText(var, x, 0)

    set x = Death_Life_Taken(cast)*GetUnitState(var, UNIT_STATE_LIFE)
    call SetUnitState(var, UNIT_STATE_LIFE, GetUnitState(var, UNIT_STATE_LIFE)-x)
    call ManaText(var, x, 1) 
    call GroupRemoveUnit(g1, var)
  endloop

    call DestroyGroup(g1)
    set victim = null
    set cast = null
    set var = null
    set g1 = null
endfunction

//***************************************************************************

function Malediction_Aura_Actions takes nothing returns nothing
//***Locals***
 local unit victim = GetAttacker()
 local unit cast = GetTriggerUnit()
 local trigger Death = CreateTrigger()

 local real x = GetWidgetX(victim)
 local real y = GetWidgetY(victim)

 local unit dummy = CreateUnit(GetOwningPlayer(cast), Dummy(), x, y, 0.00)

//***Actions***
    call UnitApplyTimedLife(dummy, 'BTLF', 2.00)
    call SetUnitAbilityLevel(dummy, Malediction_Aura_Dummy_Ability(), GetUnitAbilityLevel(cast, Malediction_Aura_Raw_Code())) 
    call IssueTargetOrder(dummy, "slow", victim)

    call SetHandleHandle(Death, "cast", cast)

    call TriggerRegisterAnyUnitEventBJ( Death, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( Death, Condition( function Death_Conditions ) )
    call TriggerAddAction( Death, function Death_Actions )  

    set victim = null
    set cast = null
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Malediction_Aura takes nothing returns nothing
    local trigger Malediction_Aura = CreateTrigger(  )

    call TriggerRegisterAnyUnitEventBJ( Malediction_Aura, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( Malediction_Aura, Condition( function Malediction_Aura_Conditions ) )
    call TriggerAddAction( Malediction_Aura, function Malediction_Aura_Actions )
endfunction

The functions 'ManaText' and 'Dummy' are in the map header and, believe me, those can't be the problem :D

@SFilip: why it's not a wise decision to make it local? I'm new to Jass and I'd like to know why...
 

SFilip

Gone but not forgotten
Reaction score
634
smith_s9 said:
@SFilip: why it's not a wise decision to make it local? I'm new to Jass and I'd like to know why...
since you are new to jass i suggest that you do not mess with the init part too much. its not wise because a local gets destroyed afterwards - in other words you wont be able to "refer" to that trigger anymore (as a matter of fact it might not even run, never experimented that much).
also you might want to add use "constant function" instead of just "function" for those that simply return a value. this makes them slightly faster.
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
SFilip said:
since you are new to jass i suggest that you do not mess with the init part too much. its not wise because a local gets destroyed afterwards - in other words you wont be able to "refer" to that trigger anymore (as a matter of fact it might not even run, never experimented that much).
also you might want to add use "constant function" instead of just "function" for those that simply return a value. this makes them slightly faster.

Well, I never had that kind of problem by using local triggers...

And ty for the tip with the constants. +rep

Btw, any solution for my problem? :D
 

SFilip

Gone but not forgotten
Reaction score
634
smith_s9 said:
Well, I never had that kind of problem by using local triggers...
well dont initialize triggers using locals, what's the point in that anyway? locals aren't faster than globals for instance.
for example never replace
Code:
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
with
Code:
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
what if you need to enable/disable/do anything to that trigger afterwards?

anyway i solve problems like this by commenting...simply start by commenting everything except for the trigger creation part (and add some text message action to the death trigger). see if it works...if it does then uncomment some more. evetually you find the buggy line although it takes time.
and sorry, this is the only solution i could think of :eek:
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
Well, I discovered the problem... Is the condition. But why it doesn't works, I don't know... The raw code is correct, the unit has the buff... :banghead:

Maybe because I make this trigger inside another one, the triggering unit is not considered the dying one, but the triggering unit from the Malediction_Aura trigger?
 

SFilip

Gone but not forgotten
Reaction score
634
can't be...try displaying a game message with the name of triggering unit in Death trigger.
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
The thing is that the Death trigger doesn't fires at all with that condition... and, if what I sais is wright, it shouldn't fire, cuz the triggering unit from the Malediction_aura doesn't have that buff... so I can't see wich is the triggering unit for the death trigger
 

SFilip

Gone but not forgotten
Reaction score
634
perhaps...what are you trying to do (don't make me read the entire code pls :p)?
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
So, when a unit dies, I must check if that unit had a buff. If it had it, then something happens... do you want more details?
 

SFilip

Gone but not forgotten
Reaction score
634
that's what i fugred out from your posts...is the ability supposed to kill the unit?
anyway maybe you can try changing the event from unit dies to unit's hp becomes less than 1 or something like that. it works sometimes for me, but not always...
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
The ability is supposed to taint the target. And when the tainted unit dies, it's friendly nearby units loose life and mana.

I think I'll use your solution... ty.

EDIT: But I can use that event only with specific units :(

EDIT1: And what happens if the unit reaches 2 life and then is killed =/

Any other ideas?
 
C

crazedcougar

Guest
does custom value (or custom boolean if you have WEU) work on a dead unit? Find a way to set it to 1 when it has the buff, and zero when it does not. Then, based on the custom value of a unit, do actions.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top