Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] IsUnitChanneling  (Read 9229 times)

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[Snippet] IsUnitChanneling
« on: July 09, 2012, 01:53:54 PM »
This is a small and clear resource that detects if a unit is channeling or not.

Code: jass  [Select]
  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. *           - hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/
  14. *
  15. *       Optional:
  16. *       ---------
  17. *
  18. *           - UnitIndexer by Nestharus
  19. *               - hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/
  20. *           - Table by Bribe
  21. *               - hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
  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: October 12, 2012, 10:49:24 AM by Magtheridon96 »

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 986
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 5
  • WC3 Models: 25
  • WC3 Tutorials: 13
  • WC3 Tools: 10
  • WC3 Maps: 11
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: [Snippet] IsUnitChanneling
« Reply #1 on: September 02, 2012, 11:54:22 AM »
And this snippet has been approved by me :)

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
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 ^.^

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11617
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 21235
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 26150
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8858
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7560
Last post January 09, 2012, 07:03:32 PM
by moyack
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!