[JASS] How to make nocd script?

Status
Not open for further replies.
Level 29
Joined
Mar 10, 2009
Messages
5,016
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
193
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)
 
Level 29
Joined
Mar 10, 2009
Messages
5,016
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
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
@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.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
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