Jump to content
Sign in to follow this  
_qor

dynamically addAction in trigger

Recommended Posts

Hey there,

I am trying to have a scenario, where the class "MtvrSupply_DES_EP1" (MTVR Supplytruck) can unload ammocrates within a trigger area.

So when a truck is inside the trigger, it gets an action.

Script:

{ while {H1_truck} do {

_x removeAction 0;

_x addAction ["UNLOAD AMMOCRATES","CHECKPOINTS\Ammo\HOME1\ammoUnload.sqf", [],1,false,false,"","((_target distance _this) <8)"];

sleep 5;

};} forEach (entities "MtvrSupply_DES_EP1") in list HOME1trig;

First problem: When multiple trucks inside, they all should have the action. But only the first truck have it. I tried to solve this with a while statement, but this adds it to the first entered vehicle only. Using the same script just as an if statement, it adds the action to each MTVR inside. So how can I add the action dynamically to every truck inside, not just to the first entered?

Second problem: Removing the action. I need to remove only this certain action, but using an index would remove an action this has been added sometime before. Isnt there a way to give the action a global variable?

All in all, the first entered truck receives every 5 seconds a new action and all the other trucks not.

Hope the pursued scenario is clear, and thanks for your helps dudes!

Edited by _qoR

Share this post


Link to post
Share on other sites

{
_x addAction ["UNLOAD AMMOCRATES","CHECKPOINTS\Ammo\HOME1\ammoUnload.sqf", [],1,false,false,"","((_target distance _this) <8) and [HOME1trig,_this] call  bis_fnc_inTrigger"];
} foreach (entities "MtvrSupply_DES_EP1")

that would add the addaction to all vehicles of the type specified but the action would only show when in the trigger area.

It only needs to be run once.

or you could add the action to each object on creation.

in the init.

this addAction ["UNLOAD AMMOCRATES","CHECKPOINTS\Ammo\HOME1\ammoUnload.sqf", [],1,false,false,"","((_target distance _this) <8) and [HOME1trig,_this] call  bis_fnc_inTrigger"];

Share this post


Link to post
Share on other sites

Awesome one!!!

I never really found such bis functions. Is there a wiki or list of them?

Share this post


Link to post
Share on other sites

You can see them in game by placing this in a radio trigger and then call it

[] call BIS_fnc_help;

Share this post


Link to post
Share on other sites

Great!

But there is still one problem with removing the action.

Is there a way to remove only a specific action not an index? It could happen that there are other addAction commands which have been added before.

I need to remove the action on deactivation because there are multiple conditions for the add of the action.

CONDITION:

HOME1 == west AND !HOME1ammo AND "MtvrSupply_DES_EP1" countType list HOME1trig > 0;

OnAct.:

{_x addAction ["UNLOAD AMMOCRATES","CHECKPOINTS\Ammo\HOME1\ammoAction.sqf", [],1,false,false,"","((_target distance _this) <8) and [HOME1trig,_this] call bis_fnc_inTrigger"];} forEach (entities "MtvrSupply_DES_EP1")

Deact.:

{_x removeAction 0} forEach (entities "MtvrSupply_DES_EP1")

When the action is executed, HOME1ammo turns to true. At this time, the action of every MTVR gets removed. But there are other MTVRs in another trigger where HOME2ammo is still false.

EDIT: I just need to make the removeAction forEach entities thislist. But how do I do that? {_x removeAction 0} forEach (entities "MtvrSupply_DES_EP1") thislist doesnt work

Edited by _qoR

Share this post


Link to post
Share on other sites

Triggers are extremely poor for this for several reasons.

Triggers won't repeat if the condition doesn't change so if you want to apply code to each unit entering it will only effect the first unit.

A unit leaving a trigger is not in thislist so can't be detected, only when the last unit leaves will the trigger deactivate.

The next issue is that if this is MP then you can end up in a right mess as each PC creates a trigger so you can end up with multiple actions.

I'm not in to MP scripting so this is more an assumption.

This may or may not work.

set your trigger over the area you want an action added

Blufor present repeating.

Cond

round (time %1) == 1

on act

	{
	if (_x getvariable ["test",-1] == -1 and typeof _x == "MtvrSupply_DES_EP1") then {   
	 act =  _x addAction ["UNLOAD AMMOCRATES","CHECKPOINTS\Ammo\HOME1\ammoAction.sqf", [],1,false,false,"","((_target distance _this) <8)"]; 
	 _x setvariable ["test",act];
	    null = _x spawn {
	     sleep 5;   
		_this removeaction (_this getvariable "test");
		  _this setvariable ["test",-1];
   } } } foreach thislist

What should happen is that any vehicle type "MtvrSupply_DES_EP1" will have the action added, after 5 seconds it will be removed and re-applied unless you leave the area in which case it will be deleted.

The trigger is being forced to repeat even if other units are inside because of this round (time %1) == 1

Share this post


Link to post
Share on other sites

Seems to works only for the first entered MTVR.

Unfortunately I cant retrace how the script should run so I cant adapt it...

Share this post


Link to post
Share on other sites

Sorry I dont get how the scripts working ;D

I tried to keep doing it on my way and it seems that it works when I give all the different actions a different name, logically.

So I can remove them individually by name. Didnt know that this works, but it actually does :)

I keep watching if the script runs without faults...

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
Sign in to follow this  

×