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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top