- Joined
- Jun 17, 2007
- Messages
- 1,433
Sometimes it can be useful to disable the auto-casting of certain abilities. For example, you may have a custom Searing Arrows ability that has a cooldown. Unfortunately, the auto-casting of it does not properly trigger the cooldown (and I believe has other issues relating to things like range). I haven't written vJASS in ~8 years, so maybe my approach is terrible or outdated, but it seems fine to me.
This API is simple:
where 'activateOrder' is the order id to enable auto-casting, and 'deactivateOrder' is the order to turn it off. For example,
prevents Inner Fire from being autocast.
This API is simple:
JASS:
function DisableAutocast takes integer activateOrder, integer deactivateOrder returns nothing
JASS:
call DisableAutocast(852067, 852068)
JASS:
library DisableAutocast initializer Init requires TimerUtils, Table
globals
private Table table
endglobals
private struct DisableData
unit u
integer deactivateOrder
static method create takes unit u, integer deactivateOrder returns DisableData
local DisableData this = DisableData.allocate()
set this.u = u
set this.deactivateOrder = deactivateOrder
return this
endmethod
endstruct
private function Callback takes nothing returns nothing
local timer t = GetExpiredTimer()
local DisableData d = GetTimerData(t)
call IssueImmediateOrderById(d.u, d.deactivateOrder)
call ReleaseTimer(t)
call d.destroy()
set t = null
endfunction
private function Actions takes nothing returns nothing
local timer t
local DisableData d
local integer orderId = GetIssuedOrderId()
if table.exists(orderId) then
set t = NewTimer()
set d = DisableData.create(GetTriggerUnit(), table[orderId])
call SetTimerData(t, d)
call TimerStart(t, 0., false, function Callback)
set t = null
endif
endfunction
function DisableAutocast takes integer activateOrder, integer deactivateOrder returns nothing
set table[activateOrder] = deactivateOrder
endfunction
public function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_ORDER)
call TriggerAddAction(t, function Actions)
set table = Table.create()
endfunction
endlibrary