Jump to content

Recommended Posts

handleautodeploy.jpg

 

Story

This is a script that I wrote a few weeks ago for a friend. It's supposed to let AI's with specific backpack's deploy static weapons automatically in a combat. You can link specific backpacks with specific static weapons multiple times. This script doesn't work, if the AI is in a combat mode all the time or if the AI never gets to be in a combat mode. There are several routine integrated to avoid script errors. A description can be found inside the SQF file, how to execute the script. It's SP/MP/Dedicated and HC compatible. Have fun.

 

Content

It is a single ~80Code-Line-Big Script to let AI's with specific backpack's deploy static weapons automatically in a combat.

 

Purpose

The aim of this script is to make it easier to implement a universal script, which makes a combat with AI more interesting.

 

Download

Missions and Script on GitHub

 

ArmaHolic

Link

 

Credits

Script & Media: Rockhount

 

Examples

 

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"]] execVM "HandleAutoDeploy.sqf";

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"],["B_Bergen_mcamo_F","B_Mortar_01_F"]] execVM "HandleAutoDeploy.sqf";

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"],["B_Bergen_mcamo_F","B_Mortar_01_F"],["B_Bergen_hex_F","B_GMG_01_high_F"],["B_Bergen_tna_F","O_GMG_01_high_F"]] execVM "HandleAutoDeploy.sqf";

 

All 3 examples are possible, because there is no limit for the amount of parameters.

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Congratulations on the script. I would like to ask if it can be used to deploy mortars or anti-missiles type TOW or similar.

 

BR

 

AtomicBoy

Share this post


Link to post
Share on other sites

You have to type the classname of the static weapon & backpack as script parameters, so you can choose whatever you want. Try it.

Share this post


Link to post
Share on other sites

Hi @rockhount,

 

Would it be possible to have this lovely script as an addon?  It would need to detect what exact backpack a soldier is wearing then choose to deploy in the correct scenario (ie it would be useless to setup a titanAA if you were being attacked by a tank).

 

As an addon I could see this being used quite extensively.

Share this post


Link to post
Share on other sites

Nope. No plans to do that now or in the future. But its open source under the MIT license, so everyone who wants can do that.

Share this post


Link to post
Share on other sites

to use the script with mortars or anti-tank misiles:

 

removeBackpackGlobal u1;u1 addBackpackGlobal "B_Bergen_dgtl_F";
nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"],["B_Bergen_mcamo_F","B_Mortar_01_F"]] execVM "HandleAutoDeploy.sqf";


removeBackpackGlobal u1;u1 addBackpackGlobal "B_Bergen_dgtl_F";
nul=[["B_Bergen_dgtl_F","B_static_AT_F"],["B_Bergen_mcamo_F","B_static_AT_F"]] execVM "HandleAutoDeploy.sqf";

 

Share this post


Link to post
Share on other sites

@rockhount many thanks for replying so soon mate.  If I was skilled enough I'd love to have something like this made, as it would help to open up gameplay features via AI so much more.  Thanks for being honest.

 

Share this post


Link to post
Share on other sites

good afternoon

I have detected a possible bug, when I put two soldiers with the script to execute it, each soldier deploys 2 weapons. If I have to deploy machine guns, each soldier deploys 2 machine guns. If I have them deploy mortars, each soldier deploys 2 mortars.

Any idea where the fault may be?

BR

AtomicBoy

Share this post


Link to post
Share on other sites

Let me guess. You ran the script twice. From the description inside the SQF: "The backpacks of all existing units get scanned 10 seconds after this script has been called. If the backpack can be find in the script parameters, then the unit gets a loop as long as he lives." That means: Run the script only once for all units. You can pass infinite number of "[BackpackClassName,StaticWeaponClassName]" parameters as Arrays in one call, as you want. There is no scenario, where it's needed to call/run this script more than once.

 

Examples:

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"]] execVM "HandleAutoDeploy.sqf";

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"],["B_Bergen_mcamo_F","B_Mortar_01_F"]] execVM "HandleAutoDeploy.sqf";

nul=[["B_Bergen_dgtl_F","B_Mortar_01_F"],["B_Bergen_mcamo_F","B_Mortar_01_F"],["B_Bergen_hex_F","B_GMG_01_high_F"],["B_Bergen_tna_F","O_GMG_01_high_F"]] execVM "HandleAutoDeploy.sqf";

 

All 3 examples are possible, because there is no limit for the amount of parameters.

Share this post


Link to post
Share on other sites

I have allowed myself to upgrade to use UAV.

 

use as the original script:

 

In the init of the soldier transporting the uav vehicle add:

 

removeBackpackGlobal this;
this addBackpackGlobal "B_UAV_01_backpack_F";


The script is added to the init of a vehicle, a soldier or an empty object:

UAV only:

nul = [["B_UAV_01_backpack_F", "B_UAV_01_F"]] execVM "HandleAutoDeploy_v2r0.sqf";

 

Combined with other deployable weapons:

nul=[["rhs_M252_Gun_Bag","B_Mortar_01_F"],["RHS_MK19_Gun_Bag","B_GMG_01_high_F"],["RHS_M2_Gun_Bag","B_HMG_01_high_F"],["B_UAV_01_backpack_F","B_UAV_01_F"]] execVM "HandleAutoDeploy_v2r0.sqf";

 

copy the script textt to a txt file and rename to HandleAutoDeploy_v2r0.sqf

 

 

/*
	Made by Rockhount - HandleAutoDeploy Script v1.1 (SP/MP & HC compatible)
	Errors will be written into the rpt and starts with "HandleAutoDeploy Error:"
	Call:
	[["B_HMG_01_A_weapon_F","B_GMG_01_high_F"],["O_HMG_01_high_weapon_F","O_GMG_01_high_F"]] execVM "HandleAutoDeploy_v2r0.sqf";
	"B_HMG_01_A_weapon_F" = Classname of the backpack
	"B_GMG_01_high_F" = Classname of the static weapon

	removeBackpackGlobal this; 
	this addBackpackGlobal "B_UAV_01_backpack_F";

	nul=[["B_UAV_01_backpack_F","B_UAV_01_F"]] execVM "HandleAutoDeploy_v2r0.sqf";

	nul=[["rhs_M252_Gun_Bag","B_Mortar_01_F"],["RHS_MK19_Gun_Bag","B_GMG_01_high_F"],["RHS_M2_Gun_Bag","B_HMG_01_high_F"],["B_UAV_01_backpack_F","B_UAV_01_F"]] execVM "HandleAutoDeploy_v2r0.sqf";
	
	The backpacks of all existing units get scanned 10 seconds after this script has been called. If the backpack can be
	find in the script parameters, then the unit gets a loop as long as he lives. The unit gets queried wheter or not he
	is in a "COMBAT" Modus. If he is, then he builds automaticly the static weapon with an animation. The static weapon
	will get undeployed only, if the unit is no longer in a "COMBAT" Modus or 10 minutes have elapsed.

	
	-------------------------------------------------------------------------------------------------------------------------
	Gemacht von Rockhount - HandleAutoDeploy Skript v1.1 (SP/MP & HC Kompatibel)
	Fehler werden in die RPT geschrieben und starten mit "HandleAutoDeploy Error:"
	Aufruf:
	[["B_HMG_01_A_weapon_F","B_GMG_01_high_F"],["O_HMG_01_high_weapon_F","O_GMG_01_high_F"]] execVM "HandleAutoDeploy.sqf";
	"B_HMG_01_A_weapon_F" = Klassenname des des Rucksacks
	"B_GMG_01_high_F" = Klassenname der statischen Waffe
	
	10 Sekunden nachdem der Skript aufgerufen wurde, werden alle Einheiten, die existieren, nach ihrem Rucksack abgefragt.
	Wenn der Rucksack in eines der Skriptparameter zu finden ist, dann bekommt diese Einheit solange sie lebt eine Schleife.
	In der Schleife wird abgefragt, ob sich die Einheit im Kampf befindet. Wenn sie sich im "COMBAT" Modus befindet, dann baut
	sie automatisch mit einer Animation die statische Waffe auf. Die statische Waffe wird erst dann wieder abgebaut, wenn sie sich
	nicht mehr im "COMBAT" Modus befindet oder mindestens 10 Minuten seit dem Aufbau vergangen sind.
*/
if (isServer) then
{
	private _Local_var_Exit = false;
	private _Local_var_Classnames = if ((!isNil "_this") && {typeName _this == "ARRAY"}) then {_this} else {_Local_var_Exit = true;false};
	if (_Local_var_Exit) exitWith
	{
		diag_log "HandleAutoDeploy Error: Wrong parameter";
	};
	if (!canSuspend) exitWith 
	{
		diag_log "HandleAutoDeploy Error: This script does not work in an unscheduled environment";
	};
	sleep 10;
	{
		private _Local_var_Soldier = _x;
		{
			if ((backpack _Local_var_Soldier) == (_x select 0)) exitWith
			{
				[_Local_var_Soldier, _x select 0, _x select 1] spawn
				{
					Params ["_Local_var_Soldier", "_Local_var_BackpackClassname","_Local_var_VehicleClassName"];
					while	{!(isNull _Local_var_Soldier) && {alive _Local_var_Soldier}} do
					{
						waitUntil{sleep 5;!(isNull _Local_var_Soldier) && {alive _Local_var_Soldier} && {(behaviour _Local_var_Soldier) == "COMBAT"}};
						removeBackpackGlobal _Local_var_Soldier;
						
						sleep 4;
						_Local_var_Vehicle = createVehicle [_Local_var_VehicleClassName, getPos _Local_var_Soldier, [], 1, "NONE"];						
						if(getNumber(configFile >> "CfgVehicles" >> typeof _Local_var_Vehicle >> "isUav")==1) then 
						{
						    _NearestEnemy = _Local_var_Soldier findNearestEnemy _Local_var_Soldier;
							[_Local_var_Soldier,""] remoteExec ["switchMove", 0, false];
							_Local_var_Vehicle setDir (getDir _Local_var_Soldier);
							createVehicleCrew _Local_var_Vehicle;
							_Local_var_Vehicle setskill 1;
							_Local_var_Vehicle engineOn true;				 
							_Local_var_Vehicle flyInHeight 100;
							_Local_var_Vehicle domove (getposATL _NearestEnemy);
						
                     							
							
						} else {
		
							_Local_var_Vehicle setDir (getDir _Local_var_Soldier);
							_Local_var_Soldier assignAsGunner _Local_var_Vehicle;
							[_Local_var_Soldier,_Local_var_Vehicle] remoteExec ["moveInGunner", _Local_var_Soldier, false];
						
						};
						_Local_var_Vehicle lock true;
						private _Local_var_Time = time + 600;
						waitUntil{sleep 5; !(isNull _Local_var_Soldier) && {alive _Local_var_Soldier} && {((behaviour _Local_var_Soldier) != "COMBAT") || {time > _Local_var_Time}}};
						if (!(isNull _Local_var_Soldier) && {alive _Local_var_Soldier} && {!isNil "_Local_var_Vehicle"} && {!isNull _Local_var_Vehicle} && {alive _Local_var_Vehicle}) then
						{
							_Local_var_Vehicle lock false;
							private _Local_var_CurDir = getdir _Local_var_Vehicle;
							moveOut _Local_var_Soldier;
							_Local_var_Vehicle lock true;
							[_Local_var_Soldier,"MOVE"] remoteExec ["disableAI", _Local_var_Soldier, false];
							[_Local_var_Soldier,"Acts_TerminalOpen"] remoteExec ["switchMove", 0, false];
							sleep 4;
							[_Local_var_Soldier,_Local_var_BackpackClassname] remoteExec ["addBackpack", _Local_var_Soldier, false];
							deleteVehicle _Local_var_Vehicle;
							[_Local_var_Soldier,""] remoteExec ["switchMove", 0, false];
							[_Local_var_Soldier,"MOVE"] remoteExec ["enableAI", _Local_var_Soldier, false];
						};
					};
				};
			};
		} forEach _Local_var_Classnames;
	} forEach (allUnits - allPlayers - allDeadMen);
};

 

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

×