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

Author Topic: [Snippet] RegisterPlayerUnitEvent  (Read 22433 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] RegisterPlayerUnitEvent
« on: July 09, 2012, 01:29:49 PM »
I'm attempting to start up some activity over here by posting/spamming resources :P.

This system was made to replace that cumbersome GTrigger by Jesus4Lyf.
Special thanks to Bribe, azlier and BBQ. (The most awesome people I know /o/)

Code: jass  [Select]
  1. /**************************************************************
  2. *
  3. *   RegisterPlayerUnitEvent
  4. *   v5.1.0.1
  5. *   By Magtheridon96
  6. *
  7. *   I would like to give a special thanks to Bribe, azlier
  8. *   and BBQ for improving this library. For modularity, it only
  9. *   supports player unit events.
  10. *
  11. *   Functions passed to RegisterPlayerUnitEvent must either
  12. *   return a boolean (false) or nothing. (Which is a Pro)
  13. *
  14. *   Warning:
  15. *   --------
  16. *
  17. *       - Don't use TriggerSleepAction inside registered code.
  18. *       - Don't destroy a trigger unless you really know what you're doing.
  19. *
  20. *   API:
  21. *   ----
  22. *
  23. *       - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
  24. *           - Registers code that will execute when an event fires.
  25. *       - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
  26. *           - Registers code that will execute when an event fires for a certain player.
  27. *       - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
  28. *           - Returns the trigger corresponding to ALL functions of a playerunitevent.
  29. *
  30. **************************************************************/
  31. library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
  32.     globals
  33.         private trigger array t
  34.     endglobals
  35.    
  36.     function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
  37.         local integer i = GetHandleId(p)
  38.         local integer k = 15
  39.         if t[i] == null then
  40.             set t[i] = CreateTrigger()
  41.             loop
  42.                 call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
  43.                 exitwhen k == 0
  44.                 set k = k - 1
  45.             endloop
  46.         endif
  47.         call TriggerAddCondition(t[i], Filter(c))
  48.     endfunction
  49.    
  50.     function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
  51.         local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
  52.         if t[i] == null then
  53.             set t[i] = CreateTrigger()
  54.             call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
  55.         endif
  56.         call TriggerAddCondition(t[i], Filter(c))
  57.     endfunction
  58.    
  59.     function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
  60.         return t[GetHandleId(p)]
  61.     endfunction
  62. endlibrary

Here's a vanilla Jass version:

Code: jass  [Select]
  1. //**************************************************************
  2. //*
  3. //*   RegisterPlayerUnitEvent (Vanilla Jass)
  4. //*   v5.1.0.1
  5. //*   By Magtheridon96
  6. //*
  7. //*   I would like to give a special thanks to Bribe, azlier
  8. //*   and BBQ for improving this library. For modularity, it only
  9. //*   supports player unit events.
  10. //*
  11. //*   Functions passed to RegisterPlayerUnitEvent must either
  12. //*   return a boolean (false) or nothing. (Which is a Pro)
  13. //*
  14. //*   Implementation:
  15. //*   ---------------
  16. //*
  17. //*       - Copy all this script into a new trigger called "RegisterPlayerUnitEvent Jass"
  18. //*       - Create a trigger array variable called RPUE.
  19. //*       - Done.
  20. //*
  21. //*   Warning:
  22. //*   --------
  23. //*
  24. //*       - Don't use TriggerSleepAction inside registered code.
  25. //*       - Don't destroy a trigger unless you really know what you're doing.
  26. //*
  27. //*   API:
  28. //*   ----
  29. //*
  30. //*       - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
  31. //*           - Registers code that will execute when an event fires.
  32. //*       - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
  33. //*           - Registers code that will execute when an event fires for a certain player.
  34. //*       - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
  35. //*           - Returns the trigger corresponding to ALL functions of a playerunitevent.
  36. //*
  37. //**************************************************************
  38. function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
  39.     local integer i = GetHandleId(p)
  40.     local integer k = 15
  41.     if udg_RPUE[i] == null then
  42.         set udg_RPUE[i] = CreateTrigger()
  43.         loop
  44.             call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], Player(k), p, null)
  45.             exitwhen k == 0
  46.             set k = k - 1
  47.         endloop
  48.     endif
  49.     call TriggerAddCondition(udg_RPUE[i], Filter(c))
  50. endfunction
  51.  
  52. function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
  53.     local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
  54.     if udg_RPUE[i] == null then
  55.         set udg_RPUE[i] = CreateTrigger()
  56.         call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], pl, p, null)
  57.     endif
  58.     call TriggerAddCondition(udg_RPUE[i], Filter(c))
  59. endfunction
  60.  
  61. function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
  62.     return udg_RPUE[GetHandleId(p)]
  63. endfunction
  64.    
  65. function InitTrig_RegisterPlayerUnitEvent_Jass takes nothing returns nothing
  66. endfunction

Feel free to comment.
« Last Edit: October 09, 2012, 01:36:37 PM by Magtheridon96 »

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: [Snippet] RegisterPlayerUnitEvent
« Reply #1 on: July 14, 2012, 02:29:27 AM »
When I use this:
Code: [Select]
RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT,function bla,bla)
everything is working properly

But when I use this:
Code: [Select]
RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function bla,bla)
spell/skill does not work.

Does anyone know what the problem is?!?

  • 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: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #2 on: July 14, 2012, 06:08:34 AM »
When I use this:
Code: jass  [Select]
  1. RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT,function bla,bla)

everything is working properly

But when I use this:
Code: jass  [Select]
  1. RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function bla,bla)

spell/skill does not work.

Does anyone know what the problem is?!?
Could you provide us with the spell code?

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...

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: Re: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #3 on: July 14, 2012, 09:20:59 AM »
Could you provide us with the spell code?

Okay, no problem.

When I try to use this:
Code: jass  [Select]
  1. function SkillHeatActions takes nothing returns boolean
  2.     // bla,bla
  3.     return true
  4. endfunction
  5.  
  6. function StartTrigger_Skill_Heat takes nothing returns nothing
  7.     local trigger=CreateTrigger()
  8.     call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
  9.     call TriggerAddCondition(t,Condition(function SkillHeatActions))
  10.     call Preload(H_ModelPath())
  11.     set t=null
  12. endfunction

Everything works perfectly,and when I try this
Code: jass  [Select]
  1. function SkillHeatActions takes nothing returns boolean
  2.    // bla,bla
  3.     return true
  4. endfunction
  5.  
  6. function StartTrigger_Skill_Heat takes nothing returns nothing
  7.     call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function SkillHeatActions)
  8.     call Preload(H_ModelPath())
  9. endfunction

simply will not work...???




« Last Edit: July 14, 2012, 09:24:43 AM by moyack »

  • 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: Re: Re: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #4 on: July 14, 2012, 10:25:57 AM »
Okay, no problem.

When I try to use this:
Code: jass  [Select]
  1. function SkillHeatActions takes nothing returns boolean
  2.     // bla,bla
  3.     return true
  4. endfunction
  5.  
  6. function StartTrigger_Skill_Heat takes nothing returns nothing
  7.     local trigger=CreateTrigger()
  8.     call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
  9.     call TriggerAddCondition(t,Condition(function SkillHeatActions))
  10.     call Preload(H_ModelPath())
  11.     set t=null
  12. endfunction

Everything works perfectly,and when I try this
Code: jass  [Select]
  1. function SkillHeatActions takes nothing returns boolean
  2.    // bla,bla
  3.     return true
  4. endfunction
  5.  
  6. function StartTrigger_Skill_Heat takes nothing returns nothing
  7.     call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function SkillHeatActions)
  8.     call Preload(H_ModelPath())
  9. endfunction

simply will not work...???

IS this function inside a scope? if so, try changing it into a library with the respective requirements

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...

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: Re: Re: Re: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #5 on: July 14, 2012, 12:46:36 PM »
IS this function inside a scope? if so, try changing it into a library with the respective requirements

I think the problem is not what you said
For Example:When I use the event EVENT_PLAYER_UNIT_SPELL_EFFECT everything is working well,but when I want to use the event EVENT_PLAYER_HERO_SKILL then there is a problem,spell/skill will not work.

Which means that only that specific event causes error.

Because it is logical that, if this works

Code: jass  [Select]
  1. function StartTrigger_Skill_Heat takes nothing returns nothing
  2.     local trigger=CreateTrigger()
  3.     call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
  4.     call TriggerAddCondition(t,Condition(function SkillHeatActions))
  5.     call Preload(H_ModelPath())
  6.     set t=null
  7. endfunction

and this will not work

Code: jass  [Select]
  1. function StartTrigger_Skill_Heat takes nothing returns nothing
  2.     call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function SkillHeatActions)
  3.     call Preload(H_ModelPath())
  4. endfunction

that there is a conflict with the system
I think this event[EVENT_PLAYER_HERO_SKILL] has a conflict with the system

  • 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] RegisterPlayerUnitEvent
« Reply #6 on: July 14, 2012, 04:39:42 PM »
Hmmm.... have you debugged it??? I mean if this even start at all?? I hope you're not using TriggerSleepAction() or PolledWait() in the condition because it breaks the thread.

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...

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #7 on: July 14, 2012, 07:11:38 PM »
Hmmm.... have you debugged it??? I mean if this even start at all?? I hope you're not using TriggerSleepAction() or PolledWait() in the condition because it breaks the thread.

I never use TriggerSleepAction and PolledWait func

  • 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: Re: Re: [Snippet] RegisterPlayerUnitEvent
« Reply #8 on: July 14, 2012, 07:22:24 PM »
I never use TriggerSleepAction and PolledWait func
That's a relief :)

just in case... try my snippet to see if it's Mag's version.

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...

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: [Snippet] RegisterPlayerUnitEvent
« Reply #9 on: July 15, 2012, 11:55:39 AM »
I have tested your system for some time, and the results are as follows:

RegisterAnyUnitEvent Condition:
Code: jass  [Select]
  1. function InitTrig_Skill_Heat takes nothing returns nothing
  2.     call RegisterAnyUnitEvent(EVENT_PLAYER_HERO_SKILL,function HeatMainAct,null)
  3. endfunction
  4.  

1.Impression:Works perfectly.
2.Opinion:Very stable.
3.Errors:No errors found.

RegisterAnyUnitEvent Action:
Code: jass  [Select]
  1. function InitTrig_Skill_Heat takes nothing returns nothing
  2.     call RegisterAnyUnitEvent(EVENT_PLAYER_HERO_SKILL,null,function HeatAddDamageAct)
  3. endfunction
  4.  

1.Impression:Works perfectly.
2.Opinion:Very stable.
3.Errors:No errors found.

RegisterAnyUnitEvent Condition/Action:
Code: jass  [Select]
  1. function InitTrig_Skill_Heat takes nothing returns nothing
  2.     call RegisterAnyUnitEvent(EVENT_PLAYER_HERO_SKILL,function RegisterSkillHeat,function HeatMainAct)
  3. endfunction
  4.  

1.Impression:Works perfectly.
2.Opinion:Very stable.
3.Errors:No errors found.

TriggerRegisterAnyUnitEventBJ:
Code: jass  [Select]
  1. function InitTrig_Skill_Heat takes nothing returns nothing
  2.     local trigger=CreateTrigger()
  3.     call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL)
  4.     call TriggerAddCondition(t,Condition(function HeatMainAct))
  5.     set t=null
  6. endfunction
  7.  

1.Impression:Works perfectly.
2.Opinion:Stable.
3.Errors:No errors found.

RegisterPlayerUnitEvent:
Code: jass  [Select]
  1. function InitTrig_Skill_Heat takes nothing returns nothing
  2.     call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_SKILL,function HeatMainAct)
  3. endfunction
  4.  

1.Impression:Not working properly.
2.Opinion:Very unstable,especially with "EVENT_PLAYER_HERO_SKILL".
3.Errors:Can cause errors.
4.Note: I still have not found the reason why this event["EVENT_PLAYER_HERO_SKILL"] in some cases,cause problems.

  • 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] RegisterPlayerUnitEvent
« Reply #10 on: July 16, 2012, 06:54:19 AM »
I need to get some time to test this event, but, meanwhile try to use the functions inside a library. I had that kind of issue in my project Power of Corruption and the problem was that I was using scopes, changing them into libraries solved the issues.

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...

  • Lurker - level 4
  • ****
  • Posts: 6
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • Reputation: 2
  • User
    • View Profile
Re: [Snippet] RegisterPlayerUnitEvent
« Reply #11 on: July 17, 2012, 02:16:53 PM »
I figured what's the problem yeahhhhhhhhh!!!
Problem solved.

  • 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] RegisterPlayerUnitEvent
« Reply #12 on: July 17, 2012, 08:32:26 PM »
I figured what's the problem yeahhhhhhhhh!!!
Problem solved.
Hmmm good :)

What was the problem??

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] RegisterPlayerUnitEvent
« Reply #13 on: August 05, 2012, 09:50:08 AM »
Oh yay, I don't have to do any fixes :D

  • 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] RegisterPlayerUnitEvent
« Reply #14 on: October 09, 2012, 01:37:03 PM »
Updated! :D
NOW MICROSECONDS FASTER.

  • 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] RegisterPlayerUnitEvent
« Reply #15 on: October 11, 2012, 09:27:33 PM »
Updated! :D
NOW MICROSECONDS FASTER.

WOAHHH!!! that's FAST!!! :D

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...

 

[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!!