Blizzard Modding Network

Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chaos Arena - A Warcraft III mod
Check all that happens in this network through BLIZZARD MODDING.INFO

* Announcements!!

  • We're now at wc3 top 200 lists. Please vote for us.
  • WC3jass.com has a new theme, very similar to the original but lighter to load. If you have any suggestions or comments about it, just post it here.
  • We are getting more social!!! Visit the new social group section and create your own group with your friends

Jass New Gen Pack

Download Jass New Generation Pack (JNGP) to use all the vJASS & Zinc scripts posted in any of the Blizzardmodding sites.

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

Offline Magtheridon96

  • Awesome Global Code Moderator
  • Code Director
  • Rookie - level 2
  • *
  • Posts: 81
  • Reputation: 515
  • vJass Incarnate
  • Referrals: 0
    • View Profile
    • Awards
[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
  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 »

Online moyack

  • Site Owner
  • Administrator
  • Frequent - level 2
  • *
  • Posts: 1707
  • Reputation: 1144
  • Site Admin - I love fix things
  • Referrals: 0
    • View Profile
    • Blizzard Modding Information Center
    • Awards
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. Not only a forum, a complete page!!.

A custom altered melee map where you can play Naga and Demons. Featuring a nice additions in features and game style. Check it out!!

Offline Magtheridon96

  • Awesome Global Code Moderator
  • Code Director
  • Rookie - level 2
  • *
  • Posts: 81
  • Reputation: 515
  • vJass Incarnate
  • Referrals: 0
    • View Profile
    • Awards
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 ^.^

Tags:
 

[Snippet] Timed Effects

Started by moyack

Replies: 0
Views: 894
Last post January 09, 2012, 07:03:32 PM
by moyack
[Snippet] StringIndexer

Started by Magtheridon96

Replies: 1
Views: 1094
Last post September 02, 2012, 11:51:03 AM
by moyack
[Snippet] AddSpecialEffectZ

Started by Purgeandfire

Replies: 4
Views: 2166
Last post August 14, 2012, 12:06:10 AM
by LembidiZ
[Snippet] Parabolic Function

Started by moyack

Replies: 1
Views: 875
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
[Snippet] RegisterAnyUnitEvent

Started by moyack

Replies: 2
Views: 958
Last post February 12, 2012, 09:20:29 PM
by moyack
  UDMod Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Vote for Blizzmod at Warcraft 3 Top 200 - Cheats Free Clans and Resources