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] RegisterPlayerUnitEvent

Magtheridon96 · 25154

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: January 18, 2018, 10:19:13 PM by moyack »

[Snippet] RegisterPlayerUnitEvent
on: July 09, 2012, 01:29:49 PM
Category: Execution
Language: JASS, vJASS

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
  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
  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: December 19, 2017, 11:35:55 PM by moyack »



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



Re: Re: [Snippet] RegisterPlayerUnitEvent
Reply #2 on: July 14, 2012, 06:08:34 AM

When I use this:
Code: jass
  1. RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT,function bla,bla)

everything is working properly

But when I use this:
Code: jass
  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?


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



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


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



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.


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



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.


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



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.


Re: [Snippet] RegisterPlayerUnitEvent
Reply #11 on: July 17, 2012, 02:16:53 PM

I figured what's the problem yeahhhhhhhhh!!!
Problem solved.



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


Re: [Snippet] RegisterPlayerUnitEvent
Reply #13 on: August 05, 2012, 09:50:08 AM

Oh yay, I don't have to do any fixes :D



Re: [Snippet] RegisterPlayerUnitEvent
Reply #14 on: October 09, 2012, 01:37:03 PM

Updated! :D
NOW MICROSECONDS FASTER.



Re: [Snippet] RegisterPlayerUnitEvent
Reply #15 on: October 11, 2012, 09:27:33 PM

Updated! :D
NOW MICROSECONDS FASTER.

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


 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod