Snippet TriggerRegisterAnyUnitEvent

PurgeandFire

zxcvmkgdfg
Reaction score
509
An improved version of TriggerRegisterAnyUnitEventBJ().

I didn't do much to change other than to fix the leak each time running. Thanks to builder Bob for pointing out the flaw in my last one.

JASS:
library TRAUE
    private function True takes nothing returns boolean
        return true
    endfunction
    function TriggerRegisterAnyUnitEvent takes trigger t, playerunitevent pue returns nothing
        local integer i = 0
        loop
            exitwhen i==16
            call TriggerRegisterPlayerUnitEvent(t,Player(i),pue,Condition(function True))
            set i = i + 1
        endloop
    endfunction
endlibrary


NOTE: If you have a global "True" dummy function, it might be better to use that instead of the TRAUE one. And you should simply inline this code, it isn't too much to.

Btw, TRAUE stands for TriggerRegisterAnyUnitEvent.

Enjoy. No credits needed... It is exactly same as TriggerRegisterAnyUnitEventBJ() but just a dummy filter.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
You can create a function named "True" exactly like mine (same stuff within too), then simply C'n'p this code:
JASS:


And adjust it accordingly.

Thanks, I always pondered whether this would work, so I tested it a long time ago with messages and it seemed to work.

I tested this code with an EVENT_PLAYER_UNIT_DEATH or w/e and it worked fine.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
It works exactly as TriggerRegisterAnyUnitEventBJ().

It registers if any unit does the specified event, but uses less execution calls and doesn't leak each time run.
 

Builder Bob

Live free or don't
Reaction score
249
Thanks, I always pondered whether this would work, so I tested it a long time ago with messages and it seemed to work.

I tested this code with an EVENT_PLAYER_UNIT_DEATH or w/e and it worked fine.

I'm going to sound very negative now... Sorry if I'm wrong.

It's not exactly the same as TriggerRegisterAnyUnitEventBJ() as I see it. For each player in the game, the trigger will only be registered for his units. If any non local code is used in the trigger's condition/action, the game will desync, because it will only happen in one player's instance of the game.

Also, it does not register any computer controlled units.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Did you test if it desyncs?

Yeah, I totally forgot about some of those stuff. Thanks for the post which jogged my memory, I'll have to test it.

But I don't think it should desync, because it is simply registering the event for the local player. After creating something, why would it desync because it is registering the event for the player, not a local player block or doing the functions for that player. But I'm not sure. If anyone is willing to test it, be my guest.
 

Builder Bob

Live free or don't
Reaction score
249
No, I can only verify that it doesn't work for computer controlled units. I don't have another computer so I can't test any GetLocalPlayer() code myself.

I'll clarify what I mean about the desync issue. It will probably not desync when you register the event. However, once the event triggers, it will desync if the action/condition function contains anything that is not supposed to be run only locally.

Let's say you create a unit on a death event. The unit will only exist for the player owning the unit. For every other player, it will be as if nothing happened.


Still, it would be good to have confirmation. I hope someone can test this. My understanding may be wrong, as I have only read what I know about GetLocalPlayer().
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I understood what you meant, and I tested it and it seems that you are right. Hm... I don't want to remove this resource though, so I will simply make it like like TriggerRegisterAnyUnitEventBJ() but use the filter instead. ;P

Thanks. I updated it but it doesn't really serve much of a purpose. xD

Just a simple "tip" I guess to prevent leaks.
 

Builder Bob

Live free or don't
Reaction score
249
Almost wish I wasn't. Looked so neat without the loop.

So using null as a filter really creates a leak? I didn't know that. It's so odd that some of the default functions causes leaks.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
@Builder Bob: http://wc3campaigns.net/showthread.php?t=100575

JASS:
exitwhen i>16

Should be:
JASS:
exitwhen i==16

It will register for 1-16. If the exitwhen was after the event, it would be "i==16", since it is before the event, I will use "i>16". So it will keep jumping and then when i == 16, it will loop once more for the "i = 16", then it will go to 17, the exitwhen will catch it, and it will exit the loop.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top