Jump to content
Sign in to follow this  
Eain

Limiting the amount of missiles called in via a script

Recommended Posts

So I've got this guided missile script from here:

http://www.kylania.com/ex/?p=21

It works perfectly well. In this mission I'm working on I want the player to call in a guided missile strike on several armored vehicles before calling in an infantry assault on a town. The problem is that with this script the player can call in an infinity of missile strikes and just wipe out all resistance from the safety of his hilltop.

I can't really find anything in the script that allows me to limit the amount of missiles to call (preferably 3) so I guess it would require a new line of code. Code that I don't know.

If anyone here could help me out I'd be most grateful.

Share this post


Link to post
Share on other sites

AnimalMother92 has the latest version of that script which includes multiple shell types and limited ammo, hopefully he can post that or I can when I get back from work. :)

Share this post


Link to post
Share on other sites

Oooh that would be neat. I'll stay on the lookout then.

Share this post


Link to post
Share on other sites

I use this script as well and would like to see the updated one also :bounce3:

However I modified the missile script so it only fires a certain amount of times, add this up at the top line:

if (ASMIS == ASnumMIS) then 
{
hint "You cannot call missile strikes anymore.";
exit1 = true
};

if (exit1) exitwith {misActive = false};

ASMIS = ASMIS + 1;

Then place this in your init file:

misActive	= false;

ASnumMIS = 5;  //number of times missile can be called

misSupLimit = "";
ASMIS = 0;

exit1 = false;

Edited by cobra4v320

Share this post


Link to post
Share on other sites

That worked great cobra, thanks :)

Share this post


Link to post
Share on other sites
AnimalMother92 has the latest version of that script which includes multiple shell types and limited ammo, hopefully he can post that or I can when I get back from work. :)

Ah, that I do. I will post the modified version up as soon as I get to my desktop (unless kylania beats me :p)

---------- Post added at 06:16 PM ---------- Previous post was at 04:54 PM ----------

Ok, here's the modified version with all kylania's awesome tweaks on my request (thanks man!)

This limits you to 4 Hellfires and 2 GBUs. The UAV does all the sideChatting but that can be changed to whatever you want.

missilestart Game Logic

miMissionActive = false; this attachTo [uAV,[0,-10,-30]]; miHellFireAvailable = 4;miGBUAvailable = 2; publicVariable "miMissionActive";publicVariable "miHellFireAvailable"; publicVariable "miGBUAvailable";

I added the attachTo because I wanted the missile spawn point to not be static, but it's not necessary. The original setPos works fine as well. Then all that's left is to addAction it to the player.

player addAction["Request Missile (Hellfire)","launchMissile.sqf",[player, missilestart,"M_Hellfire_AT",200]];

Script:

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: Venori
// Tweaks by: kylania
//////////////////////////////////////////////////////////////////

_primaryTarget = lasertarget (_this select 1); //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
_id = _this select 2;

// miHellFireAvailable = 4;
// miGBUAvailable = 2;
_round = "";
_reloadTime = 30;

if (isNull _primarytarget) exitWith {UAV sideChat "Cannot lock target."};
if (miMissionActive) exitWith {UAV sideChat "Unable to fire."};

if (miHellfireavailable == 0 && _missileType == "M_Hellfire_AT") exitWith {UAV sideChat "Hellfires depleted."; _this select 1 removeAction _id;};
if (miGBUAvailable == 0 && _missileType == "Bo_GBU12_LGB") exitWith {UAV sideChat "GBUs depleted."; _this select 1 removeAction _id;};

miMissionActive = true;

switch (_missileType) do {
case "M_Hellfire_AT": {miHellFireAvailable = miHellFireAvailable - 1; _round = "Hellfire"; publicVariable "miHellfireavailable";};
case "Bo_GBU12_LGB": {miGBUAvailable = miGBUAvailable - 1; _round = "GBU"; publicVariable "miGbuavailable";};
};

UAV sideChat format["Target locked, %1 inbound.", _round];
sleep 5;

_perSecondChecks = 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;

//secondary target used for random trajectory when laser designator is turned off prematurily
_secondaryTarget = "HeliHEmpty" createVehicle _defaultTargetPos;
_secondaryTarget setPos _defaultTargetPos;

_guidedRandomly = FALSE;

//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;

_velocityX = (((getPosASL _target) select 0) - ((getPosASL _missile) select 0)) / _travelTime;
_velocityY = (((getPosASL _target) select 1) - ((getPosASL _missile) select 1)) / _travelTime;
_velocityZ = (((getPosASL _target) select 2) - ((getPosASL _missile) select 2)) / _travelTime;

//_defaultTargetPos = position _target;
};

[_velocityX, _velocityY, _velocityZ]
};

call _homeMissile;

//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]];

//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;

sleep _reloadtime;
miMissionactive = false;

if (miHellfireavailable == 0 && _round == "Hellfire") exitWith {UAV sideChat "Hellfires depleted."; _this select 1 removeAction _id;};

if (miGBUAvailable == 0 && _round == "GBU") exitWith {UAV sideChat "GBUs depleted."; _this select 1 removeAction _id;};

UAV sideChat "Ready to fire.";

Effects:

1E1jnCeRU68

HdaOFDW_rxE

And you can play the mission using this script here: http://www.armaholic.com/page.php?id=11810

:cool:

Edited by AnimalMother92

Share this post


Link to post
Share on other sites

This is an awesome script, especially with those modifications...

Now for a request for one more, can it be modified to be fireable on a target as designated by the UAB; much like the Apache?

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
Sign in to follow this  

×