Jump to content
anfo

Spawn customised loadout AI

Recommended Posts

Hello

 

Unless I'm mistaken, most AI spawn scripts only allow for particular pre-defined AI classname to spawn, instead of say an AI individual or group which is customised with different varieties of clothing, weapons, accessories and even init code.

 

Say I call this group of four customised enemy AI "group_1". Is there a script that anybody has come across that could spawn "group_1" at "marker_x" when a trigger is fired?

 

Anfo

Share this post


Link to post
Share on other sites

You can absolutely customize anything about a group as you spawn it, all depends on how complicated and bloaty of a script you want to write.   :)

 

If you're placing a squad down on the map way outside of the AO and want to teleport them to marker when a trigger is activated you can do that too.  In the trigger onAct field something along the lines of: (you'll probably want to have the trigger set to Server Only)

{ _x setPos getMarkerPos "marker_x"} forEach units group_1;

That uses the units command to get a list of units within group_1.  Then it uses forEach command to step through that list, one unit at a time, running the command in the code block { } to the left on each unit.  Each unit is represented by the special variable _x.  So we set the position using setPos of each unit to the marker position of "marker_x".  Basically teleporting them all to the marker as a small jumbled mass of units.  They'll quickly reorganize into formation though.

  • Like 1

Share this post


Link to post
Share on other sites

_leader_1 = leader group_1;

_leader_1_pos = getPos _leader_1;

_marker_x_pos = getMarkerPos "marker_x";

{

if(_x != _leader_1) then

{

_rel_pos = _leader_1_pos vectorDiff (getPos _x);

_x setPos (_marker_x_pos vectorAdd _rel_pos);

};

} forEach units group_1;

_leader_1 setPos marker_x_pos;

This code should preserve the position of each unit in formation while teleporting them all

Edited by sarogahtyp
  • Like 2

Share this post


Link to post
Share on other sites

preserve the position of each unit in formation while teleporting

 

Why do you hate freedom?  The freedom of units to get to know, in the most intimate way, the bounding boxes of their fellow units during teleportation?  Who are you to take that away from them?  You monster!

  • Like 1
  • Haha 2

Share this post


Link to post
Share on other sites

Hello

 

Unless I'm mistaken, most AI spawn scripts only allow for particular pre-defined AI classname to spawn, instead of say an AI individual or group which is customised with different varieties of clothing, weapons, accessories and even init code.

 

Say I call this group of four customised enemy AI "group_1". Is there a script that anybody has come across that could spawn "group_1" at "marker_x" when a trigger is fired?

 

Anfo

 

Have a look at my script JEBUS. It may suit your needs.....

Share this post


Link to post
Share on other sites

Hello

 

Unless I'm mistaken, most AI spawn scripts only allow for particular pre-defined AI classname to spawn, instead of say an AI individual or group which is customised with different varieties of clothing, weapons, accessories and even init code.

 

Say I call this group of four customised enemy AI "group_1". Is there a script that anybody has come across that could spawn "group_1" at "marker_x" when a trigger is fired?

 

Anfo

Heres my script I use for a mercenary shop which will let you buy an AI teamate and add to your group, I suggest using the new built in group menu with this. You can change its gear by switching out the class names.

createMarker ["DebugSpawn",[7,7]];
"DebugSpawn" setMarkerType "Empty";
"DebugSpawn" setMarkerSize [2, 2];
_uniform = "U_I_C_Soldier_Bandit_1_F";
_vest = "V_BandollierB_ghex_F";
_headgear = "H_Shemag_olive";
_rifleMag = "30Rnd_762x39_Mag_F";
_rifle = "arifle_AKM_F";
_pistolMag = "30Rnd_9x21_Mag";
_pistol = "hgun_P07_khk_F";

switch (playerSide) do {
    case west: {
    "B_T_Soldier_F" createUnit [ getMarkerPos "DebugSpawn", group player, "myMan = this;" ];
	myMan setPos [2904.671,12635.176,1.051];
	{myMan removeWeapon _x} forEach weapons myMan;
	{myMan removeMagazine _x} forEach magazines myMan;
	removeAllAssignedItems myMan;
	removeVest myMan;
	removeUniform myMan;
	removeHeadgear myMan;
	//Add new weapons
	myMan forceAddUniform _uniform;
	myMan addVest _vest;
	myMan addHeadgear _headgear;
	myMan addMagazine _rifleMag;
	myMan addWeapon _rifle;
	myMan addMagazines [_rifleMag, 3];
	myMan addMagazine _pistolMag;
	myMan addWeapon _pistol;
	myMan addMagazines [_pistolMag, 2];
	[myMan] call neb_fnc_addBounty;
	deleteMarker "DebugSpawn";
    };
    case east: {
		"O_T_Soldier_F" createUnit [ getMarkerPos "DebugSpawn", group player, "myMan = this;" ];
		myMan setPos [2904.671,12635.176,1.051];
		{myMan removeWeapon _x} forEach weapons myMan;
		{myMan removeMagazine _x} forEach magazines myMan;
		removeAllAssignedItems myMan;
		removeVest myMan;
		removeUniform myMan;
		removeHeadgear myMan;
		//Add new weapons
		myMan forceAddUniform _uniform;
		myMan addVest _vest;
		myMan addHeadgear _headgear;
		myMan addMagazine _rifleMag;
		myMan addWeapon _rifle;
		myMan addMagazines [_rifleMag, 3];
		myMan addMagazine _pistolMag;
		myMan addWeapon _pistol;
		myMan addMagazines [_pistolMag, 2];
		[myMan] call neb_fnc_addBounty;
		deleteMarker "DebugSpawn";
    };
};

EDIT: added local variables to be able to repeat switch for more sides easier as well as copying multiple time for multiple units. If you want to change their group use something other than player group in the array. Use a 3d object in the editor to figure out the setPos coordinates [x,y,z]

  • Like 1

Share this post


Link to post
Share on other sites

Another way to do it:

 

Create your soldier with his customized load out and place him in an out of the way place over on the edge of the map.

 

Then create a trigger which causes him to transport to the required location.

.

.

Share this post


Link to post
Share on other sites

I wrote a function that does this.

 

see this thread:

https://forums.bistudio.com/topic/192453-help-me-optimize-my-script-please/

 

 

To spawn the unit on a marker, create a group and a marker.  pass the group and the marker position to the function, along with the loadout name you want, any skill bonuses, and the loadout bonuses.  An example of how I set up the loadout is there too.

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

×