14 years
edited 8 years
This is a small and clear resource that detects if a unit is channeling or not.
Feel free to comment..
1 /**************************************2 *3 * IsUnitChanneling4 * v2.1.0.05 * By Magtheridon966 *7 * - Tells whether a unit is channeling or not.8 *9 * Requirements:10 * -------------11 *12 * - RegisterPlayerUnitEvent by Magtheridon9613 * - https://wc3modding.info/4907/snippet-registerplayerunitevent/14 *15 * Optional:16 * ---------17 *18 * - UnitIndexer by Nestharus19 * - https://wc3modding.info/4607/unitindexer/20 * - Table by Bribe21 * - https://wc3modding.info/4611/snippet-new-table/22 *23 * API:24 * ----25 *26 * - function IsUnitChanneling takes unit whichUnit returns boolean27 * - Tells whether a unit is channeling or not.28 * (This function is only available if you have UnitIndexer)29 *30 * - function IsUnitChannelingById takes integer unitIndex returns boolean31 * - Tells whether a unti is channeling or not given the unit index.32 *33 **************************************/34 library IsUnitChanneling requires optional UnitIndexer, optional Table, RegisterPlayerUnitEvent
35
36 private struct OnChannel extends array
37 static if LIBRARY_UnitIndexer then
38 static boolean array channeling
39 else40 static if LIBRARY_Table then
41 static key k
42 static Table channeling = k
43 else44 static hashtable hash = InitHashtable()
45 endif46 endif47
48 private static method onEvent takes nothing returns nothing
49 static if LIBRARY_UnitIndexer then
50 local integer id = GetUnitUserData(GetTriggerUnit())
51 set channeling[id] = not channeling[id]
52 else53 static if LIBRARY_Table then
54 local integer id = GetHandleId(GetTriggerUnit())
55 set channeling.boolean[id] = not channeling.boolean[id]
56 else57 local integer id = GetHandleId(GetTriggerUnit())
58 call SaveBoolean(hash, 0, id, not LoadBoolean(hash, 0, id))
59 endif60 endif61 endmethod62
63 private static method onInit takes nothing returns nothing
64 call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CHANNEL, function thistype.onEvent)
65 call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_ENDCAST, function thistype.onEvent)
66 endmethod67 endstruct68
69 static if LIBRARY_UnitIndexer then
70 function IsUnitChannelingById takes integer id returns boolean
71 return OnChannel.channeling[id]
72 endfunction73 endif74
75 function IsUnitChanneling takes unit u returns boolean
76 static if LIBRARY_UnitIndexer then
77 return OnChannel.channeling[GetUnitUserData(u)]
78 else79 static if LIBRARY_Table then
80 return OnChannel.channeling.boolean[GetHandleId(u)]
81 else82 return LoadBoolean(OnChannel.hash, 0, GetHandleId(u))
83 endif84 endif85 endfunction86
87 endlibrary
Feel free to comment..