System CustomStun System

Joker(Div)

Always Here..
Reaction score
86
CustomStun System
By: Joker(Div)

An extremely short and simple CustomStun System. All the info is written on the code.

Screenshot:
customstunex.jpg

Code:
JASS:
//==============================================================================
//                    CUSTOMSTUN SYSTEM BY JOKER(DIV) -- v1.3
//==============================================================================
//
//  PURPOSE:
//       * Easy stunning
//       * Customizable stun duration without 99 lvls of storm bolt
//       * (Instead uses 1 lvl storm bolt)
//
//  HOW TO USE:
//       * function CustomStun_Unit takes unit attacker, unit target, string sfx, string attach, real duration returns nothing
//
//         Yep, 1 function.
//
//  PROS: 
//       * Extremelly easy to use
//       * Short simple script
//       * Customizable sfx
//
//  CONS:
//       * You still need a 1 level storm bolt
//       * Has a delta value, although its configureable
//       * Cannot go through magic immunity
//       * Buff icon cannot change regardless of what sfx used
//
//  DETAILS:
//       * It... 
//            - Casts a permanent storm bolt to the target
//            - Creates a timer for the instance
//            - Removes the stun buff after duration
//         
//  REQUIREMENTS:
//       * vJASS              (Vexorian)
//       * TimerUtils         (Vexorian)
//       * PUI v5.0 or higher (Cohadar)
//
//  HOW TO IMPORT:
//       * Just create a trigger named CustomStun
//       * convert it to text and replace the whole trigger text with this one
//
//==============================================================================
library CustomStun uses TimerUtils, PUI

    //! runtextmacro PUI_PROPERTY("private", "real", "Stunned", "0.")

    globals
        private constant real       Delta       = 0.25       //Interval of the timer, thus, delta value
        private constant integer    Dummy_Id    = 'n000'    //Dummy ID
        private constant real       Dummy_Dur   = 1.        //Dummy duration
        private constant integer    Bolt_Id     = 'A000'    //Storm bolt ID
        private constant integer    Buff_Id     = 'B000'    //Stun buff Id
    endglobals
    
    private struct Stun
        unit targ
        timer t
        effect ef
        
        static method start takes unit targ, effect ef returns nothing
            local Stun dat = Stun.create()
            
              set dat.targ = targ
              set dat.t = NewTimer()
              set dat.ef = ef

            call SetTimerData( dat.t, dat )
            call TimerStart( dat.t, Delta, true, function Stun.callback )
        endmethod
    
        private static method callback takes nothing returns nothing
            local timer t = GetExpiredTimer()
            local Stun dat = GetTimerData( t )
            
            if GetWidgetLife( dat.targ ) < 0.405 or Stunned[ dat.targ ] < Delta then //If dead or met duration
                call dat.destroy()
                return 
            endif
            
            set Stunned[ dat.targ ] = Stunned[ dat.targ ] - Delta
        endmethod
        
        private method onDestroy takes nothing returns nothing
            call UnitRemoveAbility( .targ, Buff_Id )  //Remove buff, stopping stun
            call DestroyEffect( .ef )
            call ReleaseTimer( .t )
        endmethod
    endstruct
    
    public function Unit takes unit attacker, unit target, string sfx, string attach, real duration returns nothing
        local unit dummy
        
        if Stunned[target] <= 0. and IsUnitType( target, UNIT_TYPE_MAGIC_IMMUNE ) == false then //Storm bolt cannot ever go through Magic Immune
            set Stunned[ target ] = 0.  //Safety
            set dummy = CreateUnit( GetOwningPlayer(attacker), Dummy_Id, GetUnitX( target ), GetUnitY( target ), bj_UNIT_FACING )
            
            call UnitAddAbility( dummy, Bolt_Id ) //The dummy stuff
            call IssueTargetOrder( dummy, "thunderbolt", target )
            call UnitApplyTimedLife( dummy, 'BTLF', Dummy_Dur )
            call Stun.start( target, AddSpecialEffectTarget( sfx, target, attach ) )
        endif
        
        set Stunned[target] = (Stunned[target] + duration)
        set dummy = null
    endfunction

endlibrary

Changelog:
< 1.3 >
*A bug fix
*Miniscule improvement

< 1.2 >
*Small improvements
*Allows custom stunned effects

< 1.1 >
*Minor bug fix

Requirements:
 

Attachments

  • CustomStun System - Joker(Div).w3x
    30 KB · Views: 294

Azlier

Old World Ghost
Reaction score
461
There's no Stun special effect? Frowny Face.
 

Azlier

Old World Ghost
Reaction score
461
Why don't you use a triggered effect? Makes it a whole lot more flexible.
 

Romek

Super Moderator
Reaction score
963
I agree with using a triggered effect.
Also, this could easily be made system independent.
Use a static timer, and a struct array. :)
Then loop through the active structs.
 

Viikuna

No Marlo no game.
Reaction score
265
Ye, If you were making a buff system with loads of buffs with different periods, TimerUtils would be good. But since this is only a stun system you should use static timer loop.
 

XeNiM666

I lurk for pizza
Reaction score
138
looks cool. But just 1 suggestion: can you make like a with every custom stun, you get to pick the effect. Sample: I use your custom stun on the target and choose the Banish effect as the stun buff..
 

Hatebreeder

So many apples
Reaction score
381
I kinda forgot alot about Jass...
Well, whatever...
I've got a Question:
If a Unit is stunned 2 times, will the stun duration add up? (Ex, 2 "Custom Storm Bolts" hitting one unit, each stunning for 3 seconds, total stun duration of 6 seconds?)
 

Blackrage

Ultra Cool Member
Reaction score
25
@ Hatebreeder:

There is a boolean constant in the configurables that let you configure if you want the stuns to stack or not.
 

Joker(Div)

Always Here..
Reaction score
86
I agree with using a triggered effect.
Also, this could easily be made system independent.
Use a static timer, and a struct array. :)
Then loop through the active structs.
I've having some trouble doing this. :( How do I check if a struct is active?

Edit: Minor update, fixed a bug. Expect the big change sometime this week (before Sunday).
 

Tukki

is Skeleton Pirate.
Reaction score
29
Notice that using TimerUtils will actually be faster if you stun more than 4 units simultaneously, or at least have 4+ structs allocated. I also like that you use methods instead of crappy functions, but maybe you should provide some external functions for the user.

Also delete one of those PUI_PROPERTY lines, and make the remaining an integer instead, and use it to store the unit's struct in it. Like:
JASS:
set SOME_NAME[stunned] = integer(struct) // when starting, typecast to integer
set SOME_NAME[stunned] = 0 // 0 as struct-indexes range from 1 to 8190.

Then it should be easy to decide if a unit is stunned, and increase duration if so:
JASS:
method IsStunned takes unit who returns boolean
    return SOME_NAME[who]!=0
endmethod

But remember to typecast back when using the struct later on:
JASS:
set SOME_NAME[who].dur = 5 // will not work
set Stun(SOME_NAME[who]).dur = 5 // will work


As for the effect, make two functions: one normal and one extended. The normal will stun with a default effect, while the extended allows you to change it.

Finally, please check if the unit has the stun buff, else dispelling won't work. Other than that, it is pretty neatly done. Good job :thup:

===========================================

I agree with using a triggered effect.
Also, this could easily be made system independent.
Use a static timer, and a struct array.
Then loop through the active structs.
Making this system independent is just wrong, why do these libraries exists anyway? And if you stun the unit while it's stunned, you'll have to search through the n long array for your struct. Which is faster if you have less than 5 units stunned at a time, though.
 

Joker(Div)

Always Here..
Reaction score
86
@Finally, please check if the unit has the stun buff, else dispelling won't work.
Why wouldn't it work?

Update!
I don't know what you were saying with the typecast, but I still removed 1 PUI call. I also allowed custom effects, but now it requires a blank stun buff. New screeny
 

Tukki

is Skeleton Pirate.
Reaction score
29
Typecasting is basically about the time when Vexorian wanted vJass to be typecast safe, not sure if it's required anymore though.

The struct type can be seen as an integer.
JASS:
struct myStruct
     integer mass
endstruct

private function somefunc takes nothing returns nothing
     local integer data1     // integer type
     local myStruct data2  // struct type

     set data2 = myStruct.create() // allocate a struct, and set it
     set data1 = myStruct.create() // will not work, you&#039;ll have to do:
     set data1 = integer(myStruct.create()) // to get the index of the struct (1-8190)
     set data1 = integer(data2) // will also work but

     set integer(myStruct.create()).mass = 33 // won&#039;t work, as it&#039;s in integer type but if you:
     set data1 = integer(myStruct.create())
     set myStruct(data1).mass = 33 // it will work

     //so the thing here is that PUI_PROPERTY takes the integer type, not struct type
     //if we want to convert our stored integer we&#039;ll have to typecast it back to a struct
     set data2 = myStruct(STORAGE[unit]) // typecasting from integer to struct
     set data1 = integer(data2)                // typecasting from struct to integer


JNGP won't allow you to use integers to behave as structs, but if you typecast them - it will.

Why wouldn't it work?
I meant that the timer will still run every X seconds.

One last thing, the 'real dur' is pretty useless, just make the Stunned count down instead - the WC3 internal stun management is not really good, but it's your call.
 

Joker(Div)

Always Here..
Reaction score
86
@One last thing, the 'real dur' is pretty useless, just make the Stunned count down instead
Why can't I think of these...

@the WC3 internal stun management is not really good, but it's your call.
You mean don't use storm bolt?
 

Tukki

is Skeleton Pirate.
Reaction score
29
Nah, you refer to the Stunned variable when a new stun is throwed at an already stunned unit. If the new stun is > than Stunned then switch. <-- This is the original WC3 stun management, stun durations never stack. Only a higher stun can replace another.

Else it's looking good, +rep!
 

D.V.D

Make a wish
Reaction score
73
Couldn't you make this not use a ability like storm bolt so we don't need to import a ability? Make the stun out of triggers and if possible, add the buff the player chooses.
 

Flare

Stops copies me!
Reaction score
662
Couldn't you make this not use a ability like storm bolt so we don't need to import a ability? Make the stun out of triggers and if possible, add the buff the player chooses.

1) Only thing that could possibly be regarded as stunning solely through the use of triggering would be pausing the unit, but that's not ideal. It doesn't work exactly like your normal stun, and it removes a unit's command card while the unit is paused (which is less than ideal, mainly because people have the impression that it's ugly ¬_¬)

2) There's no way to apply a buff to a unit without a dummy spell, so if you want a buff, a spell is required
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top