Jump to content
fn_Quiksilver

[RELEASE] Add action to trees

Recommended Posts

A9DFE16FFD5B09F9D5D6A69F4B2AA7BA9273F4B3

 

 

 

After an interesting question on the arma 3 discord, about how to add actions to trees, here is what we came up with.

 

Paste this block somewhere that the client machine will execute it (init.sqf, initplayerlocal.sqf, etc)

comment "Paste this block somewhere that the clients machine will execute it.";
if (isDedicated) exitWith {};
if (!hasInterface) exitWith {};
tag_fnc_myTreeCode = {
	comment 'This is your tree function!';
	_cursorObject = cursorObject;
	if (!(['\tree\',((getModelInfo _cursorObject) select 1),FALSE] call BIS_fnc_inString)) exitWith {titleText ['Sorry Im nota tree!','PLAIN',1];};
	titleText ['Hello human','PLAIN',1];
	
};
tag_fnc_isTargetTree = {
    private _return = FALSE;
	_cursorObject = cursorObject;
	if (!isNull _cursorObject) then {
		if ((player distance _cursorObject) < 10) then {
			_modelInfo = getModelInfo _cursorObject;
			if (!(_modelInfo isEqualTo [])) then {
				if (['\tree\',(_modelInfo select 1),FALSE] call BIS_fnc_inString) then {
					_return = TRUE;
				};
			};
		};
	};
    _return;
};
tag_var_action = [
	'Hello tree',
	tag_fnc_myTreeCode,
	nil,
	50,
	TRUE,
	TRUE,
	'',
	'[] call tag_fnc_isTargetTree',
	5,
	FALSE
];
player addAction tag_var_action;
player addEventHandler [
	'Respawn',
	{
		player addAction tag_var_action;	
	}
];

The client will be able to walk up and scroll on a tree. Edit the code above for your uses.

  • Like 6

Share this post


Link to post
Share on other sites

I Hope you add an option to hug trees  ;)

  • Like 5

Share this post


Link to post
Share on other sites

Alternatively you could also use nearestTerrainObjects to retrieve the trees.

 

Not really a good alternative though. Besides, you still wouldn't be able to add actions directly to them.

cursorObject is the right way to go!

 

 

ps.: In general this is a great way to add interaction with a large amount of objects, without having to use addAction on every single one of them.

Share this post


Link to post
Share on other sites

Clever idea, done this a little differently to make objects lootable. Wink wink for survival scripters.

  • Like 1

Share this post


Link to post
Share on other sites

Clever idea, done this a little differently to make objects lootable. Wink wink for survival scripters.

 

Yep

 

The guy who asked how to go about adding action to trees, wanted it for some sort of farming/logging in Life mod. 

 

Only catch is simple objects don't have namespace, so you won't be able to attach variable directly to the object, you would have to create your own scripted namespace to hold the object and any associated data.

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

×