Jump to content
DOA

How to Spawn AI Group with custom loadouts?

Recommended Posts

My goal is to use CUP TK Militia units to spawn custom groups with custom loadouts, Waypoints, respawn and set language to vanilla Farsi. I know, I don't ask for too much do I?
Thanks in advance for your time and help.

I have cobbled together some scripts into a single sqf that spawn the group, assigns them waypoints and has the group respawn. The sqf pasted below is what I am currently using.
I want to keep using the CUP Takistan Militia to try and keep down the number of addons required for my missions. The show stopping issue is that when the groups condition changes, as happens when they make contact with their enemy or start taking fire, there is a language bug that throws and error. I reported this to CUP and the suggested quick work around is to change the units language to vanilla Farsi. I also want the riflemen in this group to carry AK74s with Green Tracer mags and perhaps a few other custom items, as needed, in their loadouts. They should respawn with this same loadout.

 

The sqf below works fine. Group is spawned, follows waypoints, and respawns. This big issue is changing the language and loadouts.
I believe I can export a custom loadout from arsenal for each man and implement it in the spawned group for each man. I have tried several articles and posts but can't get it to work.


 I think what I am asking for is how to spawn an AI group with custom loadout and language set to Farsi_01 and then incorporate this into my existing SQF.

Note: The CUP TK MIlitia have this language Issue when the groups condition changes. This is this issue along with custom loadouts I am asking for help on. As a work around I tried using the SFF-R Taliban and they spawn fine and follow waypoints, respawn all as expected. The issue I have with them is that most of them carry rifles with flashlights on them and when you engage them at long range in the dark they all light up their flashlights, sort of like they are trying to give away their positions. I would also need to spawn them with custom loadouts so I am falling back on the CUP TK Militia which would also allow me to remove the SSF addons in an effort to keep the number of addons required to a minimum.

 

Here is my existing sqf if this helps. Thanks again.

 

// AISpawnManager_group1. 10 men

//Spawn AI Group using BIS_SpawnGroup function.

//Spawn _group1
_group1 = [getMarkerPos "_group1_spawn", EAST, ["CUP_O_TK_INS_Commander","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier_AR","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Bomber","CUP_O_TK_INS_Soldier_TL","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Soldier_AT","CUP_O_TK_INS_Guerilla_Medic"]] call BIS_fnc_spawnGroup;

//Assign _group1 WayPoints
_wp1_grp1 = _group1 addWaypoint [getmarkerpos "wp1_grp1", 0];
_wp1_grp1 setWaypointType "MOVE";
_wp1_grp1 setWaypointSpeed "NORMAL";
_wp1_grp1 setWaypointBehaviour "SAFE";
_wp1_grp1 setWaypointFormation "WEDGE";
[_group1, 1] setWaypointTimeout [10, 15, 20];

_wp2_grp1 = _group1 addWaypoint [getmarkerpos "wp2_grp1", 0];
_wp2_grp1 setWaypointType "MOVE";
_wp2_grp1 setWaypointSpeed "NORMAL";
_wp2_grp1 setWaypointBehaviour "SAFE";
_wp2_grp1 setWaypointFormation "WEDGE";
[_group1, 2] setWaypointTimeout [10, 15, 20];

_wp3_grp1 = _group1 addWaypoint [getmarkerpos "wp3_grp1", 0];
_wp3_grp1 setWaypointType "MOVE";
_wp3_grp1 setWaypointSpeed "NORMAL";
_wp3_grp1 setWaypointBehaviour "SAFE";
_wp3_grp1 setWaypointFormation "WEDGE";
[_group1, 3] setWaypointTimeout [10, 15, 20];

_wp4_grp1 = _group1 addWaypoint [getmarkerpos "wp4_grp1", 0];
_wp4_grp1 setWaypointType "MOVE";
_wp4_grp1 setWaypointSpeed "NORMAL";
_wp4_grp1 setWaypointBehaviour "SAFE";
_wp4_grp1 setWaypointFormation "WEDGE";
[_group1, 4] setWaypointTimeout [10, 15, 20];

_wp5_grp1 = _group1 addWaypoint [getmarkerpos "wp5_grp1", 0];
_wp5_grp1 setWaypointType "CYCLE";
_wp5_grp1 setWaypointSpeed "NORMAL";
_wp5_grp1 setWaypointBehaviour "SAFE";
_wp5_grp1 setWaypointFormation "WEDGE";
[_group1, 5] setWaypointTimeout [10, 15, 20];

// Respawn _group1
_group1 spawn {
  _group1 = _this;
  private "_unit";
  while {count units _group1 > 0} do {
        for "_i" from 0 to count (units _group1) - 1 do {
          _unit = units _group1 select _i;
          if !(_unit getVariable ["_ready",false]) then {
            _unit setVariable ["_type",typeOf _unit];
            _unit setVariable ["_dir",getdir _unit]; // not used here
            _unit setVariable ["_side",side _unit];
            _unit setVariable ["_group",_group1];
            _unit addEventHandler ["killed", {
              _fellow = _this select 0;
              _newbie =  (_fellow getVariable "_type") createUnit [getMarkerPos "_group1_spawn", _fellow getVariable "_group"];
              _newbie setVariable ["_ready", false];
              _fellow setVariable ["_ready", nil];
              //deleteVehicle _fellow;
           }];
           _unit setVariable ["_ready", true];
         };
       };
       sleep 1;
    };
  };

 

 

Share this post


Link to post
Share on other sites

I'm trying a different approach and meeting with some success.
I can now spawn the group I want, with the custom load out I want (AK74 and Green Tracers) they follow the waypoints and respawn as expected. Now my last hurtle is to set their language to "vanilla Farsi" as suggested by CUP to work around the language error that occurs the first time the group comes under fire or changed their condition like from SAFE to COMBAT. This is a link to this language issue at CUP - https://dev.cup-arma3.org/T2481 This question is listed as about custom load out. This was a multi-part request so perhaps no one will notice the voices or language issue. I think I should make it a separate request?

 

This is the sqf I am currently using to spawn the AI group with ak74, green tracers, waypoints and respawn.


// Run this on the server.
if (!isServer) exitWith {};

// Create Group.
_group1 = createGroup EAST;

//Custom Units for _group1.
of01 = _group1 createUnit ["CUP_O_TK_INS_Soldier_TL", getmarkerpos "_group1_spawn", [], 1, "FORM"];
of02 = _group1 createUnit ["CUP_O_TK_INS_Soldier", getmarkerpos "_group1_spawn", [], 1, "FORM"];

//Loadouts
removeAllWeapons of01;
removeAllItems of01;
removeAllAssignedItems of01;
of01 addMagazines ["CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M",3];
of01 addWeapon "CUP_arifle_AK74";
removeAllWeapons of02;
removeAllItems of02;
removeAllAssignedItems of02;
of02 addMagazines ["CUP_30Rnd_TE1_Green_Tracer_545x39_AK_M",3];
of02 addWeapon "CUP_arifle_AK74";

//Set Language.
of01 setSpeaker "Male01PER";
of01 setSpeaker "Male02PER";

//Assign _group1 WayPoints
_wp1_grp1 = _group1 addWaypoint [getmarkerpos "wp1_grp1", 0];
_wp1_grp1 setWaypointType "MOVE";
_wp1_grp1 setWaypointSpeed "NORMAL";
_wp1_grp1 setWaypointBehaviour "SAFE";
_wp1_grp1 setWaypointFormation "WEDGE";
[_group1, 1] setWaypointTimeout [10, 15, 20];

_wp2_grp1 = _group1 addWaypoint [getmarkerpos "wp2_grp1", 0];
_wp2_grp1 setWaypointType "MOVE";
_wp2_grp1 setWaypointSpeed "NORMAL";
_wp2_grp1 setWaypointBehaviour "SAFE";
_wp2_grp1 setWaypointFormation "WEDGE";
[_group1, 2] setWaypointTimeout [10, 15, 20];

_wp3_grp1 = _group1 addWaypoint [getmarkerpos "wp3_grp1", 0];
_wp3_grp1 setWaypointType "MOVE";
_wp3_grp1 setWaypointSpeed "NORMAL";
_wp3_grp1 setWaypointBehaviour "SAFE";
_wp3_grp1 setWaypointFormation "WEDGE";
[_group1, 3] setWaypointTimeout [10, 15, 20];

_wp4_grp1 = _group1 addWaypoint [getmarkerpos "wp4_grp1", 0];
_wp4_grp1 setWaypointType "MOVE";
_wp4_grp1 setWaypointSpeed "NORMAL";
_wp4_grp1 setWaypointBehaviour "SAFE";
_wp4_grp1 setWaypointFormation "WEDGE";
[_group1, 4] setWaypointTimeout [10, 15, 20];

_wp5_grp1 = _group1 addWaypoint [getmarkerpos "wp5_grp1", 0];
_wp5_grp1 setWaypointType "CYCLE";
_wp5_grp1 setWaypointSpeed "NORMAL";
_wp5_grp1 setWaypointBehaviour "SAFE";
_wp5_grp1 setWaypointFormation "WEDGE";
[_group1, 5] setWaypointTimeout [10, 15, 20];

// Respawn _group1
_group1 spawn {
  _group1 = _this;
  private "_unit";
  while {count units _group1 > 0} do {
        for "_i" from 0 to count (units _group1) - 1 do {
          _unit = units _group1 select _i;
          if !(_unit getVariable ["_ready",false]) then {
            _unit setVariable ["_type",typeOf _unit];
            _unit setVariable ["_dir",getdir _unit]; // not used here
            _unit setVariable ["_side",side _unit];
            _unit setVariable ["_group",_group1];
            _unit addEventHandler ["killed", {
              _fellow = _this select 0;
              _newbie =  (_fellow getVariable "_type") createUnit [getMarkerPos "_group1_spawn", _fellow getVariable "_group"];
              _newbie setVariable ["_ready", false];
              _fellow setVariable ["_ready", nil];
              //deleteVehicle _fellow;
           }];
           _unit setVariable ["_ready", true];
         };
       };
       sleep 1;
    };
  };

Share this post


Link to post
Share on other sites

Here is my approach. Use command apply. In loop use `_x` as unit. Then apply your gear. I added little bit of randomization there. I don't write whole script, but you got the idea how to do it now ...

_classes = ["CUP_O_TK_INS_Commander","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier_AR","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Bomber","CUP_O_TK_INS_Soldier_TL","CUP_O_TK_INS_Mechanic","CUP_O_TK_INS_Soldier","CUP_O_TK_INS_Soldier_AT","CUP_O_TK_INS_Guerilla_Medic"];

_group = [getMarkerPos "markerName", EAST, _classes] call BIS_fnc_spawnGroup;
(units _group) apply 
{
	// _gear = [_x] execVM "yourGearScript.sqf";
	
	removeUniform _x;
	removeVest _x;
	removeBackpack _x;

	_x forceAddUniform selectRandom ["uniform_class_1", "uniform_class_2"];
	_x addVest selectRandom ["vest_class_1", "vest_class_2"];
	_x addBackpack selectRandom ["backpack_class_1", "backpack_class_2"];
};

Share this post


Link to post
Share on other sites

An alternative to handle loadouts would be to use getUnitloadout/setUnitloadout.

Less clutter and allows it to set up a "gear loadout" mission, where you can tweak the loadout of multiple units and simply add it to an array using copytoclipboard command.

 

Good thing is, getUnitLoadout accepts objects, configs and classnames, pretty neat.

 

Cheers

 

 

 

Share this post


Link to post
Share on other sites

Thanks men for your time and help. It is much appreciated. Now I just have to figure out how to change voices to fix the language bug with the CUP TK Militia and I will have my AISpawnManager system working the way I need it to. This is a link to this language issue at CUP - https://dev.cup-arma3.org/T2481 

Thanks again for your help.  I'll give credit in my missions  for any of these scripts I use.

 


 

Share this post


Link to post
Share on other sites
13 hours ago, DOA said:

Thanks men for your time and help. It is much appreciated. Now I just have to figure out how to change voices to fix the language bug with the CUP TK Militia and I will have my AISpawnManager system working the way I need it to. This is a link to this language issue at CUP - https://dev.cup-arma3.org/T2481 

Thanks again for your help.  I'll give credit in my missions  for any of these scripts I use.

 


 

 

Well that's an easy one:

_farsi = ["Male01PER","Male02PER","Male03PER"];
_rndSpeaker = selectRandom _farsi;
[_unit,_rndSpeaker] remoteExec ["setSpeaker",0];//so it's the same speaker for every client

Cheers

  • Like 3

Share this post


Link to post
Share on other sites

Grumpy Old Man rules. I'm making missions again and came up with a question about being able to spawn custom groups with custom loadouts using the spawn ai module. I saw a thread that looked like it might help and it turned out to be a thread I started back in 2018. ROTFLOL Thanks again GOM. (BTW: Your name accurately describes me. ) Thanks again. 

Share this post


Link to post
Share on other sites
On 4/17/2018 at 3:22 PM, DOA said:

My goal is to use CUP TK Militia units to spawn custom groups with custom loadouts, Waypoints, respawn and set language to vanilla Farsi. I know, I don't ask for too much do I?
Thanks in advance for your time and help.

 

 

 

There is the CSWR script that makes all you need:

 

  • Spawn CUP TK Militia or any other vanilla or custom faction, including ground vehicles and helicopters;
  • You can custom basically everything for each side;
  • Set 4 times waypoints: move, hold, watch, and occupy;
  • about the language: it's the scope of the new version that is coming out soon.
     

 

  • Like 1

Share this post


Link to post
Share on other sites
On 11/27/2023 at 7:37 PM, David ArmAstrong said:

Grumpy Old Man rules. I'm making missions again and came up with a question about being able to spawn custom groups with custom loadouts using the spawn ai module. I saw a thread that looked like it might help and it turned out to be a thread I started back in 2018. ROTFLOL Thanks again GOM. (BTW: Your name accurately describes me. ) Thanks again. 

.

You don't need to spawn anything.

 

Create the unit with the details that you see fit. Place the unit in an out of the way place on the map.  Create a trigger and when the trigger fires, transport the unit to the correct location. 

.

.

 

  • 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

×