Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[Snippet] IsUnitChanneling No New Posts Codes & Snippets

Started by
Magtheridon96

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: January 18, 2018, 09:08:43 PM by moyack »

[Snippet] IsUnitChanneling
on: July 09, 2012, 01:53:54 PM
Category: Units
Language: vJASS

Related Topics or Resources



by

This is a small and clear resource that detects if a unit is channeling or not.

Code: jass
  1. /**************************************
  2. *
  3. *   IsUnitChanneling
  4. *   v2.1.0.0
  5. *   By Magtheridon96
  6. *
  7. *   - Tells whether a unit is channeling or not.
  8. *
  9. *   Requirements:
  10. *   -------------
  11. *
  12. *       - RegisterPlayerUnitEvent by Magtheridon96
  13. *           - https://wc3modding.info/4907/snippet-registerplayerunitevent/
  14. *
  15. *       Optional:
  16. *       ---------
  17. *
  18. *           - UnitIndexer by Nestharus
  19. *               - https://wc3modding.info/4607/unitindexer/
  20. *           - Table by Bribe
  21. *               - https://wc3modding.info/4611/snippet-new-table/
  22. *
  23. *   API:
  24. *   ----
  25. *
  26. *       - function IsUnitChanneling takes unit whichUnit returns boolean
  27. *           - 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 boolean
  31. *           - 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.         else
  40.             static if LIBRARY_Table then
  41.                 static key k
  42.                 static Table channeling = k
  43.             else
  44.                 static hashtable hash = InitHashtable()
  45.             endif
  46.         endif
  47.        
  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.             else
  53.                 static if LIBRARY_Table then
  54.                     local integer id = GetHandleId(GetTriggerUnit())
  55.                     set channeling.boolean[id] = not channeling.boolean[id]
  56.                 else
  57.                     local integer id = GetHandleId(GetTriggerUnit())
  58.                     call SaveBoolean(hash, 0, id, not LoadBoolean(hash, 0, id))
  59.                 endif
  60.             endif
  61.         endmethod
  62.        
  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.         endmethod
  67.     endstruct
  68.    
  69.     static if LIBRARY_UnitIndexer then
  70.         function IsUnitChannelingById takes integer id returns boolean
  71.             return OnChannel.channeling[id]
  72.         endfunction
  73.     endif
  74.    
  75.     function IsUnitChanneling takes unit u returns boolean
  76.         static if LIBRARY_UnitIndexer then
  77.             return OnChannel.channeling[GetUnitUserData(u)]
  78.         else
  79.             static if LIBRARY_Table then
  80.                 return OnChannel.channeling.boolean[GetHandleId(u)]
  81.             else
  82.                 return LoadBoolean(OnChannel.hash, 0, GetHandleId(u))
  83.             endif
  84.         endif
  85.     endfunction
  86.    
  87. endlibrary

Feel free to comment..
« Last Edit: December 19, 2017, 02:03:43 PM by moyack »



Re: [Snippet] IsUnitChanneling
Reply #1 on: September 02, 2012, 11:54:22 AM

And this snippet has been approved by me :)


Re: [Snippet] IsUnitChanneling
Reply #2 on: October 12, 2012, 10:50:11 AM

Updated! Now, UnitIndexer is optional.
If you don't have UnitIndexer, it will run on Table, and if you don't have Table, it will use a regular hashtable ^.^



 

Started by PitzerMike

Replies: 0
Views: 1588
Codes & Snippets

Started by Purgeandfire

Replies: 0
Views: 1672
Codes & Snippets

Started by Bribe

Replies: 0
Views: 1916
Codes & Snippets

Started by moyack

Replies: 0
Views: 9829
Codes & Snippets

Started by Magtheridon96

Replies: 1
Views: 8623
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...