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: 292

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
380
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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      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