Jump to content
Blitzen88

How to apply Custom AI Loadouts via Spawn AI Module Expression Field

Recommended Posts

Im trying to create a basic weapon swap script for units that are spawned via the AI Spawn Module.  I was hoping I could pull this off by executing a script via the module’s expression field. 

 

 

I tried searching and found some examples but I cant pull it off myself.  Can someone tell/show me how to call the script and apply it to the spawned group?

 

Thank you so much!!

Edited by Blitzen88
Grammer
  • Like 1

Share this post


Link to post
Share on other sites
wp =(_this select 0) addWaypoint [(getPos mrk1),0]; //with waypoint, make mrk1 PLAYER to follow player

spawnedGroup = _this select 0; { loadout = [_x, configfile >> "CfgVehicles" >> "I_G_soldier_F"] call BIS_fnc_loadinventory;
} 
forEach units spawnedGroup;

@Blitzen88

That'll do something. Change the class, add more classes for more soldiers.

or use something like this in a .sqf
 

    _marker = createMarker ["Enemy", enemyMARKER];
sleep 1;
    badguys = [getmarkerPOS "Enemy", east, ["I_C_Soldier_Bandit_8_F", "I_G_sharpshooter_F"]] call BIS_fnc_SpawnGroup; // notice they are east with IND outfits
    _wp1 = badguys addwaypoint [position _wpMARK ,0];
    _wp1 setwaypointtype "move";

 

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, wogz187 said:

wp =(_this select 0) addWaypoint [(getPos mrk1),0]; //with waypoint

spawnedGroup = _this select 0; { loadout = [_x, configfile >> "CfgVehicles" >> "I_G_soldier_F"] call BIS_fnc_loadinventory;
} 
forEach units spawnedGroup;

@Blitzen88

That'll do something. Change the class, add more classes for more soldiers.

I have more, gimme a sec.

Thats a great; I just need to know how to call it, etc. Im a moron

Share this post


Link to post
Share on other sites

@Blitzen88,
 

Quote

...Im a moron

No, morons can't find their way to the ArmA III forums. You're doing great!

  • Like 2

Share this post


Link to post
Share on other sites
10 hours ago, wogz187 said:

@Blitzen88,
 

No, morons can't find their way to the ArmA III forums. You're doing great!

 

How would you call a script from the expression field? What would you put there to exec a script for each group member and how would you define the group member in the script?

Share this post


Link to post
Share on other sites

What are you trying to accomplish? There's probably a better way.

Share this post


Link to post
Share on other sites
1 hour ago, wogz187 said:

What are you trying to accomplish? There's probably a better way.

Two things:

 

1) For whatever reason, units that are spawned by the AI Spawn Module are stripped of their weapon attachments (scopes and IR lasers). I want to have each unit exec a script that adds those attachments.

 

2) Sometimes I like to have CSAT use Ak12s. I want a script to remove their current weapon and add an Ak12. 

 

I have a general idea how to write/setup the script but I dont know how to call it/apply it. 

Share this post


Link to post
Share on other sites

1) For whatever reason, units that are spawned by the AI Spawn Module are stripped of their weapon attachments (scopes and IR lasers). I want to have each unit exec a script that adds those attachments.

 

2) Sometimes I like to have CSAT use Ak12s. I want a script to remove their current weapon and add an Ak12. 


We can do this but not with the AI module. The AI module can cause random errors (group full) anyway. Gimme a bit, brb.

Share this post


Link to post
Share on other sites

Set up a reference unit that has all the equipment you want. In it's INIT you can put,

this setpos (getpos objNULL); // to hide reference


and in the expression field of your AI module:

spawnedGroup = _this select 0; 
{ loadout = this setUnitLoadout (getUnitLoadout _refUNIT); } forEach units spawnedGroup; // replace refUNIT with your reference.

I'll test it whenever I get the editor opened but for now, untested.

Share this post


Link to post
Share on other sites
15 minutes ago, wogz187 said:

Set up a reference unit that has all the equipment you want. In it's INIT you can put,


this setpos (getpos objNULL); // to hide reference


and in the expression field of your AI module:


spawnedGroup = _this select 0; 
{ loadout = this setUnitLoadout (getUnitLoadout _refUNIT); } forEach units spawnedGroup; // replace refUNIT with your reference.

I'll test it whenever I get the editor opened but for now, untested.

From my understanding, thats going to cause issues:

 

1) The spawned units will copy that loadout and there will be no diversity for scopes. I wanted to define a list of scopes and then have a random selection of the available scopes. That way there is a certain degree of uniqueness in a unit’s loadout. 

 

2) For the Ak12’s, all units will copy the reference unit’s loadout. I do not want machinegunners to have Ak12’s; only riflemen and grenadiers

Share this post


Link to post
Share on other sites
31 minutes ago, Blitzen88 said:

From my understanding, thats going to cause issues:

 

1) The spawned units will copy that loadout and there will be no diversity for scopes. I wanted to define a list of scopes and then have a random selection of the available scopes. That way there is a certain degree of uniqueness in a unit’s loadout. 

 

2) For the Ak12’s, all units will copy the reference unit’s loadout. I do not want machinegunners to have Ak12’s; only riflemen and grenadiers

The above code is garbage. It's just an example to start working with. It does nothing but errors.
I'm working on this right now. The problem will be over-solved soon.

Share this post


Link to post
Share on other sites
3 minutes ago, wogz187 said:

The above code is garbage. It's just an example to start working with. It does nothing but errors.
I'm working on this right now. The problem will be over-solved soon.

Haha, I think I owe you a beer😆

Share this post


Link to post
Share on other sites

@Blitzen88,

This concept will get you started. You can make more than one reference to add some variety.
Create your reference dude, name him refUNIT.

Add to his init:

this setpos (getpos objNULL);


Put this in the mission init:

[refUNIT, [missionNameSpace, "xLOAD"]] call BIS_fnc_saveInventory;


In the Expression field of the AI Module:
 

spawnedGroup = _this select 0;
{
loadout=[_x, [missionNamespace, "xLOAD"]] call BIS_fnc_loadInventory;
}
forEach units spawnedGroup;

The saved loadout is CaSe SeNsItIvE. so "xload" will not work but "xLOAD" will.

So, for example, make three modules with three reference dudes and 3 potential loadouts. Give all the modules the same waypoint and, presto, you have custom dudes spawning and moving to location.

Here's some other ways to define "xLOAD": BIS_fnc_saveInventory

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, wogz187 said:


This concept will get you started.

 

How would I implement an approach like this:

 

_unit = ???

_possibleScopes = [
    "optic_Arco"
    ,"optic_Hamr"
    ,"optic_Holosight"
    ,"optic_Aco"
];

_randomScope = selectRandom [_possibleScopes];

_unit addPrimaryWeaponItem _RandomScope};

I know its probably full of errors but hopefully it gets my point/approach across...?

 

Thank you so much for your help by the way.  I appreciate it! Im also learning too!
 

Share this post


Link to post
Share on other sites
On 7/15/2019 at 4:07 PM, Blitzen88 said:

For whatever reason, units that are spawned by the AI Spawn Module are stripped of their weapon attachments

Shouldn't be, doesn't on mine. Vanilla units? any mods?

 

Spoiler


//Module Expression
_this execVM "spawnAIModule_Loadouts.sqf"


//spawnAIModule_Loadouts.sqf

params[ "_group" ];

{
	_x params[ "_unit" ];
	
	if ( side _group isEqualTo east ) then {
		
		_ak12_roles = [
			"Grenadier", 
			"Rifleman"
		] apply{ toLower _x };
		
		if ( toLower getText( configFile >> "CfgVehicles" >> typeOf _unit >> "role" ) in _ak12_roles ) then {
			_primary = primaryWeapon _unit;
			_compatibleMags = getArray( configFile >> "CfgWeapons" >> _primary >> "magazines" );
			{
				{
					_compatibleMags append getArray( _x );
				}forEach configProperties[ configFile >> "CfgMagazineWells" >> _x, "isArray _x", true ];
			}forEach getArray( configFile >> "CfgWeapons" >> _primary >> "magazineWell" );
			_compatibleMags = ( _compatibleMags arrayIntersect _compatibleMags ) apply{ toLower _x };
			
			_unit removeWeapon _primary;
			{
				if ( toLower _x in _compatibleMags ) then {
					_unit removeMagazines _x;
				};
			}forEach ( magazines _unit arrayIntersect magazines _unit );
			
			[ _unit, "arifle_AK12_GL_F", 7, "30Rnd_762x39_AK12_Mag_F" ] call BIS_fnc_addWeapon;
			_unit selectWeapon "arifle_AK12_GL_F";
		};		
		
	};
	
	_possibleScopes = [
	    "optic_Arco",
	    "optic_Hamr", 
	    "optic_Holosight", 
	    "optic_Aco"
	] apply { toLower _x };
	
	_compatibleScopes = getArray( configFile >> "CfgWeapons" >> primaryWeapon _unit >> "WeaponSlotsInfo" >> "CowsSlot" >> "compatibleItems" ) apply { toLower _x };
	
	_randomScope = selectRandom ( _possibleScopes arrayIntersect _compatibleScopes );

	_unit addPrimaryWeaponItem _randomScope;
		
}forEach units _group;

 

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Larrow said:

Shouldn't be, doesn't on mine. Vanilla units? any mods?

 

  Reveal hidden contents



//Module Expression
_this execVM "spawnAIModule_Loadouts.sqf"


//spawnAIModule_Loadouts.sqf

params[ "_group" ];

{
	_x params[ "_unit" ];
	
	if ( side _group isEqualTo east ) then {
		
		_ak12_roles = [
			"Grenadier", 
			"Rifleman"
		] apply{ toLower _x };
		
		if ( toLower getText( configFile >> "CfgVehicles" >> typeOf _unit >> "role" ) in _ak12_roles ) then {
			_primary = primaryWeapon _unit;
			_compatibleMags = getArray( configFile >> "CfgWeapons" >> _primary >> "magazines" );
			{
				{
					_compatibleMags append getArray( _x );
				}forEach configProperties[ configFile >> "CfgMagazineWells" >> _x, "isArray _x", true ];
			}forEach getArray( configFile >> "CfgWeapons" >> _primary >> "magazineWell" );
			_compatibleMags = ( _compatibleMags arrayIntersect _compatibleMags ) apply{ toLower _x };
			
			_unit removeWeapon _primary;
			{
				if ( toLower _x in _compatibleMags ) then {
					_unit removeMagazines _x;
				};
			}forEach ( magazines _unit arrayIntersect magazines _unit );
			
			[ _unit, "arifle_AK12_GL_F", 7, "30Rnd_762x39_AK12_Mag_F" ] call BIS_fnc_addWeapon;
			_unit selectWeapon "arifle_AK12_GL_F";
		};		
		
	};
	
	_possibleScopes = [
	    "optic_Arco",
	    "optic_Hamr", 
	    "optic_Holosight", 
	    "optic_Aco"
	] apply { toLower _x };
	
	_compatibleScopes = getArray( configFile >> "CfgWeapons" >> primaryWeapon _unit >> "WeaponSlotsInfo" >> "CowsSlot" >> "compatibleItems" ) apply { toLower _x };
	
	_randomScope = selectRandom ( _possibleScopes arrayIntersect _compatibleScopes );

	_unit addPrimaryWeaponItem _randomScope;
		
}forEach units _group;

 

 

Vanilla Units. Only thing I can think of that might mess it up would be the Advanced AI Command mod. However, that mod doesnt cause any issues with weapon attachments when units are spawned via script.

 

Edit

 

I forgot to add that I blacklisted alot of group types. Im not 100% sure but I think units used to spawn with attachments before the blacklist was applied. 

Share this post


Link to post
Share on other sites

When I put this in the expression of my spawn AI module it just says that it doesn`t expect scripts

Share this post


Link to post
Share on other sites

Hey thanks!

I was looking for this thread the other day and couldn't find it!

@Fredbefehl,

You may be trying to paste the code into the "Init" field instead of the "Expression" field.

Have fun!

  • 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

×