Problem with spell.

Carnerox

The one and only.
Reaction score
84
I made a spell which creates a glaive that circles around the caster for #n spins and then is destroyed after, but for some reason, when you cast it sometimes, the glaive will be created, but wont circle around the caster.


Here is the trigger.
JASS:
scope MoonGlaive
    globals
        private constant integer ABIL_ID = 'A003'
        private constant integer GLAIVE_ID = 'h00P'
        private constant real PERIODIC = 0.00235
        private constant string EFFECT_ID = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
        private constant string ATTACHMENT = "chest"
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_HERO
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        private constant weapontype WEAPON_TYPE = null
        private unit GLAIVE
        private group GROUP
    endglobals
    
    native UnitAlive takes unit whitchUnit returns boolean
    
    private function Distance takes nothing returns real
        return 200.00
    endfunction
    
    private function MaxSpins takes integer level returns real
        return 2.00*level+2.00
    endfunction
    
    private function AreaOfEffect takes nothing returns real
        return 160.00
    endfunction
    
    private function Damage takes integer level returns real
        return 120.00
    endfunction

    struct MoonGlaive
        unit caster
        unit glaive
        player owner
        integer level
        integer spins
        real casterX
        real casterY
        real distance
        real angle

        static method onDamage takes nothing returns boolean
            local unit t = GetFilterUnit()
            if (IsUnitEnemy(t,GetOwningPlayer(GLAIVE)) and UnitAlive(t)) and not (IsUnitInGroup(t,GROUP)) then
                call UnitDamageTargetEx(GLAIVE,t,Damage,true,false,ATTACK_TYPE,DAMAGE_TYPE,WEAPON_TYPE)
                call DestroyEffect(AddSpecialEffectTarget(EFFECT_ID,t,ATTACHMENT))
                call GroupAddUnit(GROUP,t)
            endif
            set t=null
            return false
        endmethod
        

        static method onLoop takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local thistype this = GetTimerData(t)
            local real x
            local real y
            set this.casterX=GetUnitX(this.caster)
            set this.casterY=GetUnitY(this.caster)
            if (this.angle>=360.00) then
                set this.angle=0.00
                set this.spins=this.spins+1
                call GroupClear(GROUP)
                if (this.spins>=MaxSpins(this.level)) then
                    call KillUnit(this.glaive)
                    call ReleaseTimer(t)
                    call ReleaseGroup(GROUP)
                    call DestroyGroup(GROUP)
                    call DestroyTimer(t)
                    set t=null
                    set GROUP=null
                endif
            else
                set this.angle=this.angle+1.00
            endif
            set x=this.casterX+Distance()*Cos(this.angle*bj_DEGTORAD)
            set y=this.casterY+Distance()*Sin(this.angle*bj_DEGTORAD)
            call SetUnitX(this.glaive,x)
            call SetUnitY(this.glaive,y)
            set GLAIVE=this.glaive
            call GroupEnumUnitsInArea(GROUP,x,y,AreaOfEffect(),Filter(function thistype.onDamage))
            set t=null
        endmethod
        
        static method onEffect takes nothing returns boolean
            local thistype this = thistype.allocate()
            local timer t = NewTimer()
            local real x
            local real y
            set this.caster=GetTriggerUnit()
            set this.owner=GetOwningPlayer(this.caster)
            set this.level=GetUnitAbilityLevel(this.caster,ABIL_ID)
            set this.casterX=GetUnitX(this.caster)
            set this.casterY=GetUnitY(this.caster)
            set this.angle=0.00
            set this.spins=0
            set x=this.casterX+Distance()*Cos(this.angle*bj_DEGTORAD)
            set y=this.casterY+Distance()*Sin(this.angle*bj_DEGTORAD)
            set this.glaive=CreateUnit(this.owner,GLAIVE_ID,x,y,0.00)
            set GROUP=NewGroup()
            call SetTimerData(t,this)
            call TimerStart(t,PERIODIC,true,function thistype.onLoop)
            set t=null
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            local trigger trig = CreateTrigger()
            call TriggerAddCondition(GT_RegisterStartsEffectEvent(trig,ABIL_ID),Condition(function thistype.onEffect))
        endmethod
    endstruct
endscope
 

Dirac

22710180
Reaction score
147
You're using TimerUtils and you're calling DestroyTimer(t) instead of call ReleaseTimer(t)
I highly suggest you swtich to T32, TU is very slow when it comes to periods
JASS:
scope MoonGlaive
    globals
        private constant integer ABIL_ID = 'A003'
        private constant integer GLAIVE_ID = 'h00P'
        private constant real PERIODIC = 0.00235
        private constant string EFFECT_ID = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
        private constant string ATTACHMENT = "chest"
        private constant attacktype ATTACK_TYPE = ATTACK_TYPE_HERO
        private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_NORMAL
        private constant weapontype WEAPON_TYPE = null
        private unit GLAIVE
        private group GROUP
    endglobals
    
    native UnitAlive takes unit whitchUnit returns boolean
    
    private function Distance takes nothing returns real
        return 200.00
    endfunction
    
    private function MaxSpins takes integer level returns real
        return 2.00*level+2.00
    endfunction
    
    private function AreaOfEffect takes nothing returns real
        return 160.00
    endfunction
    
    private function Damage takes integer level returns real
        return 120.00
    endfunction

    struct MoonGlaive
        unit caster
        unit glaive
        player owner
        integer level
        integer spins
        real casterX
        real casterY
        real distance
        real angle

        static method onDamage takes nothing returns boolean
            local unit t = GetFilterUnit()
            if (IsUnitEnemy(t,GetOwningPlayer(GLAIVE)) and UnitAlive(t)) and not (IsUnitInGroup(t,GROUP)) then
                call UnitDamageTargetEx(GLAIVE,t,Damage,true,false,ATTACK_TYPE,DAMAGE_TYPE,WEAPON_TYPE)
                call DestroyEffect(AddSpecialEffectTarget(EFFECT_ID,t,ATTACHMENT))
                call GroupAddUnit(GROUP,t)
            endif
            set t=null
            return false
        endmethod
        

        method periodic takes nothing returns nothing
            local real x
            local real y
            set this.casterX=GetUnitX(this.caster)
            set this.casterY=GetUnitY(this.caster)
            if (this.angle>=360.00) then
                set this.angle=0.00
                set this.spins=this.spins+1
                call GroupClear(GROUP)
                if (this.spins>=MaxSpins(this.level)) then
                    call KillUnit(this.glaive)
                    call ReleaseTimer(t)
                    call ReleaseGroup(GROUP)
                    call DestroyGroup(GROUP)
                    call .stopPeriodic()
                    set t=null
                    set GROUP=null
                endif
            else
                set this.angle=this.angle+1.00
            endif
            set x=this.casterX+Distance()*Cos(this.angle*bj_DEGTORAD)
            set y=this.casterY+Distance()*Sin(this.angle*bj_DEGTORAD)
            call SetUnitX(this.glaive,x)
            call SetUnitY(this.glaive,y)
            set GLAIVE=this.glaive
            call GroupEnumUnitsInArea(GROUP,x,y,AreaOfEffect(),Filter(function thistype.onDamage))
            set t=null
        endmethod
        implement T32x
        static method onEffect takes nothing returns boolean
            local thistype this = thistype.allocate()
            local real x
            local real y
            set this.caster=GetTriggerUnit()
            set this.owner=GetOwningPlayer(this.caster)
            set this.level=GetUnitAbilityLevel(this.caster,ABIL_ID)
            set this.casterX=GetUnitX(this.caster)
            set this.casterY=GetUnitY(this.caster)
            set this.angle=0.00
            set this.spins=0
            set x=this.casterX+Distance()*Cos(this.angle*bj_DEGTORAD)
            set y=this.casterY+Distance()*Sin(this.angle*bj_DEGTORAD)
            set this.glaive=CreateUnit(this.owner,GLAIVE_ID,x,y,0.00)
            set GROUP=NewGroup()
            call this.startPeriodic()
            set t=null
            return false
        endmethod
        
        private static method onInit takes nothing returns nothing
            call TriggerAddCondition(GT_RegisterStartsEffectEvent(CreateTrigger(),ABIL_ID),Condition(function thistype.onEffect))
        endmethod
    endstruct
endscope
You should use more encapsulation too, must of the methods are public when i consider they shouldn't be. And maybe my new snippet might work for your glaive rotation: TCircles
 

Carnerox

The one and only.
Reaction score
84
I doubt the problem has to do with the rotation I use now, else it wouldn't work at all.
It's just when I first cast it, it works, then after that it either works or not.
 

Dirac

22710180
Reaction score
147
Did you even read my post? : / the circle's thing was just a suggestion... plus the code i posted should fix you spell entirely, but it uses T32 instead
 

BlackRose

Forum User
Reaction score
239
If he uses your code, what will he learn? However, you pointed out the reason anyways:
"You're using TimerUtils and you're calling DestroyTimer(t) and (he does both) [del]instead of[/del] call ReleaseTimer(t)"

What happens when you cast the spell:
A timer in the TimerUtils queue is allocated and run, when the glaive hits the maximum spins, the timer is released AND destroyed. This causes your spell to "sometimes" not work. TimerUtils recycles its timer, ReleaseTimer will simply pause the timer and put it back into the available timers queue. However, since you destroyed the timer, it isn't allocating a timer as you destroyed it. The reason it works "sometimes" is because it considers the 'destroyed timer' in use, and allocates the next available timer (which is working). Eventually you'll run out of timers though, as you can see if you set QUANTITY in TimerUtils to a lower value.​


TL;DR: Don't call [LJASS]DestroyTimer[/LJASS] on TimerUtil timers.

P.S.: If you enable Debug Mode, you'll see you are not using GroupUtils groups properly either.
 

Carnerox

The one and only.
Reaction score
84
Did you even read my post? : / the circle's thing was just a suggestion... plus the code i posted should fix you spell entirely, but it uses T32 instead
I did read it, and I was replying to the suggestion.

BlackRose;13_____ said:
If he uses your code, what will he learn? However, you pointed out the reason anyways:
"You're using TimerUtils and you're calling DestroyTimer(t) and (he does both) [del]instead of[/del] call ReleaseTimer(t)"

What happens when you cast the spell:
A timer in the TimerUtils queue is allocated and run, when the glaive hits the maximum spins, the timer is released AND destroyed. This causes your spell to "sometimes" not work. TimerUtils recycles its timer, ReleaseTimer will simply pause the timer and put it back into the available timers queue. However, since you destroyed the timer, it isn't allocating a timer as you destroyed it. The reason it works "sometimes" is because it considers the 'destroyed timer' in use, and allocates the next available timer (which is working). Eventually you'll run out of timers though, as you can see if you set QUANTITY in TimerUtils to a lower value.​


TL;DR: Don't call [LJASS]DestroyTimer[/LJASS] on TimerUtil timers.

P.S.: If you enable Debug Mode, you'll see you are not using GroupUtils groups properly either.
I'm guessing it has to do the same with DestroyGroup, just like the DestroyTimer problem? Or is it something else?

Anyway thank you both, the spell works correctly now that DestroyTimer is gone.
+rep
 

Laiev

Hey Listen!!
Reaction score
188
Yes, both TimerUtils and GroupUtils can't be destroyed, just released (and don't need to be paused before released) :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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