Jump to content
Sign in to follow this  
patpowercat

Group respawn with specific loadout

Recommended Posts

I've been working on adapting a script I found to respawn your AI squadmembers and then insert them with a helicopter to your position. I set them up with specific gear in the arsenal editor, but no matter what I seem to do I can't get them to respawn with that equipment. I tried setting a loadout in the unit's init field, which won't work (I think) because the script doesn't actually respawn that specific unit, it creates new ones of the same class. So I've been trying to edit the script, but can't get it. 

 

This is what I have so far: 

If (not isServer) exitWith {};

private ["_helo","_unit","_hPad","_heloWp"];

// CREATE THE HELO AND HPAD. SET THE HELO'S DIRECTION
_helo = [getMarkerPos "Mk1", markerDir "Mk1", "B_Heli_Transport_01_F", WEST] call bis_fnc_spawnVehicle;
_hPad = "Land_HelipadEmpty_F" createVehicle ( position player1 );

// CHECK THE GROUP AND REPLACE DEAD UNITS. MOVE THEM INTO THE HELO'S CARGO
{
    if ( ! ( alive ( _x select 0 ) ) ) then {
        _unit = (ALPHA) createUnit [ ( _x select 1 ), getMarkerPos "Mk1", [], 0, "NONE" ];
		_unit moveInCargo ( _helo select 0 ) };
    
}
{if (typeof _unit == "B_Recon_Sharpshooter_F") then {removeheadgear _unit};}

forEach grpArray;
// RESET THE ARRAY
grpArray = [];

{
	grpArray pushBack [ _x, ( typeOf _x ) ];
} forEach units ALPHA;

// GIVE THE HELO A WAYPOINT AT THE HPAD'S POSITION (PLAYER POS)

_heloWp = ( _helo select 2 ) addWaypoint [_hPad, 0];
_heloWp setWaypointType "MOVE";
_heloWp setWaypointBehaviour "CARELESS";
_heloWp setWaypointCombatMode "BLUE";
_heloWp setWaypointSpeed "FULL";
_heloWp setWaypointStatements ["true", "(vehicle this) LAND 'LAND';"];

// WAIT UNTIL THE HELO IS TOUCHING THE GROUND OR CAN'T MOVE (SHOT DOWN / WRECK) ANDD EJECT THE UNITS
waitUntil {isTouchingGround (_helo select 0) || { ! ( canMove ( _helo select 0 ) ) } };

{
	unAssignVehicle _x; 
	_x action ["eject", ( vehicle _x )]; 
	sleep 1;
} forEach units ALPHA; 

//WAITUNTIL THERE'S NO ALIVE GROUP MEMBERS IN THE HELO AND GIVE THE HELO A NEW WAYPOINT WHERE IT WILL BE DESTROYED
waitUntil { { !( alive _x ) || { !( _x in ( _helo select 0 ) ) } } count (units ALPHA) == count (units ALPHA)};
	
_heloWp = ( _helo select 2 ) addWaypoint [[0,0,0], 0];
_heloWp setWaypointType "MOVE";
_heloWp setWaypointBehaviour "AWARE";
_heloWp setWaypointCombatMode "RED";
_heloWp setWaypointSpeed "FULL";
_heloWp setWaypointStatements ["true", "{deleteVehicle _x;} forEach crew (vehicle this) + [vehicle this];"]; 

// DELETE THE EMPTY H-PAD
deleteVehicle _hPad;

{if (typeof _unit == "B_Recon_Sharpshooter_F") then {removeheadgear _unit};}

This is where I am trying to set the specific inventory for the unit, but having lots of trouble. Any help would be appreciated!

 

Share this post


Link to post
Share on other sites

You can use loadout script example working in multiplayer and on respawn also:

 

 

yourloadoutscript.sqf

waitUntil {!isNull player};       //to prevent MP / JIP issues

_unit = _this select 0;

removeAllWeapons _unit;
removeAllItems _unit;
removeAllAssignedItems _unit;
removeUniform _unit;
removeVest _unit;
removeBackpack _unit;
removeHeadgear _unit;
removeGoggles _unit;
_unit forceAddUniform "";
_unit addItemToUniform "";
_unit addVest "";
_unit addItemToVest "";
_unit addBackpack "";
_unit addItemToBackpack "";
_unit addHeadgear "";
_unit addGoggles "";
_unit addWeapon "";
_unit addPrimaryWeaponItem "";
_unit addWeapon "";
_unit addHandgunItem "";
_unit linkItem "";

if(true) exitWith{};

and then on unit in the init field use this :

 

null = [this] execVM "yourloadoutscript.sqf";   this addeventhandler ["respawn","_this execVM 'yourloadoutscript.sqf'"];

Share this post


Link to post
Share on other sites

I have tried a respawn event handler and such. The problem is the script doesn't actually "respawn" the specific unit, it takes a TYPE of that unit. So I either need to figure out how to change a unit load out via the script AFTER spawning, or figure out how to change the script so the unit respawns. 

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  

×