Jump to content
jakkob4682

adding an action to an object

Recommended Posts

not like using the addAction command but making an object interactive so for instance giving the ability to open a container/ plant a charge etc.  

Share this post


Link to post
Share on other sites

I want to enable object interaction.  As in opening a container/placing an object etc where you hold a button down to complete the action and after so long the action is completed.  If that makes sense.

Share this post


Link to post
Share on other sites

Opening a container and placing an object are likely two very different things within your context. And holding a button down to compete an action is an addAction, specifically https://community.bistudio.com/wiki/BIS_fnc_holdActionAdd. There's no explicit enabling or disabling of an "interaction system". So like Harzach said, you're going to have to be specific about exactly what you're trying to do. 

  • Like 2

Share this post


Link to post
Share on other sites

As the rest of the people have said above, you should be a bit more precise on what you are trying to achieve. I will try to provide a random example based on my understanding of your question.

 

In this example, you should place a tablet somewhere and create a small Tanoa hangar, the one with the two sliding doors. In my example, I named the tablet object tablet and the hangar structure hangar (no wayyyy :D). So you could do the following in order to make the two sliding doors animate based on an actions attached to the tablet.

// Add open holdAction to the tablet
[
tablet, // Object the action is attached to
"Open hangar doors",  // The title of the action
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_hack_ca.paa", // Idle icon shown on screen
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_hack_ca.paa", // Progress icon shown on screen
"_this distance _target < 3", // Condition for the action to be shown
"_this distance _target < 3", // Condition for the action to progress
{}, // Code executed on action start,
{ // Code executed on every progress tick
	private _hangar = (_this select 3) select 0; // Get the hangar
	private _animPhase = _hangar animationSourcePhase "Door_2_Sound_Source"; // Get the current phase of the doors
	private _animToGo = 1/(_this select 4); // Get the animation phase to move to
	if(_animPhase <= _animToGo) then { // Check if door is already midway
		_hangar animateSource["Door_2_Sound_Source", _animToGo]; // Open left door
		_hangar animateSource["Door_3_Sound_Source", _animToGo]; // Open right door
    };
}, // End of code executed on every progress tick
{}, // Code executed when action completed
{}, // Code executed when action interrupted
[hangar], // Arguments passed to the script as _this select 3
12, // Duration of action
0, // Priority
false, // Remove completed
false, // Show unconsious
true /* Show on screen */] call BIS_fnc_holdActionAdd;
                              
// Add close holdAction to the tablet
[
tablet, // Object the action is attached to
"Close hangar doors",  // The title of the action
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_hack_ca.paa", // Idle icon shown on screen
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_hack_ca.paa", // Progress icon shown on screen
"_this distance _target < 3", // Condition for the action to be shown
"_this distance _target < 3", // Condition for the action to progress
{}, // Code executed on action start,
{ // Code executed on every progress tick
	private _hangar = (_this select 3) select 0; // Get the hangar
	private _animPhase = _hangar animationSourcePhase "Door_2_Sound_Source"; // Get the current phase of the doors
	private _animToGo = 1 - (1/(_this select 4)); // Get the animation phase to move to
	if(_animPhase >= _animToGo) then { // Check if door is already midway
		_hangar animateSource["Door_2_Sound_Source", _animToGo]; // Open left door
		_hangar animateSource["Door_3_Sound_Source", _animToGo]; // Open right door
    };
}, // End of code executed on every progress tick
{}, // Code executed when action completed
{}, // Code executed when action interrupted
[hangar], // Arguments passed to the script as _this select 3
12, // Duration of action
0, // Priority
false, // Remove completed
false, // Show unconsious
true /* Show on screen */] call BIS_fnc_holdActionAdd;

Two actions are attached to the object, one to open the doors and the other to close the doors. You could possibly refine the code here and optimize a bit but I hope you do get the basic idea.

 

One more thing to note here is that using addActions is not a great way to do things because the conditions are checked at (almost) every frame which can end up in a significant performance degradation if many addActions are used in a mission. You could possibly add a trigger which will be activated by the players, with an area about 5 metres around the object to which you attach the actions, and attach the actions when the trigger is triggered (:|). And when people leave the area, remove the actions. This way, you can set the trigger condition check to a rather low value and ease the burden on the CPU.

 

Finally, please note that the above code is not tested and may contain syntactic and/or logical errors. Please test before use.

 

Let us know if this helps you somehow or if you may have more questions and or issues.

 

Have fun, stay safe and ArmA a lot 🙂.

Share this post


Link to post
Share on other sites
1 hour ago, ZaellixA said:

One more thing to note here is that using addActions is not a great way to do things because the conditions are checked at (almost) every frame which can end up in a significant performance degradation if many addActions are used in a mission. You could possibly add a trigger which will be activated by the players, with an area about 5 metres around the object to which you attach the actions, and attach the actions when the trigger is triggered (:|). And when people leave the area, remove the actions. This way, you can set the trigger condition check to a rather low value and ease the burden on the CPU.

Sorry for "pirating" this post and taking advantage of your knowledge... I have more or less about 20 holdActions/addActions in one of my WIP mission (SP/Tanoa); should I be worried and convert them to the "trigger-solution" you suggested?

Thank you.

Share this post


Link to post
Share on other sites
23 minutes ago, zagor64bz said:

Sorry for "pirating" this post and taking advantage of your knowledge... I have more or less about 20 holdActions/addActions in one of my WIP mission (SP/Tanoa); should I be worried and convert them to the "trigger-solution" you suggested?

Thank you.

Arma Wiki:

Quote

If action is added to an object (and not to player) condition will only get evaluated IF player is closer than ~50m to the object surface AND is looking at the object.

So doing it trigger way is needless.

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, Cysiu said:

Arma Wiki:

Quote

If action is added to an object (and not to player) condition will only get evaluated IF player is closer than ~50m to the object surface AND is looking at the object.

So doing it trigger way is needless.

Thank you, I've got what I was looking for.😉

  • Like 1

Share this post


Link to post
Share on other sites
14 hours ago, beno_83au said:

Thank you this is exactly what I was looking for

 

9 hours ago, ZaellixA said:

As the rest of the people have said above, you should be a bit more precise on what you are trying to achieve. I will try to provide a random example based on my understanding of your question.

 

In this example, you should place a tablet somewhere and create a small Tanoa hangar, the one with the two sliding doors. In my example, I named the tablet object tablet and the hangar structure hangar (no wayyyy :D). So you could do the following in order to make the two sliding doors animate based on an actions attached to the tablet.

Yeah after reading Beno's response that's what I was looking for now to implement it!! Thanks guys.

  • Like 2

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

×