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.
  • 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
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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