Jump to content
Grumpy Old Man

[Release] GOM_fnc_ambientArtilleryFire V1.2

Recommended Posts

GOM_fnc_ambientArtilleryFire V1.2

 

 


Purpose of this script:

 

Gives mission makers access to simple ambient artillery units that fire just for decorative purposes into random directions.

 

 

Features:

  • Dedi and local MP compatible
  • Takes pre placed vehicles and uses their main guns to engage artillery fire at simulated targets for the given salvo/rounds number.
  • Works fine with with vanilla artillery assets and multiple third party vehicles.
  • It's also possible to immediately stop the script and free up all units to fire on actual threats, so you can use the same units for the vanilla artillery support module/other arty scripts.

 

How to use this script:
At first copy the spoiler contents into a file inside your mission folder and name it accordingly.

 

init.sqf:

_initAmbientArty = [] execVM "scripts\GOM\ambient\GOM_fnc_ambientArtilleryFire.sqf";

 

scripts\GOM\ambient\GOM_fnc_ambientArtilleryFire.sqf:

 

//How to add artillery gun to battery:
//init field of gun: this setVariable ["GOM_fnc_ambientArtyBatteryID","Battery01",true];
//this will add the gun to "Battery01"

GOM_fnc_abortAmbientArtilleryFire = {

	missionNamespace setVariable ["GOM_ambientArtilleryFiring",false,true];

};


GOM_fnc_ambientArtyFireGun = {

	params ["_gun","_dir","_alt","_rounds","_guns","_debug"];

	_position = _gun getRelPos [250, _dir];
	_position = ATLtoASL _position;
	_position = _position vectorAdd [random [1,3,5],random [1,3,5],_alt + random [1,3,5]];

	if !(GOM_ambientArtilleryFiring) exitWith {false};
	_leader = _guns select 0;
	_isLeader = _gun isEqualTo _leader;
	_gun setVariable ["GOM_fnc_ambientArtyReady",false];
	_artyAmmo = getArtilleryAmmo [_gun] select 0;

//select higher weapon charge so the projectile travels further
		_weaponmodes = getArray (configfile >> "CfgWeapons" >> currentweapon _gun >> "modes");

		_weaponModeIndex = _weaponmodes findIf {getNumber (configfile >> "CfgWeapons" >> currentweapon _gun >> _x >> "artilleryCharge") >= 0.5};

		if (_weaponModeIndex < 0) then {_weaponModeIndex = 0};

		gunner _gun action ["SwitchWeapon",  _gun,  gunner _gun,_weaponModeIndex];

	sleep random [0,1,2];
	gunner _gun doWatch _position;
	sleep random [5,7,10];
	_gun setVariable ["GOM_fnc_ambientArtyTurretReady",true,true];

	waituntil {{_x getVariable ["GOM_fnc_ambientArtyTurretReady",false]} count _guns isEqualTo count _guns OR !GOM_ambientArtilleryFiring};
	if !(GOM_ambientArtilleryFiring) exitWith {false};





	sleep random [0,0.5,1];
	for "_i" from 1 to _rounds do {

		if !(GOM_ambientArtilleryFiring) exitWith {false};

		_gun setVehicleAmmoDef 1;
		_gun addEventHandler ["Fired",{

			params ["_gun","","","","","","_projectile"];
			_gun removeEventHandler ["Fired",_thiseventhandler];
			_projectile setFeatureType 2;//makes it visible as far as terrainViewDistance goes
			_delete = _projectile spawn {

			//wait until projectile has negative Z velocity
			waitUntil {velocity _this # 2 <= 0 AND (getPosATL _this # 2) < 200 OR !alive _this};
			if (alive _this) then {deleteVehicle _this};
		};
		}];



		gunner _gun action ["SwitchWeapon",  _gun,  gunner _gun,_weaponModeIndex];
		_gun action ["useWeapon", _gun, gunner _gun,0];

		_getMuzzle  = getarray (configfile >> "CfgVehicles" >> typeof _gun >> "Turrets" >> "MainTurret" >> "weapons");
		_reloadtime = getnumber (configfile >> "CfgWeapons" >> (_getMuzzle select 0) >> "reloadTime");

		if (_reloadTime <= 0.5) then {_reloadtime = 0.5};
		sleep (_reloadtime + random [0.1,0.2,0.3]);

	};
_gun setVariable ["GOM_fnc_ambientArtyReady",true];
	if !(GOM_ambientArtilleryFiring) exitWith {false};


};

GOM_fnc_ambientArtilleryFire = {

	params [["_batteryID",""],["_salvoes",4],["_rounds",4],["_debug",false]];

	if (_batteryID isEqualTo "") exitWith {systemchat "Error GOM_fnc_ambientArtilleryFire - No battery ID given!"};

	_guns = vehicles select {_x getVariable ["GOM_fnc_ambientArtyBatteryID",""] isEqualTo _batteryID};



	if (_guns isEqualTo []) exitWith {systemchat "Error GOM_fnc_ambientArtilleryFire - No artillery guns found!"};


	{

		_x setVariable ["GOM_fnc_ambientArtyReady",false,true];
		_x setVariable ["GOM_fnc_ambientArtyTurretReady",false,true];

	} foreach _guns;

	_dir = random 360;
	_alt = random [150,200,300];

	for "_i" from 1 to _salvoes do {
		if !(GOM_ambientArtilleryFiring) exitWith {false};

		if (_debug) then {
			_guns select 0 sidechat format ["Salvo %1 of %2.",_i,_salvoes];
			_guns select 0 sidechat format ["%1 rounds.",_rounds]
		};

		{[_x,_dir,_alt,_rounds,_guns,_debug] spawn GOM_fnc_ambientArtyFireGun} forEach _guns;

		waitUntil {{_x getVariable ["GOM_fnc_ambientArtyReady",false]} count _guns isEqualTo count _guns OR !GOM_ambientArtilleryFiring};
		if !(GOM_ambientArtilleryFiring) exitWith {false};

		if (_debug) then {_guns select 0 sidechat format ["Salvo %1 of %2 finished.",_i,_salvoes,_rounds];};

		sleep random [10,15,20];

	};

	if (_debug) then {_guns select 0 sidechat "Firemission complete."};

	{

		_x spawn {

			sleep random [3,5,7];
			gunner _this dowatch objnull;
			_this setVehicleAmmoDef 1;

		};

	} foreach _guns;

};

missionNamespace setVariable ["GOM_ambientArtilleryFiring",true,true];

 

In the editor:

  1. Place few grouped or ungrouped artillery units
  2. put the following into their init fields:  this setVariable ["GOM_fnc_ambientArtyBatteryID","Battery01",true];
  3. _fire = ["Battery01",3,4] spawn GOM_fnc_ambientArtilleryFire

This will make arty guns assigned to "Battery01" fire 3 salvoes with 4 rounds each.

 

Parameters:

_battery = "Battery01"; //battery ID assigned through objects init field
_salvoes = 3; //(OPTIONAL) how many salvoes will be fired
_rounds = 6; //(OPTIONAL) rounds per salvo
_debug = false; //(OPTIONAL) displays debug messages

_fire = [_battery,_salvoes,_rounds] spawn GOM_fnc_ambientArtilleryFire

To abort the script simply call GOM_fnc_abortAmbientArtilleryFire wherever you like.

_abort = [] call GOM_fnc_abortAmbientArtilleryFire;

By executing the script again guns will fire as usual.

 

For best effect place multiple groups executing the code simultaneously,

this way you'll get multiple groups firing at multiple simulated targets.

 

Known Issues:

None so far.

 

Changelog:

 

V1.2:

  • Made script local MP and dedi compatible
  • Improved firing Arc
  • Improved projectile deletion
  • Guns are now assigned to batteries to allow multiple batteries for ambient artillery fire

 

SP Demo Mission

 

Enjoy!

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

I love ambient scripts. I will test it and probably implement to my server. Thanks a lot for sharing. :-)

  • Like 1

Share this post


Link to post
Share on other sites

Do we have a SP Demo Mission for this script?

Share this post


Link to post
Share on other sites
8 hours ago, Coolie said:

Do we have a SP Demo Mission for this script?

Added sp demo mission.

Also changed how the scripts were executed, hence update to 1.1.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I like it!

Nice would be a given direction as fourth parameter like [20,70].

Share this post


Link to post
Share on other sites

V1.2:

  • Made script local MP and dedi compatible
  • Improved firing Arc
  • Improved projectile deletion
  • Guns are now assigned to batteries to allow multiple batteries for ambient artillery fire
  • Thanks 2

Share this post


Link to post
Share on other sites

@Grumpy Old Man here I go with my suggestion. In your demo can you set up a simple task assigned to destroy the artillery battery units and a break in the battery firing for resupplying the units with more ammo like every 15 minutes or so. What a cool mission objective that mission designers can design defenses around the artillery battery.

 

I can see a mission we're special forces need to sneak into a mountain range and destroy the artillery battery.

Cheers Avibird ?

  • Like 1

Share this post


Link to post
Share on other sites
37 minutes ago, avibird 1 said:

@Grumpy Old Man here I go with my suggestion. In your demo can you set up a simple task assigned to destroy the artillery battery units and a break in the battery firing for resupplying the units with more ammo like every 15 minutes or so. What a cool mission objective that mission designers can design defenses around the artillery battery.

 

I can see a mission we're special forces need to sneak into a mountain range and destroy the artillery battery.

Cheers Avibird ?

Well you can do any kind of mission you can think of.

This is meant as a tool for mission makers to bring more life to their missions.

It already fires a user defined amount of rounds and salvoes, up to the mission maker to add certain reammo breaks or whatnot.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, Grumpy Old Man said:

V1.2:

 

Thank you Grumpy Old Man for the update !

  • Like 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man I understand you may not be supporting this anymore, but I managed to get this working for canon artillery using your text from your post, but I can't seem to get it working for rocket artillery.  I did initially have an error from trying to copy the text from the spoiler tag (the demo mission isn't avilable anymore), but I think I've eliminated any of those errors now.  Guns attached to Battery01 work, but rockets attached to Battery02 don't.  I do occassionally get an error about reload time (Line 74), and I believe that's related to the rockets, as the guns don't seem to have the issue.

 

I know it shouldn't matter, but I've tried this with 3CB Soviet artillery (basically RHS-based stuff) and RHS rocket artillery.  Both have the same issue.  Any ideas?  Otherwise, this is a great find and thanks for making it available.

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

×