1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Music Contest #10 - Results are finally published! Drop by to check some retro songs and congratulate the winners!
    Dismiss Notice
  3. Join Terraining Contest #19 and witness the aftermath!
    Dismiss Notice
  4. The 3rd Melee Mapping Contest is ON! Join in on a ride of a 4v4 melee experience!
    Dismiss Notice
  5. The 30th edition of the Modeling Contest is finally up! The Portable Buildings need your attention, so come along and have a blast!
    Dismiss Notice

Disarmament v1.1

Submitted by IcemanBo, ukn0wnD3str0y3r
This bundle is marked as approved. It works and satisfies the submission rules.
READ FIRST: Link


Introduction

There are some resources on hive which have a good idea, but are not implemented very good.
I want to re-create some of them from which I think are useful. I will mark the original author as co-author.
That's one of these resources.

Credits to ukn0wnD3str0y3r, from who's submission I have the idea.
The original implementation: www.hiveworkshop.com/threads/disarm-system-v1-0-4.260483/

Information

A snippet to temporary disable a unit's attack.

Triggers

Note:
The system is written in JASS, but it can be used easily with GUI. Test the map for a demonstration.

Code (vJASS):

library Disarmament  /* v1.1

    Information
    ¯¯¯¯¯¯¯¯¯¯¯

        A snippet to temporary disable a unit's attack.
        Also provides you a set and get function to have more managing powers.
        The system does not work with units which already have the cargo ability. See "Applied method".
 
        It's for JASS users, but it's also GUI compatible. See Config a few lines later.
 
 
    Applied method
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
 
        The system will temporary add 'Abun' (orc-cargo) ability to a unit to disabled it's attack.
        Therefore it won't work for units which already have the 'Abun' ability by default.
 
 
    Credits:
    ¯¯¯¯¯¯¯¯
 
        Credits to ukn0wnD3str0y3r, from who's submission I have the idea.
        The original implementation: hiveworkshop.com/threads/disarm-system-v1-0-4.260483/
 
        Resources:
 
            - Bribe
            - Vexorian
 

*/
requires /*

        */
Table        /* hiveworkshop.com/threads/snippet-new-table.188084/
        */
TimerUtils   /* wc3c.net/showthread.php?t=101322
 

    struct Disarmament
 
 
        Usage:
            static method getDuration takes unit u returns real
            static method setDuration takes unit u, real duration returns boolean
 
                - negative duration means infinite, for both "set" and "get"
                - duration "0" means instant removal
                - "setDuration" won't do nothing and return "false" if the unit already has the cargo ability.
         
            static method isUnitDisarmed takes unit u returns boolean
 
 
        Code registration (will run when the time expires):
 
            static method register takes boolexpr be returns triggercondition
            static method unregister takes triggercondition t returns nothing
 
        readonly:
 
            unit
                (the unit to refer to in registarted code.
                  e.g.: call KillUnit(Disarmament.unit)
           
 
*/

//================= Config ======================//

    globals
        private constant boolean GUI    = true      // allows to work with the GUI variables
                                                    // look at "GUI Demo" folder for an example.
    endglobals

 
//=============== End  Config ======================//


    struct Disarmament extends array

        private static Table TABLE
        public static unit unit
        private static constant trigger t = CreateTrigger()
        private static constant integer DISARM_ID = 'Abun'
        private static constant group GROUP = CreateGroup()
        private static method callback takes nothing returns nothing
     
            local timer clock = GetExpiredTimer()
            local integer clockId = GetHandleId(clock)
            local unit u = thistype.TABLE.unit[clockId]
            local integer unitId = GetHandleId(u)
     
            call UnitRemoveAbility(u, DISARM_ID)
            call GroupRemoveUnit(GROUP, u)
            static if GUI then
                set udg_DA_Unit = u
                set udg_DA_Event = 1
                set udg_DA_Event = 0
            endif
            set thistype.unit = u
            call TriggerEvaluate(thistype.t)
     
            call thistype.TABLE.handle.remove(unitId)
            call thistype.TABLE.handle.remove(clockId)
            call ReleaseTimer(clock)
            set u = null
        endmethod
 
        static method getDuration takes unit u returns real
            if thistype.TABLE.timer.has(GetHandleId(u)) then
                // common return value
                return TimerGetRemaining(thistype.TABLE.timer[GetHandleId(u)])
            else
                // no timer exists, because the value is negative (infinite duration)
                return thistype.TABLE.real[GetHandleId(u)]
            endif
        endmethod
 
        static method setDuration takes unit u, real duration returns boolean
            local integer parentKey = GetHandleId(u)
            local timer clock = thistype.TABLE.timer[parentKey]
     
            if not (duration != 0) then
     
                if thistype.TABLE.real.has(parentKey) then
                    call thistype.TABLE.real.remove(parentKey)
                endif
         
                if (clock != null) then
                    call thistype.TABLE.handle.remove(parentKey)
                    call thistype.TABLE.handle.remove(GetHandleId(clock))
                    call ReleaseTimer(clock)
                endif
         
                if UnitAddAbility(u, DISARM_ID) or IsUnitInGroup(u, GROUP) then
                    call UnitRemoveAbility(u, DISARM_ID)
                    call GroupRemoveUnit(GROUP, u)
             
                    static if GUI then
                        set udg_DA_Unit = u
                        set udg_DA_Event = 1
                        set udg_DA_Event = 0
                    endif
                    set thistype.unit = u
                    call TriggerEvaluate(thistype.t)
                    return true
                else
         
                    // The system should not do anything if the unit already has cargo ability but is not even registered here.
             
                    debug call BJDebugMsg("[ERRROR] Disarmament: Units with cargo ability are not allowed to be registered.")
             
                    return false
                endif
         
            else
                if not UnitAddAbility(u, DISARM_ID) and not IsUnitInGroup(u, GROUP) then
             
                    // Else we would later remove the Disarm ability, even the unit already had it before it was registered.
             
                    debug call BJDebugMsg("[ERRROR] Disarmament: Units with cargo ability are not allowed to be registered.")
         
                    return false
                endif
            endif
 
            call GroupAddUnit(GROUP, u)
     
            if (duration > 0) then
         
                if (clock == null) then
                    set clock = NewTimer()
                    set thistype.TABLE.timer[parentKey] = clock
                    set thistype.TABLE.unit[GetHandleId(clock)] = u
                endif
         
                // In case it had a permanent flag before we need to remove the saved value
         
                if thistype.TABLE.real.has(parentKey) then
                    call thistype.TABLE.real.remove(parentKey)
                endif
         
                call TimerStart(clock, duration, false, function thistype.callback)
         
            else

        //      If a timer exists we don't need it at this point anymore
        //           (infinite duration)
 
                if (clock != null) then
                    call thistype.TABLE.handle.remove(parentKey)
                    call thistype.TABLE.handle.remove(GetHandleId(clock))
                    call ReleaseTimer(clock)
                endif
             
        //      instead, we just attach the duration to the unit
         
                set thistype.TABLE.real[parentKey] = duration
         
            endif
            return true
        endmethod
 
        static if GUI then
            private static method setData takes nothing returns nothing
                call setDuration(udg_DA_Unit, udg_DA_Duration)
                set udg_DA_IsUnitDisarmed = IsUnitInGroup(udg_DA_Unit, GROUP)
            endmethod
     
            private static method getData takes nothing returns nothing
                set udg_DA_Duration = getDuration(udg_DA_Unit)
                set udg_DA_IsUnitDisarmed = IsUnitInGroup(udg_DA_Unit, GROUP)
            endmethod
     
            private static method init takes nothing returns nothing
                set udg_DA_GetData = CreateTrigger()
                set udg_DA_SetData = CreateTrigger()
                call TriggerAddAction(udg_DA_GetData, function thistype.getData)
                call TriggerAddAction(udg_DA_SetData, function thistype.setData)
                call ReleaseTimer(GetExpiredTimer())
            endmethod
        endif
 
        private static method onInit takes nothing returns nothing
            static if GUI then
                call TimerStart(NewTimer(), 0, false, function thistype.init)
            endif
            set TABLE = Table.create()
        endmethod
 
        static method register takes boolexpr be returns triggercondition
            return TriggerAddCondition(thistype.t, be)
        endmethod
 
        static method unregister takes triggercondition tc returns nothing
            call TriggerRemoveCondition(thistype.t, tc)
        endmethod
 
        static method isUnitDisarmed takes unit u returns boolean
            return IsUnitInGroup(u, GROUP)
        endmethod
 
    endstruct
endlibrary
 


Readme for GUI

Code (Text):

Infoormation:
¯¯¯¯¯¯¯¯¯¯

    A snippet to temporary disable a unit's attack.
    Also provides you a set and get function to have more managing powers.


Applied method
¯¯¯¯¯¯¯¯¯¯¯¯
    The system will temporary add 'Abun' (orc-cargo) ability to a unit to disabled it's attack.
    Therefore it won't work for units which already have the 'Abun' ability.


Import:
¯¯¯¯¯
    1. File -> Preferences -> Automaticlay create unknown variables
    2, Import the "Disarmament" folder into your map.


=========== Usage ==========


    1. Set "DA_Unit" variable, which is the unit you want to work with.
______________________________________________________________________

    2. After the unit is set you can run followingTriggers:

        Trigger - Run DA_GetData (ignoring conditions)
            after you tun this trigger "DA_Duration" will have the remaining duration for our unit.
            after you tun this trigger "DA_IsUnitDisarmed" tells us if the unit is currently disarmed.

        Trigger - Run DA_SetData (ignoring conditions)
            after you tun this trigger "DA_Duration" will be applied for our unit's remaining duration.
            after you tun this trigger "DA_IsUnitDisarmed" tells us if the unit is currently disarmed.

       Negative duration values implies an infinite duration for both triggers, GetData and SetData.
       "0" duration for "SetData" will instantly remove the disarmament.
______________________________________________________________________

    3. Event: Game - DA_Event becomes Equal to 1.00
 
            If this event runs it means that a duration expired and a unit will be able to attack again.
     
            use "DA_Unit" to refer here to the respective unit
_____________________________________________________________________

=========== Credits ==========

    Credits to ukn0wnD3str0y3r, from who's submission I have the idea.
    The original implementati

    Resources
        - Bribe
        - Vexorian
 
Contents

Disarmament v1.1 (Map)

  1. GhostHunter123

    GhostHunter123

    Joined:
    Oct 17, 2012
    Messages:
    419
    Resources:
    1
    Spells:
    1
    Resources:
    1
    How many more systems are you planning to update? Which ones?
     
  2. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Back then when I cleaned the Spell Section I rejected like 800 resources or so because of author inactivity.
    I also took some time to check them for useful concepts, so we might take initiative to re-create them one day.

    System Reinventing
     
    Last edited: Oct 18, 2016
  3. BlueSaint

    BlueSaint

    Joined:
    Jun 18, 2012
    Messages:
    2,668
    Resources:
    3
    Tools:
    1
    Spells:
    2
    Resources:
    3
    All these gameplay tweaking snippets are nice additions to hive's collection!

    In your onInit you create timer which you forgot to call
    ReleaseTimer()
    on afterwards:
    call TimerStart(NewTimer(), 0, false, function thistype.init)
    .
     
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Nice catch, thanks. I will update it next days.
     
  5. AGD

    AGD

    JASS Reviewer

    Joined:
    Mar 29, 2016
    Messages:
    396
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    I think you forgot to make the struct entend an array
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Yes, indeed. Thank you.
     
  7. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Updated:
    • Made above mentioned changes.
    • Added
      static method isUnitDisarmed takes unit u returns boolean
      , and a GUI equivalent
    • Added some safety check to prevent disarming units which already have the cargo ability.
     
  8. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    492
    Resources:
    4
    Spells:
    1
    JASS:
    3
    Resources:
    4
    Have you thought about silencing the 'Aatk' ability in order to disable a unit's attack (you can see how this can be done from this amazing silence guide by leandrotp)? The 'Abun' (orc-cargo) ability seems to hide the attack button as well, which is fine I guess, but not as "cool" as actually seeing the attack ability getting silenced, also you can disable the attack for any unit which has the 'Aatk' ability.

    PS: leandrotp's method also allows one to disable the 'Amov' ability (and almost any other ability?) ;P
     
  9. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Hm, yes I should consider looking into it, I totaly forgot.
     
  10. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,426
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    Very useful system. It would be great if you can add the feature Aniki was talking about though! I also really like the GUI-friendly feature you added with it.

    Needs Fixed


    • Nothing

    Suggestions


    • Code (vJASS):
      if not (duration != 0) then
          // do stuff
      else
          if not UnitAddAbility(u, DISARM_ID) and not IsUnitInGroup(u, GROUP) then
              // debug message
              return false
          endif
      endif

      // >>

      if not (duration !=) then
          // do stuff
      elseif not UnitAddAbility(u_DISARM_ID) and not IsUnitInGroup(u, GROUP) then
          // debug message
          return false
      endif
       

    Status


    Approved
     
  11. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    I finaly found time to read the silence tutorial, it's pure awesomeness.
    Simply adding/removing in comparison though is, more straight forward.

    I don't think it's worth for me to rewrite it now and use the silence method, specialisized for 'Aatk'.
    It would be probably good though if, when leandrotp has continued his work, him or soemone else writes a full useable system with also mentionening exceptions and everything related.
     
  12. ukn0wnD3str0y3r

    ukn0wnD3str0y3r

    Joined:
    Feb 15, 2013
    Messages:
    376
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Thanks man! for making a better verison of it
     
  13. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Since patch 1.29 it will be better to use the new native:

    native BlzUnitDisableAbilitytakes unit whichUnit, integer abilId, boolean flag, boolean hideUI returns nothing


    .. because with it, the attack ability ('Aatk') can be correcly enabled again. The cargo approach is now outdated.
     
  14. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,395
    Resources:
    17
    Maps:
    1
    Spells:
    10
    Tutorials:
    6
    Resources:
    17
    .. I should have scrolled down earlier, would have saved me an hour of implementing the silence approach.
     
  15. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    5,797
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Hm, yeh. Added note at very top.
     
  16. Daffa the Mage

    Daffa the Mage

    Map Reviewer

    Joined:
    Jan 30, 2013
    Messages:
    7,105
    Resources:
    22
    Packs:
    1
    Maps:
    8
    Spells:
    12
    Tutorials:
    1
    Resources:
    22
    I assume it should be
    Code (vJASS):

    native BlzUnitDisableAbility takes unit whichUnit, integer abilId, boolean flag, boolean hideUI returns nothing
     

    with a space between Ability and takes