Jump to content
quarren_

Need help with custom wrapper function for BIS_fnc_holdActionAdd

Recommended Posts

Hi guys,

 

this is probably a beginner question, be advised. Here we go.

 

What I'm trying to do:

 

I want to have some "recruitable" squadmates placed around the map that the player can interact with using the "hold space bar"-feature The idea was to write a wrapper function for BIS_fnc_holdActionAdd, so I can just go into the init-fields of each unit and put something simple like '[this] call addHoldActionJoinSquad;' without having to paste loads of text in there.

 

I have the following inside a file called "addHoldActionJoinSquad.sqf" located in the mission directory:

private _attach_target = _this select 0;

[_attach_target,
 "ask to join",
 "\A3\Ui_f\data\IGUI\Cfg\HoldActions\holdAction_takeOff1_ca.paa",
 "\A3\Ui_f\data\IGUI\Cfg\HoldActions\holdAction_takeOff1_ca.paa",
 "_target distance _this < 3",
 "true",
 {},
 {},
 { [_attach_target] join player; },
 {},
 [],
 2,
 nil,
 true,
 false] call BIS_fnc_holdActionAdd;

And the following inside my Description.ext:

class CfgFunctions
{
    class TST
    {
        class Util
        {
            class addHoldActionJoinSquad {file = "addHoldActionJoinSquad.sqf";};
        };
    };
};

When I load the mission in Eden Editor and preview it, I can see that the function shows up in the "Function viewer"-Tool.

 

When I put '[this] call addHoldActionJoinSquad;' inside the init-field of my units, no hold action shows up. It works when I just put the BIS_fnc_holdActionAdd function in there - with different parameters of course, i.e. 'this'/'_this' instead of '_attach_target' etc.

 

This is the first time I tried to define my own functions in ARMA, so I must be doing something wrong here.

 

Thanks a lot,

quarren

Share this post


Link to post
Share on other sites

@quarren_,

This is how I do it,

Spoiler

this setVariable ["MMF_isRecruit", 0]; // paste in unit init
[player] call MMF_fnc_recruit; // paste in init dialog or init.sqf

MMF_fnc_recruit=
{	params ["_caller"];

	if (_caller== player) then {
recruitAction=[ player, "Recruit Unit", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_connect_ca.paa", 
"player distance cursorTarget<5 && (cursorTarget getvariable ""MMF_isRecruit"") <1", "playerSide isEqualTo side cursorTarget", {}, {}, { 
[cursorTarget] call MMF_fnc_recruit;
}, {}, [], 2, 0, false, true] call BIS_fnc_holdActionAdd;
	} else {

	[_caller] join (group player);
	systemChat "Recruit hired";
	_caller setVariable ["MMF_isRecruit", 1];
dismissAction=_caller addAction ["Dismiss", "[_this select 0] join grpNull; (_this select 0) setVariable [""MMF_isRecruit"", 0]; (_this select 0) removeAction dismissAction;"];
_caller addEventHandler ["Killed", {
				(_this select 0) removeAction dismissAction;
				}];
	};
};

Paste the function and call in your init.sqf or init dialog. Recruited units may be dismissed.


Have fun!

Share this post


Link to post
Share on other sites
6 hours ago, quarren_ said:

And the following inside my Description.ext:


class CfgFunctions
{
    class TST
    {
        class Util
        {
            class addHoldActionJoinSquad {file = "addHoldActionJoinSquad.sqf";};
        };
    };
};
6 hours ago, quarren_ said:

When I put '[this] call addHoldActionJoinSquad;' inside the init-field of my units, no hold action shows up.

 

As you have compiled the function TST_fnc_addHoldActionJoinSquad.

class CfgFunctions
{
    class TST	//Tag
    {
        class Util	//FunctionViewers Category
        {
            class addHoldActionJoinSquad {file = "addHoldActionJoinSquad.sqf";};	//Name of function { file to compile }
        } ;
    };
};

TAG_fnc_functionName see the Function Library for more info.

 

Share this post


Link to post
Share on other sites

@wogz187: Thanks for that. So your approach is to attach the hold action to the player if he is close to a recruitable unit and recursively call that function on the unit to make it join the squad. I will definitely use your script if I can't fix mine at all.

 

@Larrow: Thank you. I figured that one out shortly after posting here. I was then able to call the function on my units after that. (Got some more error messages then though that I haven't yet figured out😀)

  • Like 1

Share this post


Link to post
Share on other sites

Got everything to work, in case anyone is interested in the solution: 

// addActionJoinSquad.sqf

_attach_target = _this select 0;

[_attach_target,
 "ask to join",
 "\A3\Ui_f\data\IGUI\Cfg\HoldActions\holdAction_takeOff1_ca.paa",
 "\A3\Ui_f\data\IGUI\Cfg\HoldActions\holdAction_takeOff1_ca.paa",
 "_target distance _this < 3",
 "true",
 {},
 {},
 {[_target] joinSilent player;},
 {},
 [],
 2,
 nil,
 true,
 false] call BIS_fnc_holdActionAdd;
// Description.ext
class CfgFunctions
{
    class TST
    {
        class Util
        {
            class addHoldActionJoinSquad {file = "addHoldActionJoinSquad.sqf";};
        };
    };
};
// unit's init field
[this] call TST_fnc_addHoldActionJoinSquad;

 

  • Like 1

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

×