• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] How to make nocd script?

Status
Not open for further replies.
paste this in your map...
JASS:
scope CD initializer init

private function ResetNow takes nothing returns boolean
    call UnitResetCooldown(GetFilterUnit())
    return false
endfunction

private function ResetCooldown takes nothing returns boolean
    call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, function ResetNow)
    return false    
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()  
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerAddCondition(t, Condition(function ResetCooldown))
    set t = null
endfunction

endscope
 
Level 7
Joined
Oct 16, 2010
Messages
194
The reason i need it because i want to make a nocd mode in my map. Will it be easier and better if i just do it in GUI?(I didn't do in GUI because i heard Jass is better and sometimes when i finish casting the ability it does not reset the cooldown)
 
yeah a global group will work but timer needs to be destroyed also...
anyway, this will work also...
JASS:
scope CD initializer init

private function ResetCooldown takes nothing returns boolean
    call UnitResetCooldown(GetTriggerUnit())
    return false    
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()  
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerAddCondition(t, Condition(function ResetCooldown))
    set t = null
endfunction

endscope
 
@nafre You can do this in GUI, although it's always less efficient than Jass script.

  • call reset
    • Events
      • Unit - A unit Starts effect of ability
    • Conditions
    • Actions
      • Unit Group - Add (Triggering unit) to CDgroup
      • Timer - Countdown timer as One shot that will expire in 0.00 seconds
  • reset
    • Events
      • Time - timer expires
    • Conditions
    • Actions
      • Unit Group - Pick all units in CDgroup and do Actions
        • Loop - Actions
          • Unit - Reset cooldowns for (Picked unit)
          • Unit Group - Remove (Picked unit) from CDgroup
Now for activating the 'nocd' mode simply create trigger that reacts on 'event - player types message'. Follow this with action: Trigger - Turn on call reset <gen>. Make sure 'call reset' trigger is disabled by default.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
yeah a global group will work but timer needs to be destroyed also...

Use one timer for the system, don't destroy it.

Cooldown will trigger before _ENDCAST event, so you'll see the cooldown run for some time. Better to use _SPELL_EFFECT and 0.00 timer. Spinnaker's trigger is the method I described earlier.
 
Last edited:
Respresentation of my trigger in simple jass (doesn't require use of NewGen):

Thanks to Maker, Pharaoh_ and Bribe for script improvements.
JASS:
function Callrestore takes nothing returns nothing
    call UnitResetCooldown(GetEnumUnit())
    call GroupRemoveUnit(udg_CDgroup, GetEnumUnit())
endfunction

function Callback takes nothing returns nothing
    call ForGroup(udg_CDgroup, function Callrestore)
endfunction

function GetUnit takes nothing returns boolean
    if udg_ModeEnabled then
        call GroupAddUnit(udg_CDgroup, GetTriggerUnit())
        call TimerStart(udg_timer, 0.00, false, function Callback)
    endif
    return false
endfunction

function InitTrig_ResetCooldown takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_ENDCAST)
    call TriggerAddCondition(t, Condition(function GetUnit))
    set t = null
endfunction
Requires one global group variable: CDgroup and one timer variable: timer.
Now, to enable/disable 'nocd' mode, make use of boolean variable (here it's 'udg_ModeEnabled'). If set to true, trigger will reset every cooldown.
 
Last edited:
Level 12
Joined
Feb 22, 2010
Messages
1,115
Don't use "null" as an argument in registered event (or any boolexpr). Create a function that returns true; for some odd reason, it creates a permanent leak otherwise. It is more preferable if it has anything but "null".

We are living in 2011 :vw_wtf: Null boolexpr leak doesn't exist anymore.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Status
Not open for further replies.
Top