1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  3. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  4. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  5. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  6. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  7. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Stun System 1.12

Submitted by maddeem
This bundle is marked as substandard. It may contain bugs, not perform optimally or otherwise be in violation of the submission rules.
A channel based stun system.

Pros:
Can be used on any unit or structure, irregardless of invulnerability or status.

Creates one (non periodic) timer for tracking duration & one trigger to track orders (stun, pause, sleep etc). Effectively making it very computationally light.

Cons:
Interrupts orders

Documentation & Code
Code (vJASS):

/*
STUN SYSTEM 1.12
Credits to Maker & IcemanBo for the original concept

API DOCUMENTATION:

public function Unit takes unit u, real dur, boolean stacks returns nothing
    - Stuns a unit using a real duration and boolean for duration stacking.

    - For non-stacking & multiple applications, the highest duration will be applied.

public function End takes unit u returns nothing
    - Immediately ends a stun on a unit.

public function SetRemaining takes unit u, real dur returns nothing
    - Sets the direct duration of a stun.

public function GetRemaining takes unit u returns real
    - Gets the remaining stun duration.

function IsUnitStunned takes unit u returns boolean
    - Returns a unit's stun status.
*/


library Stun initializer init
    globals
        private constant integer SPELL_ID = 'STUN'
        private constant integer ORDER_ID = 852239 //String Order: "request_hero"
        private constant hashtable HASHTABLE = InitHashtable()
        private constant string EFFECT = "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget"
        private constant string EFFECT_POINT = "overhead"
        private timer TIMER
        private conditionfunc CONDITION
    endglobals

    public function End takes unit u returns nothing
        local integer unitId = GetHandleId(u)
        local timer t= LoadTimerHandle(HASHTABLE, unitId, 1)
        local integer timerId = GetHandleId(t)
        local trigger trig = LoadTriggerHandle(HASHTABLE, unitId, 2)
        call DestroyEffect(LoadEffectHandle(HASHTABLE, unitId, 3))
        call FlushChildHashtable(HASHTABLE, timerId)
        call DestroyTimer(t)
        call TriggerClearConditions(trig)
        call DestroyTrigger(trig)
        call FlushChildHashtable(HASHTABLE, unitId)
        call UnitRemoveAbility(u,SPELL_ID)
        set t = null
    endfunction

    private function Elapsed takes nothing returns nothing
        call End(LoadUnitHandle(HASHTABLE, GetHandleId(GetExpiredTimer()), 0))
    endfunction

    private function OrderCheck takes nothing returns boolean
        local trigger trig = GetTriggeringTrigger()
        call DisableTrigger(trig)
        call IssueImmediateOrderById(GetTriggerUnit(), ORDER_ID)
        call EnableTrigger(trig)
        set trig = null
        return false
    endfunction

    public function Unit takes unit u, real dur, boolean stacks returns nothing
        local timer t
        local trigger trig
        local real stunRemain
        local integer unitId = GetHandleId(u)
        local integer i = 0
        if LoadBoolean(HASHTABLE,unitId,0) then
            set t = LoadTimerHandle(HASHTABLE, unitId, 1)
            set stunRemain = TimerGetRemaining(t) - TimerGetElapsed(t)
            call PauseTimer(t)
            if stacks then
                set stunRemain = stunRemain + dur
            elseif stunRemain < dur then
                set stunRemain = dur
            endif
            call TimerStart(t, stunRemain, false, function Elapsed)
        else
            call UnitAddAbility(u,SPELL_ID)
            call IssueImmediateOrder(u,"stop")
            call BlzUnitDisableAbility(u, SPELL_ID, false, false)
            call IssueImmediateOrderById(u, ORDER_ID)
            set trig = CreateTrigger()
            call TriggerRegisterUnitEvent(trig, u, EVENT_UNIT_ISSUED_ORDER )
            call TriggerAddCondition(trig, CONDITION)
            set t = CreateTimer()
            call SaveBoolean(HASHTABLE, unitId, 0, true)
            call SaveTimerHandle(HASHTABLE, unitId, 1, t)
            call SaveTriggerHandle(HASHTABLE, unitId, 2, trig)
            call SaveEffectHandle(HASHTABLE, unitId, 3, AddSpecialEffectTarget(EFFECT,u,EFFECT_POINT))
            call SaveUnitHandle(HASHTABLE, GetHandleId(t),0,u)
            call TimerStart(t, dur, false, function Elapsed)
        endif
        set t = null
        set trig = null
    endfunction

    public function SetRemaining takes unit u, real dur returns nothing
        local timer t= LoadTimerHandle(HASHTABLE, GetHandleId(u), 1)
        call PauseTimer(t)
        call TimerStart(t, dur, false, function Elapsed)
        set t = null
    endfunction

    function IsUnitStunned takes unit u returns boolean
        return LoadBoolean(HASHTABLE, GetHandleId(u),0)
    endfunction

    public function GetRemaining takes unit u returns real
        set TIMER = LoadTimerHandle(HASHTABLE, GetHandleId(u), 1)
        return TimerGetRemaining(TIMER) - TimerGetElapsed(TIMER)
    endfunction

    private function init takes nothing returns nothing
        set CONDITION = Condition( function OrderCheck)
    endfunction
endlibrary
 
Contents

Stun System 1.12 (Map)

  1. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    8,206
    Resources:
    31
    Packs:
    1
    Maps:
    9
    Spells:
    18
    Tutorials:
    3
    Resources:
    31
    How does this stun system works internally?
     
  2. JAKEZINC

    JAKEZINC

    Joined:
    Aug 13, 2013
    Messages:
    1,615
    Resources:
    9
    Spells:
    9
    Resources:
    9
    I can't test this in-game but...

    "A simple stun system that uses a method no other system uses."

    What method exactly?

    "Has no limitation on which targets may be stunned and plays nice with default stun mechanics."

    I don't think you're sure about this judging on the script,
    I wouldn't dive through optimizations as I'm just curious;
    ORDER_ID = 852239
    <- kindly input a prefix or comment of its string equivalent.
    I don't see any stomp or thunderbolt methods here so I guess you're ordering a unit to simulate a fake stun via infinite channel,
    Which is not the same mechanics for original stun, in case I'm not wrong about this. However, If this is correct then it's limited. :]

    Besides, we have dozens of this system already, each with bugs and limitations, as this can't be doable perfectly of bug-free yet.
     
  3. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    It uses infinite channel. I've tested it quite extensively and have not found any issues thus far.

    Channel with infinite follow through time. If cast successfully, the system only uses one, non repeating timer per target.

    If unable to cast, the target will attempt casts every period until able to do so or stun duration ends.
     
    Last edited: Aug 5, 2020
  4. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    8,206
    Resources:
    31
    Packs:
    1
    Maps:
    9
    Spells:
    18
    Tutorials:
    3
    Resources:
    31
    No Object Editor abilities needed right?
     
  5. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    One is required, yes.
     
  6. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,526
    Resources:
    9
    Models:
    1
    Icons:
    2
    Maps:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    9
    Aside from the 'STUN' ability the system comes with, nope.

    Considering the mechanics behind the stun action, this would disrupt shift-queued orders upon stunning, which regular stuns normally respect.
     
  7. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    Correct
     
  8. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    8,206
    Resources:
    31
    Packs:
    1
    Maps:
    9
    Spells:
    18
    Tutorials:
    3
    Resources:
    31
    Ah, what's the difference with the normal channel then? The latest version prevents older editors from opening the map as far as I am aware.
     
  9. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    Follow through time infinite and disable other abilities = true
     
  10. Daffa

    Daffa

    Joined:
    Jan 30, 2013
    Messages:
    8,206
    Resources:
    31
    Packs:
    1
    Maps:
    9
    Spells:
    18
    Tutorials:
    3
    Resources:
    31
    Thanks!
     
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,532
    Resources:
    23
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    5
    JASS:
    3
    Resources:
    23
  12. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    Possibly, if it uses channel as the ability cast. I'm away from my computer rn so I can't check.
     
  13. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,526
    Resources:
    9
    Models:
    1
    Icons:
    2
    Maps:
    2
    Spells:
    3
    JASS:
    1
    Resources:
    9
    Both abilities are based on the channel ability, with different base order ids.
     
  14. JAKEZINC

    JAKEZINC

    Joined:
    Aug 13, 2013
    Messages:
    1,615
    Resources:
    9
    Spells:
    9
    Resources:
    9
    Tested it or not, the logic of ordering a unit itself to simulate a stun-like mechanic to itself is already prone to fail at some cases.
    Plus, this breaks the order rather than retaining it, it also blacks out the command card which is not the case for original stun...

    I kinda disapprove the method you chose for stunning units, it would be good for pausing units though, which is already known.
     
  15. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    This system accounts for failed casts. But valid points beyond that.

    Here I thought this was an original idea lol. I can make a list of pro/cons of using this method if the system won't be outright rejected. (And credit IcemanBo)
     
    Last edited: Aug 5, 2020
  16. JAKEZINC

    JAKEZINC

    Joined:
    Aug 13, 2013
    Messages:
    1,615
    Resources:
    9
    Spells:
    9
    Resources:
    9
    While it's a good thing you've taken it into consideration, I don't think it would be good enough for the unit's inability to execute the order.
    Take this for sleeping or silenced units for example, they couldn't execute an order from their state which would just generate an overhead.
    A timer runs as they couldn't execute an order and would only be destroyed if the order is successful, otherwise if duration elapsed it'll linger.
    It's a fine idea but not that reliable to replace or at least simulate a stun. Before making a public system make sure to check for the others.
    You may stick to this and wait for the moderator's verdict or at least update it with exemplary features that would make it shine from the rest.

    (These statements are just my point of view though. Just criticizing this as I'm just curious on what method you've done here in the first place)
     
  17. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    Very fair points. You're right, I had not considered silence. Maybe I'll rework this with another method I was considering.

    Edit: silence does not affect channel if it has universal cast enabled, I'll update this as soon as I can with the silence fix. (If this was fixed, another option is to enable the ability with the new natives)

    I also have a fix to remove the additional timer. Also the timer at the moment does not linger, it is destroyed when the duration ends.
     
    Last edited: Aug 5, 2020
  18. JAKEZINC

    JAKEZINC

    Joined:
    Aug 13, 2013
    Messages:
    1,615
    Resources:
    9
    Spells:
    9
    Resources:
    9
    Yeah, I've also read that from somewhere else claiming it. I didn't tested it yet but you may try it here and then prove if it works. (I hope so)
    Didn't notice you're destroying two timers even the other one is only created if a condition is met, otherwise you're destroying a non-existent.
     
  19. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,324
    Resources:
    6
    Icons:
    1
    Maps:
    2
    Spells:
    3
    Resources:
    6
    Destroying a null timer is less computationally taxing then checking a comparison then destruction imo. But seeing as missed casts may be rare, it may not be for this scenario