Effects not being Destroyed from Array, what am I missing?

Sungazer

New Member
Reaction score
0
This is my 2nd attempt at a JASS spell and up to this point I've been doing ok, slowly plowing my way through it. However, I'm finally stumped and I'm not seeing it.

Explanation: This is a simple custom spell that creates a "castable" immolation that gives the hero a buff that lasts for 10 seconds that creates a special effect and deals damage once per second in a 200 area.

There is a little added complexity with a "chain-spell" system I'm implementing (inspired by my recent Aion Online beta experience), where this spell "unlocks" access to two other spells. If those spells are cast, the immolation effect is consumed and this spell is supposed to "shut off."

What's not working: As per the title, the immolation_target special effect is sticking around and stacking, instead of "flickering" for one second like it's supposed to. I had this working at one point and a few modifications later it's got me stumped.

JASS:
function Conditions takes nothing returns boolean
    if (GetSpellAbilityId() == 'A00D') then   //checking for the correct spell
        return true
    endif
endfunction

function EnemyCheck takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())))  //A simple Condition function that is used with GetEnumUnitsInRange() below
endfunction

function DamageEffect takes nothing returns nothing     //This function is the "What to do on the units picked with ForGroup()", hence the globals needed so I can use this as a "static" function
    call BJDebugMsg("immo_count: "+I2S(udg_immo_count))     //My debug attempts; as far as I can see the indexes are behaving as expected
    call AddSpecialEffectTarget( "Abilities\\Spells\\Other\\ImmolationRed\\ImmolationRedDamage.mdl", GetEnumUnit(), "head" )
    set udg_immo_effect[udg_immo_count] = GetLastCreatedEffectBJ()
    call UnitDamageTarget(GetTriggerUnit(), GetEnumUnit(), 15.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
    set udg_immo_count = udg_immo_count + 1
endfunction

function Actions takes nothing returns nothing
  
    local unit caster
    local integer abil_level
    local integer i = 0   //index used for the outer loop which runs the bulk of the spell
    local integer j = 0   //index used for the inner loop which destroys effects from an array
    local integer k = 9   //max index used for outer loop
    local group immo_targets = CreateGroup()
   
    set udg_pyroclast_active = true  //A boolean flag that gets set to 'false' when this effect is consumed by its chain spell
    set caster = GetTriggerUnit()
    set abil_level = GetUnitAbilityLevel(caster, 'A00D')
    
    if (abil_level > 0) then                  //Checks the level of the ability being cast and adds a corresponding chain spell
        call UnitAddAbility(caster, 'A00P')
    elseif (abil_level > 2) then
        call UnitAddAbility(caster, 'A00R')
    else
        call DoNothing()
    endif
    
    
    loop
        exitwhen ((i > k) or (udg_pyroclast_active == false)) //k=9 here because I want this to loop for 10 seconds
         
        call GroupEnumUnitsInRange(immo_targets, GetUnitX(caster), GetUnitY(caster), 200.00,Condition(function EnemyCheck))
        call ForGroup ( immo_targets, function DamageEffect ) //These "work"; the units in range that I want are selected and damaged like they're supposed to be             
           
        call TriggerSleepAction(1.00)         //I know waits are looked down upon, but this makes this loop a 1-sec "periodic"; 
                                              //also, the immolation target effect is destroyed instantly without a wait
        loop                                 //If there's another way around this, I'm open to it
            call BJDebugMsg("j: "+I2S(j))
            exitwhen j > (udg_immo_count - 1)  //udg_immo_count = the # of effects in the array, subtracting 1 because it increments an extra time after the last effect is added
            call DestroyEffect(udg_immo_effect[j]) //The culprit line apparently not working
            set j = j + 1
        endloop 

        set udg_immo_count = 0 //Resetting indexes because the hero may move and get an entirely new set of units
        set j = 0              //I'm still looking at this, it may be what's causing an effect to linger
        set i = i + 1
         
    endloop
    
    set i = 0
    set j = 0
    set k = 9
    set udg_immo_count = 0
   
    call UnitRemoveAbility(caster, 'A00P')  //If the hero does not use the chain spell to consume the effect in 10 seconds
    call UnitRemoveAbility(caster, 'A00R')  //the chain spell is removed 
     
    call DestroyGroup(immo_targets)         //Leaks; did I miss any others?
    
endfunction

function InitTrig_Pyroclastic_Shards takes nothing returns nothing
    set gg_trg_Pyroclastic_Shards = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Pyroclastic_Shards, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Pyroclastic_Shards, Condition( function Conditions ) )
    call TriggerAddAction( gg_trg_Pyroclastic_Shards, function Actions )
endfunction


Oh, if you find ways to clean this up or have suggestions on functions that can simplify things I'm open to them. Still learning a lot.

Thanks in advace, +Rep around the room for any help!
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
Don't do bj_lastCreatedSpecialEffect, instead do this:

JASS:
set udg_immo_effect[udg_immo_count] = AddSpecialEffectTarget( "Abilities\\Spells\\Other\\ImmolationRed\\ImmolationRedDamage.mdl", GetEnumUnit(), "head" )
 

Sungazer

New Member
Reaction score
0
lol, wow, that was it!

I don't understand though, what's wrong with that function?

And how would I have found this out? I've been pouring over pages of documentation and never saw this mentioned.

Thanks a ton for the extremely quick and correct reply!
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
The bj_lastCreatedSpecialEffect variable is only set if you use the BJ, hence GUI.
 

Sungazer

New Member
Reaction score
0
Ahh... I see it now. I used a native function to add the special effect and was using a BJ to access it. I'll have to be careful not to mix up my natives and BJs. *runs away giggling at the imagery*

Thanks again! :thup:
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
It's not much, but here's a vanity touch up:

JASS:
scope YourSpell initializer Init

private function EnemyCheck takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())) //A simple Condition function that is used with GetEnumUnitsInRange() below
endfunction

private function DamageEffect takes nothing returns nothing     //This function is the "What to do on the units picked with ForGroup()", hence the globals needed so I can use this as a "static" function
    call BJDebugMsg("immo_count: "+I2S(udg_immo_count))     //My debug attempts; as far as I can see the indexes are behaving as expected
    call AddSpecialEffectTarget( "Abilities\\Spells\\Other\\ImmolationRed\\ImmolationRedDamage.mdl", GetEnumUnit(), "head" )
    set udg_immo_effect[udg_immo_count] = GetLastCreatedEffectBJ()
    call UnitDamageTarget(GetTriggerUnit(), GetEnumUnit(), 15.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
    set udg_immo_count = udg_immo_count + 1
endfunction

private function Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local integer abil_level = GetUnitAbilityLevel(caster, 'A00D')
    local integer i = 0   //index used for the outer loop which runs the bulk of the spell
    local integer j = 0   //index used for the inner loop which destroys effects from an array
    local integer k = 9   //max index used for outer loop
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local group immo_targets = CreateGroup()
    set udg_pyroclast_active = true  //A boolean flag that gets set to 'false' when this effect is consumed by its chain spell 
    if (abil_level > 0) then                  //Checks the level of the ability being cast and adds a corresponding chain spell
        call UnitAddAbility(caster, 'A00P')
    elseif (abil_level > 2) then
        call UnitAddAbility(caster, 'A00R')
    else
    endif        
    loop
        exitwhen i > k or udg_pyroclast_active == false//k=9 here because I want this to loop for 10 seconds         
        call GroupEnumUnitsInRange(immo_targets, x, y, 200.00, Filter(function EnemyCheck))
        call ForGroup ( immo_targets, function DamageEffect ) //These "work"; the units in range that I want are selected and damaged like they're supposed to be                        
        call TriggerSleepAction(1.00)         //I know waits are looked down upon, but this makes this loop a 1-sec "periodic"; 
                                            //also, the immolation target effect is destroyed instantly without a wait
        loop                                 //If there's another way around this, I'm open to it
            call BJDebugMsg("j: "+I2S(j))
            exitwhen j > (udg_immo_count - 1)  //udg_immo_count = the # of effects in the array, subtracting 1 because it increments an extra time after the last effect is added
            call DestroyEffect(udg_immo_effect[j]) //The culprit line apparently not working
            set j = j + 1
        endloop 
        set udg_immo_count = 0 //Resetting indexes because the hero may move and get an entirely new set of units
        set j = 0              //I'm still looking at this, it may be what's causing an effect to linger
        set i = i + 1
    endloop    
    set i = 0
    set j = 0
    set k = 9
    set udg_immo_count = 0
    call UnitRemoveAbility(caster, 'A00P')  //If the hero does not use the chain spell to consume the effect in 10 seconds
    call UnitRemoveAbility(caster, 'A00R')  //the chain spell is removed     
    call DestroyGroup(immo_targets)         //Leaks; did I miss any others?   
    set caster = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00D'
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
endfunction
endscope
 

Sungazer

New Member
Reaction score
0
That clean-up looks like vJass. Don't get me wrong, I appreciate it, but I haven't had success using the utilities required for compiling vJass. In the past I often got errors when saving due to new WC3 versions and incompatibility. Now 1.24 is out and with my meager experience, I didn't want to touch it.

I did like Vex's tutorial on it and I see the advantages, just couldn't find updated working utilities.
 

Renendaru

(Evol)ution is nothing without love.
Reaction score
309
There's no problem to it, just download NewGen, put the code in, and save. If you have problems with vJass, just ask anyone here.
 

Sungazer

New Member
Reaction score
0
I have, that happens to be what I tried. Whenever I try to save it crashes with a windows error, so rather than risk losing work I'll just deal with primitive JASS for now ;P
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top