• 🏆 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] need help with my Stun struct

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
hey, i've made a code that stuns a unit for X time,
then un-stuns it, after the amount of time stated.
it all works good, but for some reason it never unstuns.
any help is appreciated =]

JASS:
library StunTarget initializer OnInit
        
        struct Stun
            private static constant string StunObjectPath = "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl"
            private static thistype c = 0
            private static thistype c2 = 0
            private static integer c3 = 0
            private unit caster = null
            private unit target = null
            private real duration = 0
            private real dps = 0
            private effect eff = null
                static method create takes unit caster, unit target, real duration, real dps returns Stun
                    if IsUnitPaused(target) then
                        set c = c + 1
                        set c3 = c3 + 1
                        set c.caster = caster
                        set c.target = target
                        set c.duration = duration
                        set c.dps = dps
                        call PauseUnit(c.target, true)
                        call IssueImmediateOrder(c.target, "stop")
                        call ResetUnitAnimation(c.target)
                        set c.eff = AddSpecialEffectTarget(StunObjectPath, c.target, "overhead")
                    else
                        return null
                    endif
                    return c
                endmethod
                
                method setTarget takes unit new, boolean unpauselast returns nothing
                    if unpauselast then
                        call PauseUnit(this.target, false)
                    endif
                    set this.target = new
                endmethod
                
                method setCaster takes unit new returns nothing
                    set this.caster = new
                endmethod
                
                method setDuration takes real time returns nothing
                    set this.duration = time
                endmethod
                
                method setDPS takes real damage returns nothing
                    set this.dps = damage
                endmethod
                
                static method onLoop takes nothing returns nothing
                    if c > 0 then
                        loop
                        set c2 = c2 + 1
                            if c2.duration > 0 then
                                set c2.duration = c2.duration - 0.032
                                if c2.dps != 0 then
                                    // not equal to 0, cuz it can heal aswell, while using -
                                    call UnitDamageTarget(c2.caster, c2.target, c2.dps, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
                                endif
                            else
                                call PauseUnit(c2.target, false)
                                set c2.dps = 0
                                set c2.duration = 0
                                set c2.caster = null
                                set c2.target = null
                                call DestroyEffect(c2.eff)
                                set c3 = c3 - 1
                                if c3 == 0 then
                                    set c = 0
                                    set c2 = 0
                                endif
                            endif
                        exitwhen c2 >= c
                        endloop
                    endif
                endmethod
        endstruct
            
    private function OnInit takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.032, true, function s__Stun_onLoop)
    endfunction
endlibrary

thanks in advance :D
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
if your target alrdy is paused you pause again? Reading on my cell so hard to judge but pausing sucks as stun just to point that out :)

Any ways i guess the it never reach the end. Try to set a new target and see if the current one gets unpaused then that one works and you know that the loop is wrong
 
Level 6
Joined
Nov 3, 2008
Messages
117
Well if you don't want any other systems, first of all get rid of pausing units. Its the worst way you could choose for a stun system. Use the creepthunderbolt as a base ability (since it works on magic immunity aswell) and set its duration to 0. Then just create a timer with any duration. When the timer expired just remove the buff of that unit (normally 'BPSE')
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
Well if you don't want any other systems, first of all get rid of pausing units. Its the worst way you could choose for a stun system. Use the creepthunderbolt as a base ability (since it works on magic immunity aswell) and set its duration to 0. Then just create a timer with any duration. When the timer expired just remove the buff of that unit (normally 'BPSE')

Word.
 
Level 6
Joined
Nov 3, 2008
Messages
117
hmm, so what should i do? ;/
i couldnt find a better way to do so..

well static methods actually act like normal functions.
Use them like this: function Struct.function

The example from your code:
call TimerStart(CreateTimer(), 0.032, true, function Stun.onLoop)

As i said befor you should use a dummy spell based on the creepthunderbolt ability. set its duration at both fields (normal/hero) to 0. When you want to stun a unit order a dummy to cast that ability on a unit. Then create a timer that expires after the duration you want the stun stop. When the timer expires remove the Buff with rawcode 'BPSE' from the target. That's the whole deal.
 
Level 6
Joined
Nov 3, 2008
Messages
117
ofc there is. But pausing is just the worst way, because it removes a units command card.
But its up to you.
well you can add buffs to units. but they won't have any effects, unless you added them with the adequate ability. To create a buff that only shows in status bar you create an ability based on the Tornado Slow Aura, set the target fields to self only, add the Buff to the ability, add the aura to a Unit and your done. The buff is shown but doesn't have any effect. If you want to remove the buff simply remove the aura ability.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Why not just use a dummy unit and cast storm bolt instead of working with pause,effect,damage,lines of code...
 
Level 11
Joined
Sep 12, 2008
Messages
657
well.. thats what they told me 1 page ago..
1. cast the spell with a dummy
2. make it run a timer as i did now
3. each timer interval damage the unit dealing the damage.
4. when timer ends, remove buff.
 
Status
Not open for further replies.
Top