Author Topic: [Snippet] RegisterAnyUnitEvent  (Read 8427 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[Snippet] RegisterAnyUnitEvent
« on: February 02, 2012, 11:18:36 AM »
Desciption.
A library to reduce the time writing the same shit. I took some code ideas from a similar resource approved here. This one supports all the possibilities in calling the trigger. If user defines the condition and action functions this function will return the respective trigger, so it can be controlled by other instance (just in case).

If the user only sets a condition or action, then it will return null because this trigger handles a lot of conditions and actions and it shouldn't be accessible by the user.


Usage:
For functions without triggersleepaction or waits, it's recommended to use
Code: jass  [Select]
  1. call RegisterAnyUnitEvent(<Event>, code Function, null)
For functions with triggersleepaction or waits, it's recommended to use
Code: jass  [Select]
  1. call RegisterAnyUnitEvent(<Event>, null, code Function)
For triggers which condition and action codes must be separated (it could happen) you set this:
Code: jass  [Select]
  1. private function Conditions takes nothing returns boolean
  2.     return GetSpellAbilityId() == 'A000'
  3. endfunction
  4.  
  5. private function Actions takes nothing returns nothing
  6.     // your stuff...
  7. endfunction
  8.  
  9. private function init takes nothing returns nothing
  10.     local trigger t = RegisterAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function Conditions, function Actions)
  11. endfunction


Actual code
Code: jass  [Select]
  1. /*
  2. //************************************************************************//
  3. //                    RegisterAnyUnitEvent by moyack                      //
  4. //************************************************************************//
  5. // Code improved with the idea developed by Magtheridon96 , Bribe, azlier //
  6. //************************************************************************//
  7.  
  8. A library to reduce the time writing the same shit. I took some code ideas from a similar
  9. resource approved here. This one supports all the possibilities in calling the trigger.
  10. If user defines the condition and action functions this function will return the respective
  11. trigger, so it can be controlled by other instance (just in case).
  12.  
  13. If the user only sets a condition or action, then it will return null because this
  14. trigger handles a lot of conditions and actions and it shouldn't be accessible by the user.
  15.  
  16.  * For functions without triggersleepaction or waits, it's recommended to use:
  17.     call RegisterAnyUnitEvent(<Event>, code Function, null)
  18.  
  19.  * For functions with triggersleepaction or waits, it's recommended to use:
  20.     call RegisterAnyUnitEvent(<Event>, null, code Function)
  21. */
  22. globals
  23.     private trigger array ts
  24. endglobals
  25.  
  26. function RegisterAnyUnitEvent takes playerunitevent e, code cond, code act returns nothing
  27.     local integer i = GetHandleId(e)
  28.     local trigger t
  29.     if act != null then
  30.         set t = CreateTrigger()
  31.         call TriggerRegisterAnyUnitEventBJ(t, e)
  32.         if cond != null then
  33.             call TriggerAddCondition(t, Filter(cond))
  34.         endif
  35.         call TriggerAddAction(t, act)
  36.         set t = null
  37.     else
  38.         if ts[i] == null then
  39.             set ts[i] = CreateTrigger()
  40.             call TriggerRegisterAnyUnitEventBJ(ts[i], e)
  41.         endif
  42.         call TriggerAddCondition(ts[i], Filter(cond))
  43.     endif
  44. endfunction
  45.  
  46. endlibrary

Examples:
Examples
Condition only
Code: jass  [Select]
  1. scope test initializer init
  2.  
  3. private function Conditions takes nothing returns boolean
  4.     // your code... please DO NOT use waits or triggersleeaction...
  5.     return false // please always set it to false
  6. endfunction
  7.  
  8. private function init takes nothing returns nothing
  9.     // that's the recommended way, it's faster and nice :)
  10.     call RegisterAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function Conditions, null)
  11. endfunction
  12.  
  13. endscope
Action Code Only
Code: jass  [Select]
  1. scope test initializer init
  2.  
  3. private function Actions takes nothing returns nothing
  4.     // your stuff...
  5. endfunction
  6.  
  7. private function init takes nothing returns nothing
  8.     // It's valid but not as faster as using conditions. Use it when you have in the code
  9.     // Polledwait(), triggersleepaction() or wait()
  10.     call RegisterAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, null, function Actions)
  11. endfunction
  12.  
  13. endscope
Condition and action separated
Code: jass  [Select]
  1. scope test initializer init
  2.  
  3. private function Conditions takes nothing returns boolean
  4.     return GetSpellAbilityId() == 'A000'
  5. endfunction
  6.  
  7. private function Actions takes nothing returns nothing
  8.     // your stuff...
  9. endfunction
  10.  
  11. private function init takes nothing returns nothing
  12.     call RegisterAnyUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function Conditions, function Actions)
  13. endfunction
  14.  
  15. endscope

Optionally I can add textmacros for other kind of events, but I left it in this way because this is the most used by me.
« Last Edit: July 25, 2013, 07:49:59 AM by moyack »


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!!
Save your important files fast and easy

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: [Snippet] RegisterAnyUnitEvent
« Reply #1 on: February 09, 2012, 12:48:09 PM »
http://www.hiveworkshop.com/forums/2098379-post2.html

I'm too lazy to type that out again =P

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: [Snippet] RegisterAnyUnitEvent
« Reply #2 on: February 12, 2012, 09:20:29 PM »


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!!
Save your important files fast and easy

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[Snippet] RegisterAnyUnitEvent
« Reply #3 on: July 25, 2013, 07:50:49 AM »
A small make up to the first post has been made :)


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!!
Save your important files fast and easy

 

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

Started by rvonsonsnadtzBoard Codes & Snippets

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

Started by moyackBoard Codes & Snippets

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

Started by moyackBoard Codes & Snippets

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

Started by PurgeandfireBoard Codes & Snippets

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

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 6977
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!!