Stop Casting Problem

0zaru

Learning vJASS ;)
Reaction score
60
Well i have an spell that makes a unit channel up for 12 seconds. When i make it stop by moving or some other issue move it makes all the effects but.. When i cast it again it Crash with no error. BUT if i make the unit wait the channel, and then cast it again it won't crash...

Here is my code:
JASS:
scope NaturesWrath

globals
    private integer NWId='A007'
    private integer NWDummyTree='h005'
    private integer NWDummyChannel='h004'
    private integer NWDummyEffectFs='h006'
    private real NWAoEForEffects=800
    private real NWAoEForDamage=400
    private real NWDistanceRest=50
    private real DamagePerSecondPerLevel=100
    private integer NWMaxCircleUnits=36
    private real NWCircleHeightIncrease=12
    private real MaxHeight=800
endglobals

private function Trig_Natures_Wrath_Condition takes nothing returns boolean
    return GetSpellAbilityId()==NWId
endfunction

private function BallsMove takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local string ttable=GetAttachmentTable(t)
    local real Cx=GetTableReal(ttable,"xc")
    local real Cy=GetTableReal(ttable,"yc")
    local unit Caster=GetTableUnit(ttable,"Caster")
    local real x
    local real y
    local real newx
    local real newy
    local unit dummy
    local boolean b=false
    local integer i=0
    local real Height
    local real AngleToGo
    loop
       exitwhen i>NWMaxCircleUnits
              set dummy=GetTableUnit(ttable,"dummy"+I2S(i))
              set x=GetUnitX(dummy)
              set y=GetUnitY(dummy)
              if IsUnitInRange(dummy,Caster,50)==false then
                  set AngleToGo=Atan2(y-Cy,x-Cx)
                  set newx=x-NWDistanceRest*Cos(AngleToGo)
                  set newy=y-NWDistanceRest*Sin(AngleToGo)
                  call SetUnitPosition(dummy,newx,newy)
              elseif IsUnitInRange(Caster,dummy,100)==true then
                  set dummy=GetTableUnit(ttable,"dummy"+I2S(i))
                  call SetUnitFlyHeight(dummy,1600,1000.00)
                  call UnitApplyTimedLife(dummy,'BTLF',4)
              if b!=true then
                  set b=true
              endif
              endif
              set i=i+1
    endloop
    if b==true then
       call ClearTable(ttable)
       call DestroyTimer(t)
    endif
    set dummy=null
    set t=null
    set Caster=null
endfunction





private function NWSpecialEffectsAndCount takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local timer tr=CreateTimer()
    local string trtable=GetAttachmentTable(tr)
    local string ttable=GetAttachmentTable(t)
    local unit dummy
    local unit Caster=GetTableUnit(ttable,"Caster")
    local integer i=0
    local real x=GetUnitX(Caster)
    local real y=GetUnitY(Caster)
    local integer Casting=GetTableInt(ttable,"CastingCount")
    local real Angle=0
    local real tmpangle
    local real startx
    local real starty
    loop
        exitwhen i>NWMaxCircleUnits
                set startx=x+NWAoEForEffects*Cos(Angle)
                set starty=y+NWAoEForEffects*Sin(Angle)
                set tmpangle=bj_RADTODEG*Atan2(y-starty,x-startx)
                set dummy=CreateUnit(GetOwningPlayer(Caster),NWDummyChannel,startx,starty,tmpangle)
                call SetTableObject(trtable,"dummy"+I2S(i),dummy)
                set i=i+1
                set Angle=Angle+10
    endloop
    call SetTableReal(trtable,"xc",x)
    call SetTableObject(trtable,"Caster",Caster)
    call SetTableReal(trtable,"yc",y)
    call SetTableInt(ttable,"CastingCount",Casting+1)
    call TimerStart(tr,0.10,true,function BallsMove)
    set tr=null
    set t=null
    set dummy=null
    set Caster=null
endfunction

private function NWEffects takes nothing returns nothing
    local trigger t=GetTriggeringTrigger()
    local string ttable=GetAttachmentTable(t)
    local unit Caster=GetTableUnit(ttable,"Casterab")
    local timer tr=GetTableTimer(ttable,"Timer")
    local string trtable=GetAttachmentTable(tr)
    local integer Count=GetTableInt(trtable,"CastingCount")
    local real level=GetUnitAbilityLevel(Caster,NWId)
    local unit dummy
    local real x=GetUnitX(Caster)
    local real y=GetUnitY(Caster)
    local group g=CreateGroup()
    local unit w
    call PauseUnit(Caster,true)
    set dummy=CreateUnit(GetOwningPlayer(Caster),NWDummyEffectFs,x,y,270)
    call UnitApplyTimedLife(dummy,'BTLF',10)
    call SetUnitAnimation(dummy,"birth")
    set dummy=CreateUnit(GetOwningPlayer(Caster),NWDummyTree,x,y,270)
    call SetUnitAnimation(dummy,"birth")
    call TriggerSleepAction(1.1)
    call SetUnitAnimation(dummy,"attack")
    call GroupEnumUnitsInRange(g,x,y,NWAoEForDamage,null)
    call UnitApplyTimedLife(dummy,'BTLF',1.5)
    call PauseUnit(Caster,false)
    loop
        set w=FirstOfGroup(g)
        exitwhen w==null
               call GroupRemoveUnit(g,w)
               if IsUnitEnemy(w,GetOwningPlayer(Caster))==true then
                  call UnitDamageTarget(Caster,w,level*DamagePerSecondPerLevel*Count,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,null)
               endif
    endloop
    set dummy=null
    call ClearTable(ttable)
    call ClearTable(trtable)
    call DestroyTimer(tr)
    set tr=null
    call DestroyGroup(g)
    set g=null
    call DestroyTrigger(t)
    set t=null
endfunction

private function Trig_Natures_Wraht_Actions takes nothing returns nothing
    local trigger t=CreateTrigger()
    local timer tr=CreateTimer()
    local string trtable=GetAttachmentTable(tr)
    local string ttable=GetAttachmentTable(t)
    local unit Caster=GetSpellAbilityUnit()
    call SetTableObject(ttable,"Casterab",Caster)
    call SetTableObject(trtable,"Caster",Caster)
    call SetTableObject(ttable,"Timer",tr)
    call TimerStart(tr,1,true,function NWSpecialEffectsAndCount)
    call TriggerRegisterUnitEvent(t,Caster,EVENT_UNIT_SPELL_ENDCAST)
    call TriggerAddAction(t,function NWEffects)
    set t=null
    set tr=null
    set Caster=null
endfunction

//===========================================================================
function InitTrig_Natures_Wrath takes nothing returns nothing
    set gg_trg_Natures_Wrath = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Natures_Wrath, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition(gg_trg_Natures_Wrath,Condition(function Trig_Natures_Wrath_Condition))
    call TriggerAddAction( gg_trg_Natures_Wrath, function Trig_Natures_Wraht_Actions )
endfunction

endscope


I haven't learn structs yet, but i can understand them a little thought.... (If you are going to answer me with somehing with structs)

As you see i use Vexorian Tables system to store multiple units..

Maybe this isn't the best way, but it's the best way i could think :p
EDIT:There are some constant globals that aren't being used, i just forget to delete them :p:

Like these two:
private real NWCircleHeightIncrease=12
private real MaxHeight=800
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
JASS:
Check for casting
    if (OrderId2String(GetUnitCurrentOrder(<UNIT THAT CHANNELS>)) != "channel") then
        // Do whatever it takes to stop the spell, clear up the variables, effects, etc.
    else
        // Continue with the spell
    endif


This works if the spell is based on channel, replace the "channel" part with whatever the spell's order ID is.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top