Jump to content
Heeeere's johnny!

[SCRIPT] Trigger List Changed v2.1 - Handle units which entered/left a trigger's list

Recommended Posts

Trigger List Changed - v2.1

 
This script is about handling units which enter or leave a trigger's list or trigger area respectively. This is different from handling "thisList" or "all units inside/outside the trigger".
It's easy to handle units in the trigger's "thisList", but handling only those which just entered or just left is a different story.
 
Such distinction might be important for instance if a certain value/operation should be added/reduced/applied/executed only on such units or when a unit enters in the very same 0.5 seconds as another unit leaves, which would let the number of units in thisList remain unchanged while one unit is actually different.

 

This function should be executed server side only!

 

Feel free to use, adapt, expand (and maybe give credit if you consider it useful, I'd be grateful :)).
 
news_download_a3_3.png

Download v2.1 from Armaholic

 

Changelogs:

v2.1

- added "isCall" parameter
    -> if true, trigger statements will be called, else they will be spawned
- hardcoded the generated functions into the trigger statements (no setVariable/getVariable anymore)

 

v2.0

- massively overhauled, cleaned and optimized code

 

v1.0

- initial release

 

Have a nice Play!

  • Like 6

Share this post


Link to post
Share on other sites

Somehow, I felt the need to overhaul this thing a bit, ... well ... a bit more, actually.

 

Example to use this script as a function:

_someTrigger = createTrigger ["EmptyDetector", getPosATL player];
_someTrigger setTriggerActivation ["ANY", "PRESENT", true];
_someTrigger setTriggerArea [10, 10, 0, false];
_someTrigger = [
    _someTrigger,
    {hintSilent format ["%1 entered", name _x];},
    {hintSilent "You shall not pass!!!"; _x setDamage 1;},
    true
] call fnc_triggerListChanged;

Have a nice Play! :)

Share this post


Link to post
Share on other sites

Wow, didn't think that this little tweak was worth being put to Armaholic. Thanks. ^_^

 

Somehow, I feel like having to maintain it now... :D

Share this post


Link to post
Share on other sites

Wow, didn't think that this little tweak was worth being put to Armaholic. Thanks. ^_^

 

Somehow, I feel like having to maintain it now... :D

Hi,

 

even the little things should be adhered, too.

Good to know that someone (Foxhound) has an eye for such things.

 

It is well-deserved.

(If someone is searching for this, now he could find it much better.)  ;)

 

Greetings

McLupo

  • Like 1

Share this post


Link to post
Share on other sites

Pretty useful script. I'm workking on a fork/spinoff of F3 template and i would like to include your function as a tool for the editor. Giving you credit of course. Any concerns? (though you already say there are none)

  • Like 1

Share this post


Link to post
Share on other sites

Pretty useful script. I'm workking on a fork/spinoff of F3 template and i would like to include your function as a tool for the editor. Giving you credit of course. Any concerns? (though you already say there are none)

 

No concerns. Thanks for your appreciation. :D

Share this post


Link to post
Share on other sites

please forgive my stupidity, how would i use this for a area protection zone.

 

I would like to have everything under a trigger invincible. (coop mission on nimitz)

 

So i was going to _x addEventHandler ["HandleDamage", {0}];

 

and then,

 

_x removeEventHandler ["HandleDamage", {0}]; (to remove the invincibility )

 

so far i have added a trigger around the nimitz, act: any 

 

I have named the trigger, safezone and added that into the code. 

where do i put this code to get it to work. i have tried in an Init.sqf , and into the trigger itself. I have also tried initplayerlocal. 

 

any help is appreciated

Share this post


Link to post
Share on other sites

please forgive my stupidity, how would i use this for a area protection zone.

 

I would like to have everything under a trigger invincible. (coop mission on nimitz)

 

So i was going to _x addEventHandler ["HandleDamage", {0}];

 

and then,

 

_x removeEventHandler ["HandleDamage", {0}]; (to remove the invincibility )

 

so far i have added a trigger around the nimitz, act: any 

 

I have named the trigger, safezone and added that into the code. 

where do i put this code to get it to work. i have tried in an Init.sqf , and into the trigger itself. I have also tried initplayerlocal. 

 

any help is appreciated

 

Hi lordprimate,

 

I'm very sorry I didn't notice your post, I didn't get a notification that you posted in here. Since your issue is already two months old, I wouldn't doubt you have already found some solution. Nevertheless, let me try to explain this here so if you shouldn't need it, then maybe somebody else might.

 

So, in your case, you don't need to use the trigger inside the "on enter" and "on leave" code. But you were very close with your setup, you just made a small mistake in the removeEventHandler line, namely the second parameter in the array must be a number - the index of the event handler that should be removed. But you put a piece of code "{0}" in there.

 

So, you could setVariable the ID returned by addEventHandler to the unit and then getVariable it again when the unit leaves the area, like this:

_safezone = createTrigger ["EmptyDetector", getPosATL player];
_safezone setTriggerActivation ["ANY", "PRESENT", true];
_safezone setTriggerArea [10, 10, 0, false];
[
	_safezone,
	{_x setVariable ["invincible", _x addEventHandler ["HandleDamage", {0}]];},
	{_x removeEventHandler ["HandleDamage", _x getVariable "invincible"];}
] call fnc_triggerListChanged;

Again, I am very sorry that this comes so lately. I have made sure now that I won't miss a post in here again.

 

Kind regards,

Johnny

  • Like 1

Share this post


Link to post
Share on other sites

Seriously this post should be PINNED!! Such useful tool needs to be highlighted

Share this post


Link to post
Share on other sites

Hi Johnny

 

Just a quick clarification, I need to define this as a CfgFunctions right?

 

Thanks 

C

 

Edit: Yes. ;)

Share this post


Link to post
Share on other sites

So I was fiddling around with area triggers and custom CfgMusic (track are used as ambient).

And I couldn't make to work one simple task: when a player enters trigger zone, specific track starts to play in a loop. When a player leaves the zone, track stops. There should be different zones with different music on the map. Can you help me, please?

 

 

P.S. For SP, MP and dedicated.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×