System Stun Library

D.V.D

Make a wish
Reaction score
73
Stun Library

Thanks to uberfoop for helping me fix my struct problem which allowed me to test my functions after.

Have fun with stuning your enemies.

JASS:
library Stun initializer Init requires TimerUtils

//==========================================================================\\
//                         Stun Library By D.V.D                            \\
//==========================================================================\\
// Description:                                                             \\
// The Stun Library allows you to stun units without the use of spells or   \\
// units. This allows you to stop the stun at a certian period and even     \\
// pausing and resuming your stun. With this code, you are able to fully    \\
// customize your stun so it fits the spells that will use this in your map.\\
//==========================================================================\\
// Pros:                                                                    \\
// - Does not use dummy units                                               \\
// - Does not use custom abilities                                          \\
// - Does not use custom buffs but they can be added.                       \\
// - Allows you to fully customize your stun like pausing and resuming      \\
//==========================================================================\\
// Functions:                                                               \\
// static method StunUnit takes unit target, real time, real damage,        \\
// attacktype type1, damagetype type2, string effect, string attachment     \\
//                                                         returns stun     \\
// method PauseStun takes nothing returns nothing                           \\
// method ResumeStun takes nothing returns nothing                          \\
// method ChangeEffect takes string effect returns nothing                  \\
// method ChangeAttachment takes string attachment returns nothing          \\
//==========================================================================\\
// How to Implement:                                                        \\
// 1. Copy the code in this trigger                                         \\
// 2. Create A New Trigger In Your Map                                      \\
// 3. Convert the trigger to Jass and Paste this code over the trigger code \\
// 4. Click the check mark for the Run on Map Initialization button         \\
// 5. Have fun! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />                                                          \\
//==========================================================================\\
        struct stun
            attacktype type1
            damagetype type2
            effect e1
            integer count
            real damage
            real time
            string attachment
            string e
            timer p
            unit caster
            unit target
            
//===========================================================================
            method onDestroy takes nothing returns nothing
                set .type1 = null
                set .type2 = null
                call DestroyEffect(.e1)
                call ReleaseTimer(.p)
            endmethod
        
//===========================================================================
        static method Stunned takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local stun d = GetTimerData(t)
            
            call IssueImmediateOrder( d.target, &quot;stop&quot; )
            set d.count = d.count + 1
            
            if ( d.count / 100 == R2I( d.time ) ) then
                call ReleaseTimer(t)
                call d.destroy()
            elseif ( IsUnitAliveBJ( d.target ) == false ) then
                call ReleaseTimer(t)
                call d.destroy()
            endif
        endmethod
        
//===========================================================================
        static method StunUnit takes unit caster, unit target, real time, real damage, attacktype type1, damagetype type2, string e, string attachment returns stun
            local stun d = stun.create()
            local timer t = NewTimer()
            
            set d.attachment = attachment
            set d.caster = caster
            set d.count = 0
            set d.damage = damage
            set d.e = e
            set d.p = NewTimer()
            set d.target = target
            set d.time  = time
            set d.type1 = type1
            set d.type2 = type2
            
            set d.e1 = AddSpecialEffectTarget( d.e, d.target, d.attachment )
            call UnitDamageTarget( d.caster, d.target, d.damage, true, false, d.type1, d.type2, null )
            call SetTimerData( d.p, d )
            call TimerStart( d.p, 0.01, true, function stun.Stunned )
            
            return d
        endmethod
        
//===========================================================================
        method PauseStun takes nothing returns nothing
            call PauseTimer( .p )
            call DestroyEffect(.e1)
        endmethod
        
//===========================================================================
        method ResumeStun takes nothing returns nothing
            call ResumeTimer( .p )
            call AddSpecialEffectTarget( .e, .target, .attachment )
        endmethod
        
//===========================================================================
        method ChangeEffect takes string e returns nothing
            call DestroyEffect(.e1)
            set .e1 = AddSpecialEffectTarget( e, .target, &quot;origin&quot; )
        endmethod
        
//===========================================================================
        method ChangeAttachment takes string attachment returns nothing
            call DestroyEffect(.e1)
            set .e1 = AddSpecialEffectTarget( .e, .target, attachment )
        endmethod
        
    endstruct

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
    endfunction

endlibrary
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
//===========================================================================
        method PauseStun takes nothing returns nothing
            //call PauseTimer( s.t )
        endmethod
        
//===========================================================================
        method ResumeStun takes nothing returns nothing
            //call ResumeTimer( s.t )
        endmethod
He just wants us to FEEL like we have that functionality... ;)

Edit: Errr....
Original code:
JASS:
library Stun initializer Init requires TimerUtils

//==========================================================================\\
//                         Stun Library By D.V.D                            \\
//==========================================================================\\
// Description:                                                             \\
// The Stun Library allows you to stun units without the use of spells or   \\
// units. This allows you to stop the stun at a certian period and even     \\
// pausing and resuming your stun. With this code, you are able to fully    \\
// customize your stun so it fits the spells that will use this in your map.\\
//==========================================================================\\
// Pros:                                                                    \\
// - Does not use dummy units                                               \\
// - Does not use custom abilities                                          \\
// - Does not use custom buffs                                              \\
// - Allows you to fully customize your stun like pausing and resuming      \\
//==========================================================================\\
// Functions:                                                               \\
// static method StunUnit takes unit target, real time, real damage,        \\
// attacktype type1, damagetype type2, string effect, string attachment     \\
//                                                         returns stun     \\
// method PauseStun takes nothing returns nothing                           \\
// method ResumeStun takes nothing returns nothing                          \\
// method ChangeEffect takes string effect returns nothing                  \\
// method ChangeAttachment takes string attachment returns nothing          \\
//==========================================================================\\
// How to Implement:                                                        \\
// 1. Copy the code in this trigger                                         \\
// 2. Create A New Trigger In Your Map                                      \\
// 3. Convert the trigger to Jass and Paste this code over the trigger code \\
// 4. Have fun! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />                                                          \\
//==========================================================================\\
        struct stun
            attacktype type1
            damagetype type2
            effect e1
            integer count
            real damage
            real time
            string attachment
            string e
            timer p
            unit target
            
//===========================================================================
            method onDestroy takes nothing returns nothing
                set .type1 = null
                set .type2 = null
                call DestroyEffect(.e1)
                call ReleaseTimer(.p)
            endmethod
        
//===========================================================================
        static method Stunned takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local stun d = GetTimerData(t)
            
            call IssueImmediateOrder( d.target, &quot;stop&quot; )
            set d.count = d.count + 1
            
            if ( d.count / 100 == R2I( d.time ) ) then
                call ReleaseTimer(t)
                call d.destroy()
            elseif ( IsUnitAliveBJ( d.target ) == false ) then
                call ReleaseTimer(t)
                call d.destroy()
            endif
        endmethod
        
//===========================================================================
        static method StunUnit takes unit target, real time, real damage, attacktype type1, damagetype type2, string e, string attachment returns stun
            local stun d = stun.create()
            local timer t = NewTimer()
            
            set d.attachment = attachment
            set d.count = 0
            set d.damage = damage
            set d.e = e
            set d.target = target
            set d.time  = time
            set d.type1 = type1
            set d.type2 = type2
            
            set d.e1 = AddSpecialEffectTarget( d.e, d.target, d.attachment )
            call SetTimerData( t, d )
            call TimerStart( t, 0.01, true, function stun.Stunned )
            
            return d
        endmethod
        
//===========================================================================
        method PauseStun takes nothing returns nothing
            //call PauseTimer( s.t )
        endmethod
        
//===========================================================================
        method ResumeStun takes nothing returns nothing
            //call ResumeTimer( s.t )
        endmethod
        
//===========================================================================
        method ChangeEffect takes string e returns nothing
            call DestroyEffect(.e1)
            set .e1 = AddSpecialEffectTarget( e, .target, &quot;origin&quot; )
        endmethod
        
//===========================================================================
        method ChangeAttachment takes string attachment returns nothing
            call DestroyEffect(.e1)
            set .e1 = AddSpecialEffectTarget( .e, .target, attachment )
        endmethod
        
    endstruct

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger(  )
    endfunction

endlibrary
You spam the stop order? Hmm. Doesn't really resemble a WC3 style stun... In a WC3 style stun, you can change the unit's current order. With this, you may as well use PauseUnit.

I was disappointed because you should be able to write a perfectly good stun system using an object merger line for an infinite duration stun, and then buff removal. Also, you've tried to do too much here with dealing damage.
 

D.V.D

Make a wish
Reaction score
73
Woops, posted the wrong code. Damn I overwrote this code with my good one. Wait Ill update soon. No it doesn't look choppy when the unit won't move at all.
 

D.V.D

Make a wish
Reaction score
73
Ok sorry about that. Updated with the new version. About the leaking trigger, should I simply remove it or will it not work on Map Initialization anymore?

EDIT: I got a idea to stop spamming the stop order. Ill update anotehr version soon.
 

Azlier

Old World Ghost
Reaction score
461
You need a storm bolt with an infinite duration. That's how our tried and true stun systems work.

You reinvented the wheel, except this one is square.
 

D.V.D

Make a wish
Reaction score
73
Im working on making the system not need a custom spell. I figured out how to do it and Im working on it so maybe by tomorrow Ill have it posted.
 

Azlier

Old World Ghost
Reaction score
461
How? PauseUnit is bad. Mass stop is bad. Storm Bolt is good. Is there any other alternative?
 

D.V.D

Make a wish
Reaction score
73
There is but I can't seem to test it cause even when I save my map, it won't open the map. I'll try fixing this as soon as possible, test to see if what I thought might make this work without pausing or stopping the unit work.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Even if there is an alternative, actual stun is generally the way to go, since, you know, apart from not having a flashing buff icon as it wears off (which is almost always irrelevant with stuns anyway), it emulates stunning perfectly.
 

D.V.D

Make a wish
Reaction score
73
Meh, I wanted to try make something new and the thing I hated about the stuns were that you gotta import the ability. I'll atleast try to finish this. BTW, could anyone tell me how to disabel RTC in NewGen so I could finally test the map?

And if you use a normal spell, you can't pause, resume, change effect, or change attachments during the stun. Thats a advantage this system has that the other stun systems don't have.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
And if you use a normal spell, you can't pause, resume, change effect, or change attachments during the stun. Thats a advantage this system has that the other stun systems don't have.
Sure you can. Just put the same functionality in without the pause, and for adding and removing the stun you can just remove the buff and recast when it's resumed.
 

D.V.D

Make a wish
Reaction score
73
Different effects and attachments can't be maid through the ability and Im not sure you can Add a buff using triggers without casting another ability.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
I know that. And it in no way challenges anything in my post. I didn't say the stun ability wouldn't be cast again or that the effects wouldn't be added via triggers in that case.
 

Jesus4Lyf

Good Idea™
Reaction score
397
doingitwrong.jpg
This really isn't the right way to do stun. Graveyarded.

Personal opinion:
Ideal interface:
JASS:
function Stun takes unit target, real duration returns nothing

Or better yet:
JASS:
function AddStun takes unit target returns nothing
function RemoveStun takes unit target returns nothing

So you can use a periodic function to add a level of stun or remove it as you see fit. See stack safety and implement attaching an integer to a unit. Effects can then be handled by the triggers running the show.

To-do lists it.

In regards to importing the ability, it should be done with object merger, a modified firebolt or the like. :)
 

Jesus4Lyf

Good Idea™
Reaction score
397
Because when you're just iterating through a list of structs, simpler things like a basic struct stack or PeriodicModule are better.
No, it depends what your goal is. Iterating through a linked list is faster if it is a doubly linked list (unless your singularly linked list never has elements removed).
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Assuming that the entry and exit from the stack is done externally and the actions were carried out inside the same function that loops through the stack, a struct stack would probably be slightly faster :)
Granted, that's a garbage interface to work with and usefulness converges to 0.


Not very useful thing in question:
JASS:

function Callback takes nothing returns nothing
    local integer i = 0
    local struct s
    //potentially other stuff
    loop
        exitwhen i &gt; Quantity
        set s = Stack<i>
        //stuff
        set i = i + 1
    endloop
endfunction

method Add takes nothing returns nothing
    set Quantity = Quantity + 1
    set Active[Quantity] = this
    set .Index = Quantity
endmethod

method Remove takes nothing returns nothing
    set Active[.Index] = Active[Quantity]
    set Quantity = Quantity - 1
    //possibly set .Index to -1 here depending on the system to denote exit
endfunction
</i>
 
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