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.
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!
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() == 039;A00D039;) 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, 039;A00D039;)
if (abil_level > 0) then //Checks the level of the ability being cast and adds a corresponding chain spell
call UnitAddAbility(caster, 039;A00P039;)
elseif (abil_level > 2) then
call UnitAddAbility(caster, 039;A00R039;)
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, 039;A00P039;) //If the hero does not use the chain spell to consume the effect in 10 seconds
call UnitRemoveAbility(caster, 039;A00R039;) //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!