Jump to content

Recommended Posts

I've been working on a little lightweight recruitment and dismissing script for editor placed AI units. So far it works well in single player games, as you can recruit and dismiss AI units repeatedly and at will.

In my noobiness, I decided to achieve this via 4 small .sqf files inside a folder called wRecruit:

 

recruiting.sqf - file content below:

 

/*  Usage: put this in INIT of the unit to be recruited;
nul=[this] execVM "wRecruit\recruiting.sqf";
*/
_guyNotRecruited = true;

_fng = _this select 0;

_fng setcaptive true;

_recruitGuy = _fng addAction ["Recruit","wRecruit\newguyinit.sqf"];

while {_guyNotRecruited}
    do
    {
if (not(captive _fng)) then {_guyNotRecruited = false};
if (not alive _fng) exitwith {_fng removeAction _recruitGuy};
sleep 1;
    };
_fng removeAction _recruitGuy;

[_fng] join (group player);

_fng enableAI "MOVE";
sleep 1;

nul = [[["New Team Member recruited.","<t align='center' shadow='2' size='0.7'>%1</t><br/>"],["","<t align='center' shadow='2' size='0.7'>%1</t><br/>"],["","<t align='center' shadow='2' size='0.7'>%1</t>"]]] spawn BIS_fnc_typeText;
sleep 5;

nul=[_fng] execVM "wRecruit\dismissing.sqf";

__________________________________________________________

newguyinit.sqf - file content below:

 

// set unit not captive
_unit=_this select 0;
_unit setCaptive false;

__________________________________________________________

dismissing.sqf - file content below:

 

_guyRecruited = true;

_fng = _this select 0;

_dropGuy = _fng addAction ["Dismiss","wRecruit\dropguyinit.sqf"];

while {_guyRecruited}
    do
    {
if (captive _fng) then {_guyRecruited = false};
if (not alive _fng) exitwith {_fng removeAction _dropGuy};
sleep 1;
    };
_fng removeAction _dropGuy;

[_fng] join grpNull;

_fng setCaptive true;

sleep 1;


if (not alive _fng)
    then
        {
            hint "Team member deceased";
        }
            else
                {
                    nul = [[["Team Member dismissed.","<t align='center' shadow='2' size='0.7'>%1</t><br/>"],["","<t align='center' shadow='2' size='0.7'>%1</t><br/>"],["","<t align='center' shadow='2' size='0.7'>%1</t>"]]] spawn BIS_fnc_typeText;
                    nul=[_fng] execVM "wRecruit\recruiting.sqf";
                };

            sleep 5;

____________________________________________________

dropguyinit.sqf - file content below:

 

// set unit captive
_unit=_this select 0;
_unit setCaptive true;

 

_____________________________________________________

 

This works well in single player but I would love to know how to make this multiplayer-compatible without  making the script too big or cumbersome. ??

Also, how would I be able to implement this on units spawned in-game by other scripts?

 

I used setCaptive as the condition needed to achieve the effect I wanted but I'm sure there are different ways or conditions that could be used similarly?

Edited by Theo Thalwitzer
Adding information
  • Like 1

Share this post


Link to post
Share on other sites

Hello there @Theo Thalwitzer and welcome also to BI Forum !

 

Here is a dfferent approach , without loops , working also with spawned units:

Spoiler

//________________	GF_Join_Disband	________________

GF_Join_Disband_Side 			= playerSide;




GF_Join_Disband_Killed = {

	_unit = _this select 0;
	
	if(isMultiplayer)then{

		_unit addMPEventHandler ["MPKilled", {
			params ["_unit", "_killer", "_instigator", "_useEffects"];
			removeAllActions _unit;
			_unit setVariable ["Var_GF_Join_Disband",false];
		}];
	}else{
	
		_unit addEventHandler ["Killed", {
			params ["_unit", "_killer", "_instigator", "_useEffects"];
			removeAllActions _unit;
			_unit setVariable ["Var_GF_Join_Disband",false];
		}];
	};	
};


GF_Join_Disband = {

	_unit = _this select 0;
	
	[_unit,
		[
			"<t size=""1.2"" font=""RobotoCondensedBold"" color=""#FF9933"">" + "Join Group",
			{
				params ["_target", "_caller", "_actionId", "_arguments"];
				private _target = _this select 0;
				private _caller = _this select 1;
				private _actionId = _this select 2;
				[_target] joinSilent _caller;
				_target setCaptive false;
				_target enableAI 'MOVE';
				[_target, _actionid] remoteExec ["removeAction"];
				
				[_target,[
			"<t size=""1.2"" font=""RobotoCondensedBold"" color=""#FF9933"">" + "Disband",
			{
				params ["_target", "_caller", "_actionId", "_arguments"];		
				private _target = _this select 0;
				private _caller = _this select 1;
				private _actionId = _this select 2;
				_Group = createGroup civilian;
				[_target] joinSilent _Group;
				_target setCaptive false;
				_target removeAction _actionId;
				[_target] call GF_Join_Disband;
			},
			[],1.5,true,true,"","true",8,false,"", ""
		]] remoteExec ["addAction"];
			},[], 1.5,true,true,"","true",8,false,"",""
	]] remoteExec ["addAction"];
};
publicVariable "GF_Join_Disband";



[]spawn{
	while{true}do{
	
		_allUnits = allUnits select{(side _x) isEqualto GF_Join_Disband_Side};
		{
			if(
				((alive _x))
				&& (player!=_x)
				&& ((side _x) isEqualto GF_Join_Disband_Side)
				&& (!(_x getVariable ["Var_GF_Join_Disband",false]))
				)then{
					[_x]call GF_Join_Disband;
					[_x]call GF_Join_Disband_Killed;
					};	
					_x setVariable ["Var_GF_Join_Disband",true];
					{waitUntil {!alive _x};
					_x setVariable ["Var_GF_Join_Disband",false]; 
				};
		}forEach _allUnits;
		uisleep 5;
	};
};

 

npAu4A0.png

  • 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

×