Jump to content
Sign in to follow this  
USMCWall

Predefining a spawned soldiers loadout

Recommended Posts

I know there is a way to do this that exists, but I can't wrap my head around it. What I' m aiming to do is have a script that is a predefined loadout for certain classes of units (IE, medic, AR, AT, etc.) that once the game has detected they are on the map (like with many of the recruitment scripts out there) it will change the unit from their default loadout to the predefined one. I attempted using a trigger the size of the map set to repeatedly when the faction was present but could not get it to removeallweapons and just add a different weapon as a starting point. If anyone has some insight or direction I could approach this that would be great, thanks.

Share this post


Link to post
Share on other sites

Not tested, run on server. Only works for units already placed down.


if (!isServer) exitWith {};

private["_iUnit","_loadout"];

Loadout_Array =
[
["Rifleman",["M4A1"],["30RND_556x45_STANAG"]],
["Medic",["M16A2"],["30RND_556x45_STANAG"]]
];

FNC_GetLoadout =
{
private["_unit","_type","_weps","_mags","_ret"];
_unit = _this select 0;
_type = typeOf _unit;
_weps = [];
_mags = [];
for "_i" from 0 to (count Loadout_Array) do
{
	if (_type == ((Loadout_Array select _i) select 0)) then
	{
		_weps = ((Loadout_Array select _i) select 1);
		_mags = ((Loadout_Array select _i) select 2);
	};
};
_ret = [_weps,_mags];
_ret
};

for "_i" from 0 to (count allUnits) do
{
_iUnit = allUnits select _i;
_loadout = [_iUnit] call FNC_GetLoadout;
       removeAllWeapons _iUnit;
{
	_iUnit addWeapon _x;
} forEach (_loadout select 0);
{
	_iUnit addMagazine _x;
} forEach (_loadout select 1);
};

Obviously you can add more loadouts and I don't even know if those classnames exist.

Share this post


Link to post
Share on other sites

Thanks for the reply, but if it only works for units already placed I don't think that is going to be a solution. Basically if a unit is recruited in MSO, when it is spawned into the game world I want it to spawn with a custom loadout rather than the loadout scripted into the unit itself.

Share this post


Link to post
Share on other sites

Maybe run the script again once new units are created? Else I'm not sure

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  

×