1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  5. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  6. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  7. The 13th Music Contest Poll is up! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  8. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  9. 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.

Passive Cooldown System [GUI Friendly] v1.04

Submitted by Flux
This bundle is marked as approved. It works and satisfies the submission rules.
-----------------------------------------------------------------------------
Sysem Code with description of the System
-----------------------------------------------------------------------------
Code (vJASS):

//            ----------------------------------------------------------------                     //
//                    Passive Cooldown System [GUI Friendly] v1.04                                 //
//                                  by Flux                                                        //
//                  http://www.hiveworkshop.com/forums/members/flux/                               //
//            ----------------------------------------------------------------                     //
//                                                                                                 //
//    This system allows you to make any unit's ability goes into cooldown via trigger             //
//    Though written in Jass, it has GUI support and easy to use for GUI users                     //
//    Even if the name shows "Passive Cooldown", it can be applied on Active Abilities as well     //
//    (as show in Demo 3) but this system is mostly intended for Passive Abilities.                //
//                                                                                                 //
//    HOW TO IMPORT:                                                                               //
//       1. Copy the PCD_IndicatorStart and PCD_ValidTargetCheck Ability to your map               //
//       2. Copy the PCD_DummyCaster Unit to your map                                              //
//       3. Configure the PCD_DummyCasterId, PCD_IndicatorStartId, PCD_ValidTargetCheckId          //
//          and PCD_VTCBaseOrderId in PCD System Configuration Trigger.                            //
//       4. Copy PCD Variable Creator to your map to automatically create the system's variables.  //
//          Make sure you check the "Automatically create unknown variables while pasting trigger  //
//          data" in File->Preferences of World Editor. After the variables are created, you can   //
//          then delete the 'PCD Variable Creator' trigger.                                        //
//                                                                                                 //
//                                                                                                 //
//    HOW TO USE:                                                                                  //
//       1. Set the PCD_Unit variable. This refers to the unit that will have its ability          //
//          goes into cooldown via trigger.                                                        //
//       2. Set the PCD_Ability variable. This refers to the ability that will go into cooldown.   //
//       3. Set the PCD_DummyAbility variable. This refers to the ability based on Spell Shield    //
//          that you have created. It must have the same tooltip, manacost and icon.               //
//       4. Set the PCD_Time variable. This refers how long the PCD_Ability will be replaced by    //
//          the PCD_DummyAbility. It should match the 'Stats - Cooldown' of the PCD_DummyAbility.  //
//       5. Set the PCD_Manacost variable. This is the manacost of the PCD_Ability which should    //
//          match the manacost of the PCD_DummyAbility 'Stats - Manacost' if you don't want        //
//          the unit to lose mana when you trigger it's cooldown.                                  //
//       6. Execute by "Trigger - Run Trigger Cooldown System <gen> (checking conditions)"         //
//                                                                                                 //
//                                                                                                 //
//      Notes:                                                                                     //
//          - When triggering the cooldown of an active ability, it will reset the original        //
//            ability's cooldown. Example: Original Ability's  is on cooldown for 20 seconds but   //
//            the triggered cooldown only last 5 seconds, when that 5 seconds is finished,         //
//            the original ability is now ready to be use again.                                   //
//          - Can only trigger Unit ability so far, so to trigger a Hero's ability, a dummy hero   //
//            ability must be used and when the dummy ability is learned, add the real ability.    //
//            (As shown in Map Demo 3)                                                             //
//                                                                                                 //                              
//      Works on:                                                                                  //
//          - Invulnerable, Spell Immune, Structures, Ancient,                                     //
//            Mechanical, Invisible (but removes it)                                               //
//      Does not work on:                                                                          //
//          - Hidden, Cycloned                                                                     //
//                                                                                                 //
//    CREDITS:                                                                                     //
//       Xonok - for the Spell Block trick to simulate cooldown                                    //
//       Wietlol - for finding bugs and suggesting solutions to it.                                //


//-------------------------------------------------------------------------------------------------//
//-------------------------------------- SYSTEM CORE ----------------------------------------------//
//-------------------------------------------------------------------------------------------------//
function Trig_Passive_Cooldown_System_TimerExpires takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local unit u = LoadUnitHandle(udg_PCD_Hashtable, id, 0)
    local integer origAbil = LoadInteger(udg_PCD_Hashtable, id, 0)
    local integer fakeAbil = LoadInteger(udg_PCD_Hashtable, id, 1)
    local integer lvl = GetUnitAbilityLevel(u, fakeAbil)

    call UnitAddAbility(u, origAbil)
    if lvl > 1 then
        call SetUnitAbilityLevel(u, origAbil, lvl)
    endif
    call UnitRemoveAbility(u, fakeAbil)
    //Destroy the timer reference data
    call FlushChildHashtable(udg_PCD_Hashtable, id)
    //Destroy the unit reference data
    call FlushChildHashtable(udg_PCD_Hashtable, GetHandleId(u))
    call DestroyTimer(t)
    set t = null
    set u = null
endfunction

function Trig_Passive_Cooldown_System_Execute takes nothing returns boolean
    local timer t
    local integer id
    local integer unitId
    local integer lvl
    set lvl = GetUnitAbilityLevel(udg_PCD_Unit, udg_PCD_Ability)
    call SetUnitX(udg_PCD_DummyCaster, GetUnitX(udg_PCD_Unit))
    call SetUnitY(udg_PCD_DummyCaster, GetUnitY(udg_PCD_Unit))
    //For checking if it is castable
    call SetPlayerAlliance(Player(14), GetOwningPlayer(udg_PCD_Unit), ALLIANCE_PASSIVE, true)
    if IssueTargetOrder(udg_PCD_DummyCaster, udg_PCD_VTCBaseOrderId, udg_PCD_Unit) then
        if lvl > 0 then
            call UnitRemoveAbility(udg_PCD_Unit, udg_PCD_Ability)
        else
            set lvl = GetUnitAbilityLevel(udg_PCD_Unit, udg_PCD_DummyAbility)
            call UnitRemoveAbility(udg_PCD_Unit, udg_PCD_DummyAbility)
        endif
        //Add the fake ability
        call UnitAddAbility(udg_PCD_Unit, udg_PCD_DummyAbility)
        call SetUnitAbilityLevel(udg_PCD_Unit, udg_PCD_DummyAbility, lvl)
     
        call IssueTargetOrderById(udg_PCD_DummyCaster, 852075, udg_PCD_Unit)
     
        set unitId = GetHandleId(udg_PCD_Unit)
        //[unitId][5] is for timers
     
        //If there is already a timer, just reset it
        if HaveSavedHandle(udg_PCD_Hashtable, unitId, udg_PCD_Ability) then
            call TimerStart(LoadTimerHandle(udg_PCD_Hashtable, unitId, udg_PCD_Ability), udg_PCD_Time, false, function Trig_Passive_Cooldown_System_TimerExpires)
        else
            set t = CreateTimer()
            set id = GetHandleId(t)
            //Save the timer in reference to the unit
            call SaveTimerHandle(udg_PCD_Hashtable, unitId, udg_PCD_Ability, t)
            call TimerStart(t, udg_PCD_Time, false, function Trig_Passive_Cooldown_System_TimerExpires)
            set t = null
            //Save the unit
            call SaveUnitHandle(udg_PCD_Hashtable, id, 0, udg_PCD_Unit)
            //Save the original ability replaced
            call SaveInteger(udg_PCD_Hashtable, id, 0, udg_PCD_Ability)
            //Save the fake ability
            call SaveInteger(udg_PCD_Hashtable, id, 1, udg_PCD_DummyAbility)
        endif
     
        if udg_PCD_Manacost > 0 then
            call SetUnitState(udg_PCD_Unit, UNIT_STATE_MANA, GetUnitState(udg_PCD_Unit, UNIT_STATE_MANA) + udg_PCD_Manacost)
        endif
    endif
    call SetPlayerAlliance(Player(14), GetOwningPlayer(udg_PCD_Unit), ALLIANCE_PASSIVE, false)
 
    return false
endfunction

function Trig_Passive_Cooldown_System_LastInit takes nothing returns nothing
    set udg_PCD_DummyCaster = CreateUnit(Player(14), udg_PCD_DummyCasterId, 0, 0, 0)
    call SetHeroLevel(udg_PCD_DummyCaster, 6, false)
    call UnitAddAbility(udg_PCD_DummyCaster, udg_PCD_IndicatorStartId)
    call SelectHeroSkill(udg_PCD_DummyCaster, udg_PCD_IndicatorStartId)
    call UnitAddAbility(udg_PCD_DummyCaster, udg_PCD_ValidTargetCheckId)
    call DestroyTimer(GetExpiredTimer())
endfunction

//===========================================================================
function InitTrig_Passive_Cooldown_System takes nothing returns nothing
    set gg_trg_Passive_Cooldown_System = CreateTrigger()
    set udg_PCD_Hashtable = InitHashtable()
    call TimerStart(CreateTimer(), 0, false, function Trig_Passive_Cooldown_System_LastInit)
    call TriggerAddCondition(gg_trg_Passive_Cooldown_System, Condition(function Trig_Passive_Cooldown_System_Execute))
endfunction
 

-----------------------------------------------------------------------------
Using this System Sample
-----------------------------------------------------------------------------
This trigger will make all units with Hardened Skin to go into cooldown
  • Trigger Cooldown 1
    • Events
      • Player - Player 1 (Red) types a chat message containing 1 as An exact match
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Level of Hardened Skin (Mountain Giant) for (Matching unit)) Greater than 0)) and do (Actions)
        • Loop - Actions
          • -------- Set the unit --------
          • Set PCD_Unit = (Picked unit)
          • -------- Set the original ability --------
          • Set PCD_Ability = Hardened Skin (Mountain Giant)
          • -------- Set the fake ability based on Spell Shield --------
          • Set PCD_DummyAbility = Hardened Skin (For PCD System)
          • -------- PCD_Time = How much time you want the spell to be on cooldown --------
          • -------- It must match the PCD_DummyAbility 'Stats - Cooldown' --------
          • Set PCD_Time = 5.00
          • -------- Set the manacost of the ability --------
          • Set PCD_Manacost = 0.00
          • Trigger - Run Passive Cooldown System <gen> (checking conditions)



-----------------------------------------------------------------------------
Changelog
-----------------------------------------------------------------------------
v1.00 - [10 October 2015]
- Initial Release

v1.01 - [15 October 2015]
- Changed the name to "Passive Cooldown System" from "Trigger Cooldown System"
- Added a new system ability that will check if PCD_Unit is targetable instead of using PCD_IndicatorStart for that. That way, the buff will no longer be applied and removed.
- Fixed a handle reference leak.
- Made the configuration GUI.
- System Core is added as a condition in a trigger for faster execution.

v1.02 - [17 October 2015]
- Made the system works on Invulnerable Units.
- No longer pause the timer before destroying it.

v1.03 - [8 January 2016]
- Now works on all types of Invulnerability, Spell Immune, Structures, Mechanical and Ancient units.

v1.04 - [20 August 2016]
- Activating the system no longer poses a threat/alert to the unit.




Keywords:
passive cooldown system
Contents

Passive Cooldown System 1.04 (Map)

Reviews
Moderator
17th Oct 2015 Bribe: Approved. Works very smoothly! This is a nice way to standardize triggered cooldowns. (Please remove the shadow from your dummy unit, it is quite distracting in the demo).
  1. 17th Oct 2015
    Bribe: Approved. Works very smoothly! This is a nice way to standardize triggered cooldowns.

    (Please remove the shadow from your dummy unit, it is quite distracting in the demo).
     
  2. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,698
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    After reading the name of the system I thought it was a a system that disabled a trigger and enabled it after X seconds.

    I am not the biggest fan of this system as I hate everything that requires object editor work.
    To begin with, I don't even get the point of a dummy ability here.
    If the spell is triggered, it is not needed. If the spell is made in the object editor, I think you can work around that by using the event "begins casting a spell" and then order the unit to stop if spell is on cooldown.
     
  3. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    The point of the dummy ability is to make the Ability go into cooldown. If I just removed the ability for a period of time, it looks ugly. So I needed to make the ability appears it is on cooldown and this is the solution.
    It won't show the cooldown indicator.

    Here are some of the reasons why I made this system.
    http://www.hiveworkshop.com/forums/world-editor-help-zone-98/passive-ability-cooldown-121471/

    Passive skill with cooldown

    Trigger cooldown on passive ability

    http://www.hiveworkshop.com/forums/triggers-scripts-269/can-passive-ability-has-cooldown-179885/
     
  4. btdonald

    btdonald

    Joined:
    Dec 3, 2011
    Messages:
    346
    Resources:
    8
    Maps:
    1
    Spells:
    7
    Resources:
    8
    No No. Use timer and remove/re-add ability to reset its cooldown.
     
  5. Wrda

    Wrda

    Joined:
    Nov 18, 2012
    Messages:
    1,235
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Known bug: all buffs diappear when you trigger the cooldown of a spell
    Would be a perfect system if you fixed that.
     
  6. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,125
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Fixes:

    local unit u needs to be nulled at the end of the expire function.
    I think this will cause micro-slows on the cooldown unit, but I could be wrong there.

    Should be configurable:

    - owning player of dummy unit
    - order ID of dummy spell
    - The buff 'Bslo'

    Recommendations:

    Since you intend for this to be used by GUI users, I recommend making the configurables in a GUI trigger so users can select the unit type and ability ID without looking up the rawcode.

    The trigger should use a condition instead of action as it's faster. Have the GUI user do "checking conditions" instead of ignoring them.

    Overall, this has potential to be a decent cooldown simulator. However, it requires massive amounts of user configuration and that's not that awesome. I don't think this will get more than a 3/5 rating as it's not sufficient to break the mold.
     
  7. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    This system's aim is not to reset a cooldown.
    I'll take a look.


    Yep, I should have double checked.
    Not at all, I instantly removed ithe Buff.

    - why? For the Spell Shield to activate, the caster must be an enemy
    - Slow is one of the best spell to trigger Spell Shield because it has no projectile so I don't see why you would configure that.
    - Same reason as above

    Make sense, though it will require another trigger.

    I thought using action would make it more GUI friendly. Ok, will change that too.

    Well, you only need to make Dummy Abilities for spells that you want to trigger the cooldown. Example in your map, you have overall 20 spells but only two of those needs to have it's cooldown triggered, then only 2 extra Dummy Ability. The point is, it is a workaround to the links I gave in my earlier post.
     
  8. Wrda

    Wrda

    Joined:
    Nov 18, 2012
    Messages:
    1,235
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Actually I was a bit wrong about this, if in any game a player slows an enemy unit for 60 seconds and then that unit has an active/passive spell that triggers cooldown (ex:critical strike), it will be triggered, but the slow's effects and buff are already done even if the unit didn't have the slow effects for 60 seconds, so that is broken.
    Yes you can.(tested it) Any "units in region" and "units in range"...
    • Unit Group - Pick every unit in (Units in (Region) and do (Actions)
    • Unit Group - Pick every unit in (Units within X of Region) and do (Actions)

    ...won't detect locusted and hidden units. But cycloned units can be detected.

    You can detect the former by "units of type" or any "units owned by player" function.
     
  9. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,125
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Is there a way to make a custom slow debuff so it doesn't erase previous slows when used?
     
  10. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    Hmm, if I made a custom Buff based on slow, I think the original 'Bslo' won't get affected. I might be wrong though. I think I will also change the name to Passive Cooldown System.

    EDIT:
    The other things you mentioned Bribe. I need to have all issues clear to have it all fixed in one update. If you don't tell me the reason of some of your suggestion (the configurable part), then I won't follow it. But most likely scenario is after updating it without following the configurable part, you won't approve it and I will end up updating again.

    Is this system really not useful? If that's the case I will just remove it. No point in putting effort to something useless.

    You can detect it via trigger but if it is a cycloned unit, you cannot target it so the cooldown won't start. That is why there is an initial check to see if it is targetable first before doing the necessary actions.
     
    Last edited: Oct 15, 2015
  11. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    Spell updated to v1.01
    EDIT: Sorry Bribe, but tonight is my free time.
     
    Last edited: Oct 15, 2015
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,125
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Ah I see now that you edited your post before this. Don't worry, you fixed the main thing which was the leaky handle index. Tomorrow morning (European morning) I will run more tests. The code looks good and any further changes to it won't affect the upcoming revised mod review. As long as the slow ability doesn't get cut short by this any more, then this is ready for prime time.

    And you're right about the setup of the ability. Only a small number of dummy abilities would need to get copied tooltips and icons, most likely.
     
  13. Empirean

    Empirean

    Joined:
    Jun 20, 2014
    Messages:
    390
    Resources:
    8
    Spells:
    8
    Resources:
    8
    I tried this and its awesome how you trigger the specific spell withlut triggering the other one. The cooldown resets when u click the cd spell multiple times.
     
  14. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    There is no castable buff-placer that doesn't override others based on the same one. So you will inevitably risk collisions with at least 1 ability.

    I like that you made this system for general use. I've been wanting to make something like this for a long time, but never bothered enough. Also, I would probably not make mine GUI-friendly.
     
  15. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    Not at all. I tested it placing a Slow Buff first before triggering the cooldown and it works fine.. It doesn't remove the initial Slow Buff.

    This was fairly easy to do in JASS or vJass in my opinion because of timer's ease of use in Jass so that's why I made it GUI-friendly.


    Spell updated to v1.02 to make it work on Invulnerable units and removed the PauseTimer(t) before destroying it.

    EDIT:
    Will do. Done
     
    Last edited: Oct 17, 2015
  16. Empirean

    Empirean

    Joined:
    Jun 20, 2014
    Messages:
    390
    Resources:
    8
    Spells:
    8
    Resources:
    8
    Yeah! Approved
     
  17. KILLCIDE

    KILLCIDE

    Administrator

    Joined:
    Jul 22, 2015
    Messages:
    3,501
    Resources:
    20
    Models:
    2
    Icons:
    10
    Spells:
    7
    Tutorials:
    1
    Resources:
    20
    I will be definitely using this for my project :) thank you!
     
  18. jonbon29

    jonbon29

    Joined:
    Aug 19, 2014
    Messages:
    1,099
    Resources:
    0
    Resources:
    0
    Finally a passive cooldown system! I'll be using this too :)
     
  19. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,042
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    Oh, now I get it. Since the spellshield blocks the ability from applying in the first place, then the previous slow debuffs, if any, don't get touched at all.