Jump to content

[CUSTOM] Revised AT (RPG), with AA Addition


Recommended Posts

At the moment, the last unit of each group spawned gets given an RPG if the DZMSUseRPG variable is set to true. So if four groups get spawned at a mission, there will be 4 RPG's.

 

I've made a bunch of changes which essentially allows you to specify which groups get AT(RPG), and also AA, on top of this I've also made the AA and AT weapons/magazines configurable in the config.

 

DZMSConfig.sqf - replace "DZMSUseRPG = true;" with:

// AT, Weapon/Magazine
DZMSUseAT = true;
DZMS_AT_Weapon = "RPG7V";
DZMS_AT_Magazine = "PG7V";

// AA, Weapon/Magazine
DZMSUseAA = true;
DZMS_AA_Weapon = "Strela";
DZMS_AA_Magazine = "Strela";

ExtConfig/DZMSAIConfig.sqf - add the following two arrays (you can adjust the AI settings, especially the AA settings for spotDistance and spotTime - to stop them shooting choppers out of the sky from 2KM away - e.g. lower it until you are happy):

DZMSSkillsAA = [
["aimingAccuracy",0.50],
["aimingShake",0.60],
["aimingSpeed",0.50],
["endurance",1.00],
["spotDistance",0.50],
["spotTime",0.50],
["courage",1.00],
["reloadSpeed",1.00],
["commanding",1.00],
["general",1.00]
];

DZMSSkillsAT = [
["aimingAccuracy",0.80],
["aimingShake",0.8],
["aimingSpeed",0.60],
["endurance",1.00],
["spotDistance",0.70],
["spotTime",0.70],
["courage",1.00],
["reloadSpeed",1.00],
["commanding",1.00],
["general",1.00]
];

DZMSAISpawn.sqf - most of the changes are in this file, here's my complete version:

private [
	"_position", "_unitcount", "_skill", "_wpRadius", "_xpos",
	"_ypos", "_unitGroup", "_aiskin", "_unit", "_weapon",
	"_magazine", "_wppos1",	"_wppos2", "_wppos3", "_wppos4",
	"_wp1",	"_wp2",	"_wp3",	"_wp4",	"_wpfin", "_unitArrayName",
	"_unitMissionCount", "_giveAT",	"_giveAA", "_configured"
];

_position = _this select 0;
_unitcount = _this select 1;
_skill = _this select 2;
_unitArrayName = _this select 3;
_giveAT = if (count _this > 4) then {_this select 4} else {false};
_giveAA = if (count _this > 5) then {_this select 5} else {false};

//diag_log text format ["[DZMS]: AI Pos:%1 / AI UnitNum: %2 / AI SkillLev:%3",_position,_unitcount,_skill];

_wpRadius = 20;

_xpos = _position select 0;
_ypos = _position select 1;

//Create the unit group. We use east by default.
_unitGroup = createGroup east;

//Probably unnecessary, but prevents client AI stacking
if (!isServer) exitWith {};

for "_x" from 1 to _unitcount do {

	//Lets pick a skin from the array
	_aiskin = DZMSBanditSkins call BIS_fnc_selectRandom;

	//Lets spawn the unit
	_unit = _unitGroup createUnit [_aiskin, [(_position select 0),(_position select 1),(_position select 2)], [], 10, "PRIVATE"];
	
	//Make him join the correct team
	[_unit] joinSilent _unitGroup;
	
	//Add the behaviour
	_unit enableAI "TARGET";
	_unit enableAI "AUTOTARGET";
	_unit enableAI "MOVE";
	_unit enableAI "ANIM";
	_unit enableAI "FSM";
	_unit setCombatMode "YELLOW";
	_unit setBehaviour "COMBAT";
	
	//Remove the items he spawns with by default
	removeAllWeapons _unit;
	removeAllItems _unit;
	_configured = false;
	

	// Give AA if applicable
	if (DZMSUseAA && _giveAA && _x == 1) then {
		_unit addMagazine DZMS_AA_Magazine;
		_unit addMagazine DZMS_AA_Magazine;

		_unit addWeapon DZMS_AA_Weapon;
		_unit selectWeapon DZMS_AA_Weapon;

		_aicskill = DZMSSkillsAA;
		_configured = true;
	};

    // Give AT if applicable
	if (DZMSUseAT && _giveAT && _x == _unitcount) then {
		_unit addMagazine DZMS_AT_Magazine;
		_unit addMagazine DZMS_AT_Magazine;

		_unit addWeapon DZMS_AT_Weapon;
		_unit selectWeapon DZMS_AT_Weapon;

		_aicskill = DZMSSkillsAT;
		_configured = true;
	};

	//Now we need to figure out their loadout, if not already equiped
	if(!_configured) then {
		//Get the weapon array based on skill
		_weaponArray = [_skill] call DZMSGetWeapon;
		
		_weapon = _weaponArray select 0;
		_magazine = _weaponArray select 1;
		
		//diag_log text format ["[DZMS]: AI Weapon:%1 / AI Magazine:%2",_weapon,_magazine];
		
		//Get the gear array
		_aigearArray = [DZMSGear0,DZMSGear1,DZMSGear2,DZMSGear3,DZMSGear4];
		_aigear = _aigearArray call BIS_fnc_selectRandom;
		_gearmagazines = _aigear select 0;
		_geartools = _aigear select 1;
		
		//Gear the AI backpack
		_aipack = DZMSPacklist call BIS_fnc_selectRandom;

		//Lets add it to the Unit
		for "_i" from 1 to 3 do {
			_unit addMagazine _magazine;
		};
		_unit addWeapon _weapon;
		_unit selectWeapon _weapon;
		
		_unit addBackpack _aipack;
		
		if (DZMSUseNVG) then {
			_unit addWeapon "NVGoggles";
		};
		
		{
			_unit addMagazine _x
		} forEach _gearmagazines;
		
		{
			_unit addWeapon _x
		} forEach _geartools;

		//Lets set the skills
		switch (_skill) do {
			case 0: {_aicskill = DZMSSkills1;};
			case 1: {_aicskill = DZMSSkills2;};
			case 2: {_aicskill = DZMSSkills3;};
		};
    };
	
	{
		_unit setSkill [(_x select 0),(_x select 1)]
	} forEach _aicskill;

	
	//Lets prepare the unit for cleanup
	_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSAIKilled; }];
	_unit setVariable ["DZMSAI", true];
};

// These are 4 waypoints in a NorthSEW around the center
_wppos1 = [_xpos, _ypos+20, 0];
_wppos2 = [_xpos+20, _ypos, 0];
_wppos3 = [_xpos, _ypos-20, 0];
_wppos4 = [_xpos-20, _ypos, 0];

// We add the 4 waypoints
_wp1 = _unitGroup addWaypoint [_wppos1, _wpRadius];
_wp1 setWaypointType "MOVE";
_wp2 = _unitGroup addWaypoint [_wppos2, _wpRadius];
_wp2 setWaypointType "MOVE";
_wp3 = _unitGroup addWaypoint [_wppos3, _wpRadius];
_wp3 setWaypointType "MOVE";
_wp4 = _unitGroup addWaypoint [_wppos4, _wpRadius];
_wp4 setWaypointType "MOVE";

// Then we add a center waypoint that tells them to visit the rest
_wpfin = _unitGroup addWaypoint [[_xpos,_ypos, 0], _wpRadius];
_wpfin setWaypointType "CYCLE";

//diag_log text format ["[DZMS]: Spawned %1 AI at %2",_unitcount,_position];

// load the unit groups into a passed array name so they can be cleaned up later
call compile format["
%1 = %1 + (units _unitGroup); 
_unitMissionCount = count %1;
",_unitArrayName];
diag_log text format["[DZMS]: (%3) %1 AI Spawned, %2 units in mission.",count (units _unitGroup),_unitMissionCount,_unitArrayName];

DZMSAIKilled.sqf - find the block of code which checks and removes the RPG from the unit (at bottom of file, ~line 60) and replace with:

if (DZMSUseAA AND (DZMS_AA_Weapon in (weapons _unit))) then {
	_unit removeWeapon DZMS_AA_Weapon;
	_unit removeMagazines DZMS_AA_Magazine;
};

if (DZMSUseAT AND (DZMS_AT_Weapon in (weapons _unit))) then {
	_unit removeWeapon DZMS_AT_Weapon;
	_unit removeMagazines DZMS_AT_Magazine;
};

Now, inside your Major/Minor mission files, you can specify which AI groups have a AA, AT or BOTH when calling the DZMSAISpawn function. 

 

Basic usage is:

[<position>,<amount of units>,<skill>,<unit type>,<at>,<aa>] call DZMSAISpawn;

The newly added 5th, and 6th parameters for controlling AT/AA are optional, and default to false!

 

 

For example (coordinates and sleep commands remove for brevity), my major missions look like this (1 AA, 1 AT unit):

[[0,0,0],5,1,"DZMSUnitsMajor", true, true] call DZMSAISpawn;
[[0,0,0],3,1,"DZMSUnitsMajor"] call DZMSAISpawn;
[[0,0,0],3,1,"DZMSUnitsMajor"] call DZMSAISpawn;
[[0,0,0],3,1,"DZMSUnitsMajor"] call DZMSAISpawn;

And an example from my minor mission (1 AT unit, no AA - note the 5th and 6th parameters are option):

[[0,0,0],3,0,"DZMSUnitsMinor", true] call DZMSAISpawn;
[[0,0,0],3,0,"DZMSUnitsMinor"] call DZMSAISpawn;
[[0,0,0],2,0,"DZMSUnitsMinor"] call DZMSAISpawn;
[[0,0,0],2,0,"DZMSUnitsMinor"] call DZMSAISpawn;

If you only wanted AA, you could do something like this:

[[0,0,0],2,0,"DZMSUnitsMinor", false, true] call DZMSAISpawn;

If you want to change the AT or AA weapon used by the AI, you can do this by changing the variables in DZMSConfig.sqf, for example if you want the AA units to use a Stinger instead of a Strela:

DZMS_AA_Weapon = "Stinger";
DZMS_AA_Magazine = "Stinger";

Here are the possible AA weapons, their ammunition class names are the same as the weapon names:

Igla
Strela
Stinger

To change the AT weapon/ammunition, obviously set the corrosponding DZMS_AT_Weapon/Magazine variables, here's an example for a SMAW instead of an RPG:

DZMS_AT_Weapon = "SMAW";
DZMS_AT_Magazine = "SMAW_HEAA";

Here are the possible AT weapons, their ammunition class names following in brackets:

SMAW (SMAW_HEAA, SMAW_HEDP)
Javelin (Javelin)
M136 (M136)
MetisLauncher (AT13)
RPG18 (RPG18)
RPG7V (PG7V, PG7VL, PG7VR, OG7)

A few things to note:

 

  • If adding AT and AA to a group of units, there must be a minimum of two units in the group (AT gets added to first, AA gets added to last)
  • AT and AA units do not get any other equipment apart from the launcher and related rounds (AT gets 3 rounds, AA gets 2 rounds)
  • AT and AA weapons get striped from the units upon death
  • Adjust the DZMSSkillsAT and DZMSSkillsAA arrays if the AI are shooting you from too far away or targetting too quickly
  • You can disable AT or AA globally without editing missions simply by setting DZMSUseAA/DZMSUseAT to false in the config
Link to comment
Share on other sites

  • 1 month later...

Hi Shizweak,

 

First, thx for Ur code.

It works perfectly.

 

We have a strange bug with AA or AT AI.

Some time, during mission, an AA/AT AI was killed by another AI.

So, that AA/AT AI (that was killedgets up and run without stopping and he's in god mod.

 

On the other side, If the AA/AT AI was killed by a player we have no problem.

 

Have U already note this bug ?

Have U any suggestion to resolve this problem ?

 

Regards

Link to comment
Share on other sites

very nice, I did the same with my NPCs gave them couple different launchers determined by chance and unitcount
every AI group with 3 or less will have 3 or less AI with launchers, the launchers itself are chance based. works nice.

there nothing like a autorotation landing after you flew past a mission with one AI with a strela or stinger on him... keeps the adrenalin pumping :D

Link to comment
Share on other sites

We have a strange bug with AA or AT AI.

Some time, during mission, an AA/AT AI was killed by another AI.

So, that AA/AT AI (that was killed) gets up and run without stopping and he's in god mod.

 

On the other side, If the AA/AT AI was killed by a player we have no problem.

 

this is an arma bug that randomly happend sometimes when an ai dies, regardles of wheather killer was an ai or whatever weapon was in use.

 

the ai is dead and can be looted if stopped in some other way, but will stay stuck in running animation untill deleted.

Possibly it could be scripted to stop somehow, but i doubt it and imo its not even worth the truble to try.

Link to comment
Share on other sites

  • 6 months later...
  • 3 weeks later...
  • 1 month later...

I have this working however this error is spamming the hell out of my RPT.

21:23:03 [DZMS]: Running Minor Mission SM5.
21:23:05 Error in expression <[(_x select 0),(_x select 1)]
} forEach _aicskill;



_unit addEventHandler ["Ki>
21:23:05   Error position: <_aicskill;



_unit addEventHandler ["Ki>
21:23:05   Error Undefined variable in expression: _aicskill
21:23:05 File z\addons\dayz_server\DZMS\Scripts\DZMSAISpawn.sqf, line 136
21:23:05 Error in expression <[(_x select 0),(_x select 1)]
} forEach _aicskill;

 

I have also changed the missions so they will display as hints and not text but those edits are in the actual missions.

 

Here is my edited DZMSAISpawn.sqf

/*																		//
	DZMSAISpawn.sqf by Vampire
	Usage: [position,unitcount,skillLevel] execVM "dir\DZMSAISpawn.sqf";
		Position is the coordinates to spawn at [X,Y,Z]
		UnitCount is the number of units to spawn
		SkillLevel is the skill number defined in DZMSAIConfig.sqf
*/																		//
private [
	"_position", "_unitcount", "_skill", "_wpRadius", "_xpos",
	"_ypos", "_unitGroup", "_aiskin", "_unit", "_weapon",
	"_magazine", "_wppos1",	"_wppos2", "_wppos3", "_wppos4",
	"_wp1",	"_wp2",	"_wp3",	"_wp4",	"_wpfin", "_unitArrayName",
	"_unitMissionCount", "_giveAT",	"_giveAA", "_configured"
];

_position = _this select 0;
_unitcount = _this select 1;
_skill = _this select 2;
_unitArrayName = _this select 3;
_giveAT = if (count _this > 4) then {_this select 4} else {false};
_giveAA = if (count _this > 5) then {_this select 5} else {false};

//diag_log text format ["[DZMS]: AI Pos:%1 / AI UnitNum: %2 / AI SkillLev:%3",_position,_unitcount,_skill];

_wpRadius = 20;

_xpos = _position select 0;
_ypos = _position select 1;

//Create the unit group. We use east by default.
_unitGroup = createGroup east;

//Probably unnecessary, but prevents client AI stacking
if (!isServer) exitWith {};

for "_x" from 1 to _unitcount do {

	//Lets pick a skin from the array
	_aiskin = DZMSBanditSkins call BIS_fnc_selectRandom;

	//Lets spawn the unit
	_unit = _unitGroup createUnit [_aiskin, [(_position select 0),(_position select 1),(_position select 2)], [], 10, "PRIVATE"];
	
	//Make him join the correct team
	[_unit] joinSilent _unitGroup;
	
	//Add the behaviour
	_unit enableAI "TARGET";
	_unit enableAI "AUTOTARGET";
	_unit enableAI "MOVE";
	_unit enableAI "ANIM";
	_unit enableAI "FSM";
	_unit setCombatMode "YELLOW";
	_unit setBehaviour "COMBAT";
	
	//Remove the items he spawns with by default
	removeAllWeapons _unit;
	removeAllItems _unit;
	_configured = false;
	

	// Give AA if applicable
	if (DZMSUseAA && _giveAA && _x == 1) then {
		_unit addMagazine DZMS_AA_Magazine;
		_unit addMagazine DZMS_AA_Magazine;

		_unit addWeapon DZMS_AA_Weapon;
		_unit selectWeapon DZMS_AA_Weapon;

		_aicskill = DZMSSkillsAA;
		_configured = true;
	};

    // Give AT if applicable
	if (DZMSUseAT && _giveAT && _x == _unitcount) then {
		_unit addMagazine DZMS_AT_Magazine;
		_unit addMagazine DZMS_AT_Magazine;

		_unit addWeapon DZMS_AT_Weapon;
		_unit selectWeapon DZMS_AT_Weapon;

		_aicskill = DZMSSkillsAT;
		_configured = true;
	};

	//Now we need to figure out their loadout, if not already equiped
	if(!_configured) then {
		//Get the weapon array based on skill
		_weaponArray = [_skill] call DZMSGetWeapon;
		
		_weapon = _weaponArray select 0;
		_magazine = _weaponArray select 1;
		
		//diag_log text format ["[DZMS]: AI Weapon:%1 / AI Magazine:%2",_weapon,_magazine];
		
		//Get the gear array
		_aigearArray = [DZMSGear0,DZMSGear1,DZMSGear2,DZMSGear3,DZMSGear4];
		_aigear = _aigearArray call BIS_fnc_selectRandom;
		_gearmagazines = _aigear select 0;
		_geartools = _aigear select 1;
		
		//Gear the AI backpack
		_aipack = DZMSPacklist call BIS_fnc_selectRandom;

		//Lets add it to the Unit
		for "_i" from 1 to 3 do {
			_unit addMagazine _magazine;
		};
		_unit addWeapon _weapon;
		_unit selectWeapon _weapon;
		
		_unit addBackpack _aipack;
		
		if (DZMSUseNVG) then {
			_unit addWeapon "NVGoggles";
		};
		
		{
			_unit addMagazine _x
		} forEach _gearmagazines;
		
		{
			_unit addWeapon _x
		} forEach _geartools;

		//Lets set the skills
		switch (_skill) do {
			case 0: {_aicskill = DZMSSkills1;};
			case 1: {_aicskill = DZMSSkills2;};
			case 2: {_aicskill = DZMSSkills3;};
		};
    };
	
	{
		_unit setSkill [(_x select 0),(_x select 1)]
	} forEach _aicskill;

	
	//Lets prepare the unit for cleanup
	_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSAIKilled; }];
	_unit setVariable ["DZMSAI", true];
};

// These are 4 waypoints in a NorthSEW around the center
_wppos1 = [_xpos, _ypos+20, 0];
_wppos2 = [_xpos+20, _ypos, 0];
_wppos3 = [_xpos, _ypos-20, 0];
_wppos4 = [_xpos-20, _ypos, 0];

// We add the 4 waypoints
_wp1 = _unitGroup addWaypoint [_wppos1, _wpRadius];
_wp1 setWaypointType "MOVE";
_wp2 = _unitGroup addWaypoint [_wppos2, _wpRadius];
_wp2 setWaypointType "MOVE";
_wp3 = _unitGroup addWaypoint [_wppos3, _wpRadius];
_wp3 setWaypointType "MOVE";
_wp4 = _unitGroup addWaypoint [_wppos4, _wpRadius];
_wp4 setWaypointType "MOVE";

// Then we add a center waypoint that tells them to visit the rest
_wpfin = _unitGroup addWaypoint [[_xpos,_ypos, 0], _wpRadius];
_wpfin setWaypointType "CYCLE";

//diag_log text format ["[DZMS]: Spawned %1 AI at %2",_unitcount,_position];

// load the unit groups into a passed array name so they can be cleaned up later
call compile format["
%1 = %1 + (units _unitGroup); 
_unitMissionCount = count %1;
",_unitArrayName];
diag_log text format["[DZMS]: (%3) %1 AI Spawned, %2 units in mission.",count (units _unitGroup),_unitMissionCount,_unitArrayName];

Link to comment
Share on other sites

  • 8 months later...

I just added this since people started figuring out they can clear the DZMS with helis just howering.. 

But Im getting the same spam in the RPT and it would be nice to have a fix... its an old script but does anyone know a good way to fix this ? :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...