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.

      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