- Joined
- Nov 25, 2008
- Messages
- 1,309
So, my spell 'static Discharge' creates several dummy caster units, has them cast a spell, and removes them. However, It would seem that I am removing them too soon, and they can't cast their spell.
What am I doing wrong?
PS: The 'spell' is in the trigger's condition, and the events are added via another trigger. The events are correct and do trigger the spell as intended.
JASS:
function Trig_StaticDischarge takes nothing returns boolean
local unit C=GetSpellAbilityUnit()
local player P=GetOwningPlayer(C)
local real X=GetSpellTargetX()
local real Y=GetSpellTargetY()
local integer Id1=GetSpellAbilityId()
local integer Id2='h002'//Dummy Unit ID
local string Pur="purge"//Purge Order String
local string Blt="chainlightning"//Bolt Order String
local integer Lv=GetUnitAbilityLevel(C,Id1)
local real Dmg=Lv*75
local real AoE=350
local integer B=2+Lv
local unit U=null
local integer Pc=0
local unit array T
local group G=CreateGroup()
local unit array Dmy
local integer Ndm=0
local integer I
if Id1!='A003'then// Spell Id Check
return false
endif
call DisplayTextToPlayer(Player(0),0,0,"Start")
set C=null
// Get Bolt Targets, Deal Damage, Apply Purge
call GroupEnumUnitsInRange(G,X,Y,AoE,null)
loop
set U=FirstOfGroup(G)
exitwhen U==null
call DisplayTextToPlayer(Player(0),0,0,"Found Unit")
if IsUnitEnemy(U,P)then
call DisplayTextToPlayer(Player(0),0,0,"Unit Is Enemy")
set I=0
loop
exitwhen I>=B
if T[I]!=U then
call DisplayTextToPlayer(Player(0),0,0,"Unit Isn't Picked")
if T[I]==null then
set Pc=Pc+1
set T[I]=U
set I=B
call DisplayTextToPlayer(Player(0),0,0,"Bolt Target")
elseif Pc>=B and GetUnitState(U,UNIT_STATE_LIFE)<GetUnitState(T[I],UNIT_STATE_LIFE) then
set T[I]=U
set I=B
call DisplayTextToPlayer(Player(0),0,0,"Bolt Target 2")
endif
endif
set I=I+1
endloop
call DisplayTextToPlayer(Player(0),0,0,"Purge")
set C=CreateUnit(P,Id2,X,Y,0)
set Dmy[Ndm]=C
set Ndm=Ndm+1
call IssueTargetOrder(C,Pur,U)
call DisplayTextToPlayer(Player(0),0,0,"Damage")
call UnitDamageTarget(C,U,Dmg,true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_LIGHTNING,WEAPON_TYPE_WHOKNOWS)
set C=null
endif
call GroupRemoveUnit(G,U)
set U=null
endloop
call DestroyGroup(G)
set G=null
set I=0
loop
exitwhen I==B
call DisplayTextToPlayer(Player(0),0,0,"Bolt")
set C=CreateUnit(P,Id2,X,Y,0)
set Dmy[Ndm]=C
set Ndm=Ndm+1
call IssueTargetOrder(C,Blt,T[I])
set T[I]=null
set I=I+1
set C=null
endloop
set P=null
loop
exitwhen Ndm<0
call RemoveUnit(Dmy[Ndm])
set Dmy[Ndm]=null
set Ndm=Ndm-1
endloop
return false
endfunction
function InitTrig_StaticDischarge takes nothing returns nothing
set gg_trg_StaticDischarge=CreateTrigger()
call TriggerAddCondition(gg_trg_StaticDischarge,Condition(function Trig_StaticDischarge))
endfunction
What am I doing wrong?
PS: The 'spell' is in the trigger's condition, and the events are added via another trigger. The events are correct and do trigger the spell as intended.