Jump to content
barbuse

[Release] Guided missile script

Recommended Posts

Simple script that allows you fire a guided missile from the position of your choice to any type of target (object, unit, laser designated target...)

I made this script for a mission I'm working on and I thought that could be useful for others.

Hope you enjoy it !

 

Link to the script guidedMissile.sqf

 

What it does

The script simply creates a missile on a defined position that will track a designated target. The target can be a ground/air static or moving target. It can also be a laser designated target.

 

How it works

To use this script add the following code into a trigger:
 

nul=[target, startLocation, missileType, missileLaunchingHeight] execVM "guidedMissile.sqf"

For exemple, if the target is laser designated by the player:
 

nul=[laserTarget player, getPos startLocation, "M_Scalpel_AT", 500] execVM "guidedMissile.sqf"

 

Update 1.1

  • Fixed: it is now possible to target fast flying targets such as aircrafts

 

  • Like 2

Share this post


Link to post
Share on other sites
53 minutes ago, Devastator_cm said:

Thanks for the script.
It will help to create no fly zones :)

You're welcome :) The script was made to hit ground targets so you might need to adapt it if you want to hit targets above the missile starting position.

Share this post


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

When I read guided missile I thought it was against air units :(

At the moment it works on ground fixed and moving targets as well as air fixed/slow moving targets. But I do need to improve it to be able to shoot targets such as planes.

32 minutes ago, dimas1k said:

Its work in MP?

I haven't tried yet but I don't see why it wouldn't

Share this post


Link to post
Share on other sites

I've updated the script. It now works on any type of targets, including fast moving aircrafts!

  • Like 1

Share this post


Link to post
Share on other sites

Can this work for water to simulate a Sub firing a missile?

Share this post


Link to post
Share on other sites

I keep getting error, line 27
 

Quote

_pos = [_startPos select 0, _startPos select 1, _missileHeight];

 

this is what init looks like,
 

nul=[plane, marker, Titan_AA, 100] execVM "guidedMissile.sqf"

Where the start location is a marker. Not 100% what to put start location as.

can Anyone help me with start location?

and maybe with MissileType and MissileLaunching height.

Thanks

Share this post


Link to post
Share on other sites
On 12/28/2016 at 6:55 PM, scottdog62 said:

I keep getting error, line 27
 

 

this is what init looks like,
 


nul=[plane, marker, Titan_AA, 100] execVM "guidedMissile.sqf"

Where the start location is a marker. Not 100% what to put start location as.

can Anyone help me with start location?

and maybe with MissileType and MissileLaunching height.

Thanks

 

Try this:

nul=[plane, getMarkerPos "marker", "M_Titan_AA", 500] execVM "guidedMissile.sqf"
  1. guidedMissile.sqf requires a position [x, y, z] to work. Use getMarkerPos to get the position of your marker. I assumed it was called marker.
     
  2. For the MissileType, you'll probably need to use M_Titan_AA rather than Titan_AA. Also, MissileType takes the class name as a string so put quotation marks around it.
     
  3. To adjust the MissileLaunching height, just adjust the 4th parameter. The height has been increased to 500m in the example above.

 

Share this post


Link to post
Share on other sites

Thanks heeps, it works.

One other thing, is there a way to make the camera follow the missile(like bullet cam).

Share this post


Link to post
Share on other sites

Hello. This is essentially an updated stripped down clean version of @kylania Missile Script. I use a somewhat updated version, but am getting the following error and am wondering if you can assist with your understanding and revision of the missile script.

The script works and the missile hits the target, but I'm getting the following error.

rpt

Spoiler

21:37:27 Error in expression <] call BIS_fnc_param;

};
if ((typeName _velocityX) != (typeName 0)) then {_velo>
21:37:27   Error position: <_velocityX) != (typeName 0)) then {_velo>
21:37:27   Error Undefined variable in expression: _velocityx
21:37:27 launch_missile.sqf, line 108
21:37:27 Error in expression <eck = call _homeMissile;
if ({(typeName _x) == (typeName 0)} count _velocityForC>
21:37:27   Error position: <_x) == (typeName 0)} count _velocityForC>
21:37:27   Error Undefined variable in expression: _x
21:37:27 launch_missile.sqf, line 138

 

 

launch_missile.sqf

Spoiler

// _primaryTarget = lasertarget ((_this select 3) select 0); //target for the missile
// _missileStart = getPos ((_this select 3) select 1); //position where te missile will be spawned
// _missileType = (_this select 3) select 2; //type of the missile
// _missileSpeed = (_this select 3) select 3; //speed of the missile
// _defaultTargetPos = (_this select 3) select 4; //default position where unguided missiles
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////
private ["_primaryTarget","_missileStart","_missileType","_missileSpeed","_defaultTargetPos","_perSecondChecks","_getPrimaryTarget","_target","_missile","_secondaryTarget","_guidedRandomly","_homeMissile"];
_primaryTarget = laserTarget vehicle player; //target for the missile
_missileStart = [((getPosASL sub3) select 0) - 17,((getPosASL sub3) select 1) + 0,((getPosASL sub3) select 2) + 10]; //position where the missile will be spawned
_missileType = "Missile_AGM_02_F"; //type of the missile
_missileSpeed = 880; //speed of the missile
_defaultTargetPos = [(getPosASL proteus2) select 0,(getPosASL proteus2) select 1,(getPosASL proteus2) select 2]; //default position where unguided missiles
_stageTargetPos = [((getPosASL sub3) select 0) - 17,((getPosASL sub3) select 1) + 0,((getPosASL sub3) select 2) + 520];
_stageSpeed = _missileSpeed / 8;

_reloadTime = 10;

if (isNull _primarytarget) exitWith {hint "No Target Found!"};
mima = server_1 getVariable "miMissileActive";
if (mima) exitWith{hint "Missile unavailable!"};

miMissileActive = true;
server_1 setVariable ["miMissileActive",miMissileActive,true];

hint "Target Detected!\n\nMissile inbound!";
sleep 5;

_perSecondChecks = 25; //direction checks per second
_stageperSecondChecks = 25; //direction checks per second
_getPrimaryTarget = {if (typeName _primaryTarget == typename {}) then {call _primaryTarget} else {_primaryTarget}}; //code can be used for laser dots
_target = call _getPrimaryTarget;

_missile = _missileType createVehicle _missileStart;
_missile setPos _missileStart;

_secondaryTarget = proteus2;
_secondaryTarget setPos _defaultTargetPos;
_altTarget = "Sign_Sphere10cm_F" createVehicle _stageTargetPos;
_altTarget setPos _stageTargetPos;

_guidedRandomly = FALSE;

_stageMissile = {
	private ["_stageTime","_stagesteps","_dummy","_velocityA","_velocityB","_velocityC"];
	_stageTarget = _altTarget;
	if (_missile distance _stageTarget > (_stageSpeed / 88)) then {
	_stageTime = (_stageTarget distance _missile) / _stageSpeed;
	_stagesteps = floor (_stageTime * _perSecondChecks);
	
	_dummy = [];
	_velocityA = [_dummy, 0, ((((getPosASL _stageTarget) select 0) - ((getPosASL _missile) select 0)) / _stageTime), [123]] call BIS_fnc_param;
	_velocityB = [_dummy, 1, ((((getPosASL _stageTarget) select 1) - ((getPosASL _missile) select 1)) / _stageTime), [123]] call BIS_fnc_param;
	_velocityC = [_dummy, 2, ((((getPosASL _stageTarget) select 2) - ((getPosASL _missile) select 2)) / _stageTime), [123]] call BIS_fnc_param;
	};
	 
	if ((typeName _velocityA) != (typeName 0)) then {_velocityA = 0};
	if ((typeName _velocityB) != (typeName 0)) then {_velocityB = 0};
	if ((typeName _velocityC) != (typeName 0)) then {_velocityC = 0};

	[_velocityA, _velocityB, _velocityC]
};

//procedure for guiding the missile
_homeMissile = {

	//here we switch to secondary target at random position if the laser dot no longer exists
	//if the designator is turned on again, the missile will return to it's original target (providing it hadn't flown too far)
	private ["_velocityX", "_velocityY", "_velocityZ", "_target"];
	_target = _secondaryTarget;
	if (!(_guidedRandomly) && _missile distance _target > _missileSpeed * 1.5) then {
		_guidedRandomly = TRUE;
		_target = _secondaryTarget;
		_dispersion = (_missile distance _defaultTargetPos) / 20;
		_dispersionMin = _dispersion / 10;
		_target setPos [(_defaultTargetPos select 0) + _dispersionMin - (_dispersion / 2) + random _dispersion, (_defaultTargetPos select 1) + _dispersionMin - (_dispersion / 2) + random _dispersion, 0];
	};
	if (!(isNull (call _getPrimaryTarget))) then {_target = call _getPrimaryTarget; _defaultTargetPos = position _target; _guidedRandomly = FALSE};

	//altering the direction, pitch and trajectory of the missile
	if (_missile distance _target > (_missileSpeed / 20)) then {
		_travelTime = (_target distance _missile) / _missileSpeed;
		_steps = floor (_travelTime * _perSecondChecks);

		_relDirHor = [_missile, _target] call BIS_fnc_DirTo;
		_missile setDir _relDirHor;

		_relDirVer = asin ((((getPosASL _missile) select 2) - ((getPosASL _target) select 2)) / (_target distance _missile));
		_relDirVer = (_relDirVer * -1);
		[_missile, _relDirVer, 0] call BIS_fnc_setPitchBank;

		_dummy = [];
		_velocityX = [_dummy, 0, ((((getPosASL _target) select 0) - ((getPosASL _missile) select 0)) / _travelTime), [123]] call BIS_fnc_param;
		_velocityY = [_dummy, 1, ((((getPosASL _target) select 1) - ((getPosASL _missile) select 1)) / _travelTime), [123]] call BIS_fnc_param;
		_velocityZ = [_dummy, 2, ((((getPosASL _target) select 2) - ((getPosASL _missile) select 2)) / _travelTime), [123]] call BIS_fnc_param;
		 
	};
	if ((typeName _velocityX) != (typeName 0)) then {_velocityX = 0};
	if ((typeName _velocityY) != (typeName 0)) then {_velocityY = 0};
	if ((typeName _velocityZ) != (typeName 0)) then {_velocityZ = 0};

	[_velocityX, _velocityY, _velocityZ]
};
[_missile, 90, 0] call BIS_fnc_setPitchBank;
call _stageMissile;

//fuel burning should illuminate the landscape
_fireLight = "#lightpoint" createVehicle position _missile;
_fireLight setLightBrightness 0.5;
_fireLight setLightAmbient [1.0, 1.0, 1.0];
_fireLight setLightColor [1.0, 1.0, 1.0];
_fireLight lightAttachObject [_missile, [0, -0.5, 0]];

while {((alive _missile) && (_missile distance proteus < 500))} do {
    _velCheck = call _stageMissile;
    if ({(typeName _x) == (typeName 0)} count _velCheck == 3) then {_missile setVelocity _velCheck};
    sleep (1 / _stageperSecondChecks);
};

/////////////////////////////////////////////////////////////////////////////
waitUntil {(_missile distance proteus > 500)};
[_missile, 0, 0] call BIS_fnc_setPitchBank;
call _homeMissile;

//missile flying
while {alive _missile} do {
    _velocityForCheck = call _homeMissile;
    if ({(typeName _x) == (typeName 0)} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck};
    sleep (1 / _perSecondChecks)
};

deleteVehicle _fireLight;
deleteVehicle _secondaryTarget;
deleteVehicle _altTarget;

sleep _reloadtime;
miMissileActive = false;
server_1 setVariable ["miMissileActive",miMissileActive,true];
hint "Missile available!";

 

 

Thanks for any help.

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

×