• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Cleaning Dummy Units on Spell Fails

Status
Not open for further replies.
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.

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.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I analyzed you spell more closely now and this is what you should do.

1. Object editor, Dummy unit
a) Set Art - Animation - Cast Point and backswing to 0
b) Set Movement speed to 0. Type doesn't matter
c) Set death type to Can't raise, does not decay
d) Make sure the ability has 0 cooldown

2. Triggers
a) Create only one dummy
b) Order the dummy to cast the spell on each unit
c) Use RemoveUnit() in the end
 
Status
Not open for further replies.
Top