Jump to content
Sign in to follow this  
icfhoop

Guiding missle question

Recommended Posts

Hello,

Before I get into the thick of things, I did in fact use the search function, and if I missed something I apologize.

To the point; in the first mission in Red Harvest, you are up on the point calling in what seem like tomahawks (or something of that nature) by simply using your laser designator and calling it in via the action menu, thus the missle would land where the laser was. My question is how can i replicate this, I dePBOed the mission and found a script called launchmissle.sqf

_primaryTarget = _this select 0; //target for the missile

_missileStart = _this select 1; //position where te missile will be spawned

_missileType = _this select 2; //type of the missile

_missileSpeed = _this select 3; //speed of the missile

_defaultTargetPos = _this select 4; //default position where unguided missiles will fly [8340.718750,3074.914795,0];

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

//-----mission-specific code (C1: Into the Storm)

[_missile] spawn {

while {alive (_this select 0)} do {

if (!(isNil "BIS_missionScope")) then {BIS_missionScope setVariable ["impactPos", position (_this select 0)]};

sleep 0.01

};

{_x setDamage 1} forEach ((BIS_missionScope getVariable "impactPos") nearObjects ["All",10]);

if (!(isNil "BIS_missionScope")) then {BIS_missionScope setVariable ["impact", TRUE]};

};

//-----end of mission-specific code

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

But I am unsure if this has any relevance, but i was wondering if any one knew how to accomplish this.

I appreciate any help.

Thanks you in advance. -Hoop

Share this post


Link to post
Share on other sites

all you need to do is call the code and supply the required info.

just to get it working for now.

Place the function module on the map.

Create a game logic and name it maintarget

Create a game logic and name it deftarget

Place a flying helicopter and name it missilestart

now you just need the call code placed in the chopper init

nul=[maintarget,getpos deftarget,"M_Ch29_AT",200,getpos deftarget] execvm "launchmissle.sqf"

you could use CruiseMissile2 if you wish, some other bombs work as well.

The chopper could be replaced as long as you give the start location some height or the missile spawns too low.

The maintarget game logic could be replaced by a onmapsingleclick command or use something like cursortarget combined with laser designator.

Share this post


Link to post
Share on other sites

Nice work F2K_Sel, got this working perfectly now!! With a few changes :)

1. Place Functions Module

2. Create a GameLogic and name it missilestart and place it where you want your missiles coming from. (500m up seemed pretty awesome: this setPos [getPos this select 0, getPos this select 1, 500]) Looks best when it's within 1000m of the player.

5. Call it from the radio or addAction with the following code:

nul=[laserTarget player, getpos missilestart,"M_Ch29_AT",200] execvm "launchmissile.sqf"

4. Use the script below with one small change from the original (in orange below). Basically if your laser it's turned on you won't get a missile.

_primaryTarget = _this select 0; //target for the missile
_missileStart = _this select 1; //position where te missile will be spawned
_missileType = _this select 2; //type of the missile
_missileSpeed = _this select 3; //speed of the missile
_defaultTargetPos = _this select 4; //default position where unguided missiles will fly [8340.718750,3074.914795,0];

[color="DarkOrange"]if (isNull _primarytarget) exitWith {hintSilent "No Target Found!"};[/color]

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

In testing it seemed as if the deftarget stuff wasn't working at all, or if it was the distance was so small as to not matter, so I removed that part of the setup. Script seems to run fine.

It's a little crazy how the missile will follow your target like a cat chasing a laser pen till she crashes into something!

Edited by kylania

Share this post


Link to post
Share on other sites

Thanks kylania for cleaning it up and for reminding me of laserTarget, spent alot of time a while back trying to detect when I was using the laser when I only needed to use lasertarget instead of cursortarget.

If anyone does use the cruisemissile you will have to spawn a bomb at the missiles final location as it has about as much impact as a fly swatter.

Share this post


Link to post
Share on other sites

I appreciate the help from both of you guys. Thank you thank you :)

Share this post


Link to post
Share on other sites

Works great, thanks !

@ kylania

You have made a little mistake. The gamelogic must be named missilestart in your example !

Share this post


Link to post
Share on other sites

one more question real quick, how could i make it to where there is 15 seconds between each missle strike so it simulates "reloading"?

Thanks.

Share this post


Link to post
Share on other sites

Several ways are possible. Are you using the method I posted above? If so how did you want it to work: You manually trigger each shot, you call in a fire mission of a set amount of shots, you select from a selection of shot amounts or the amount is determined by how the script is called?

Share this post


Link to post
Share on other sites

All I want is for the FAC operator (player) to call one in missile strike at a time, with 15 seconds between each request for a strike. (to prevent player from spamming the area, and to simulate reload.)

Oh and sorry I forgot to add, along with this can I have it to where if a player tries calling it in while it is "rearming" can I have a hint popping up saying you have to wait x amount of time?

Edited by icfhoop
forgot to add this

Share this post


Link to post
Share on other sites

Anything to do with sleep command maybe?

Share this post


Link to post
Share on other sites
All I want is for the FAC operator (player) to call one in missile strike at a time, with 15 seconds between each request for a strike. (to prevent player from spamming the area, and to simulate reload.)

Oh and sorry I forgot to add, along with this can I have it to where if a player tries calling it in while it is "rearming" can I have a hint popping up saying you have to wait x amount of time?

Demo mission.

Share this post


Link to post
Share on other sites

Exactly what I was looking for thank you kylania :)

Share this post


Link to post
Share on other sites

For some reason I cannot get this to work with addaction at all, but it works with a radiotrigger.

it's literally like all the arguments are being deleted inbetween the action and the script. I've tried everything I can think of to try and fix this but it's still not working

Share this post


Link to post
Share on other sites

For addAction use:

_primaryTarget = (_this select 3) select 0; //target for the missile
_missileStart = (_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 

Share this post


Link to post
Share on other sites
For addAction use:

_primaryTarget = (_this select 3) select 0; //target for the missile
_missileStart = (_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 

two issues right now:

Error in expression <serTarget player, getpos missilestart, "M_Hellfire_AT", 250]", 6];>
 Error position: <M_Hellfire_AT", 250]", 6];>
 Error Missing ]

Error in expression <imaryTarget;

_missile = "_missiletype" createVehicle _launchlocation;
_missile >
 Error position: <createVehicle _launchlocation;
_missile >
 Error createvehicle: Type Object, expected Array

Share this post


Link to post
Share on other sites
two issues right now:

Error in expression <serTarget player, getpos missilestart, "M_Hellfire_AT", 250]", 6];>
 Error position: <M_Hellfire_AT", 250]", 6];>
 Error Missing ]

Looks like you forgot to use a [ by "M_Hellfire_AT"

On your second error it looks like you need to remove the "" on "_missiletype"

By the way pretty cool mission Kylania.

Edited by cobra4v320

Share this post


Link to post
Share on other sites
Looks like you forgot to use a [ by "M_Hellfire_AT"

On your second error it looks like you need to remove the "" on "_missiletype"

By the way pretty cool mission Kylania.

there isn't an "" on missiletype it's just how the arma2oa.rpt outputs it. And there really, really shouldn't need to be a '[' by "M_Hellfire_AT" which is why it's such a confusing error.

Share this post


Link to post
Share on other sites

Worked like that in my demo mission by changing the missile type to M_Hellfire_AT, maybe there's something else wrong in the trigger?

Share this post


Link to post
Share on other sites

it's not a trigger though, it's an addaction. This script seems to work fine with a trigger but with addaction it FLIPS. OUT.

Share this post


Link to post
Share on other sites

For addAction to work change the script to read:

_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

And call it as:

this addAction["Fire Missile","launchMissile.sqf",[this, missilestart,"M_Hellfire_AT",200]];

Share this post


Link to post
Share on other sites

nope, still getting errors relating to createvehicle

Share this post


Link to post
Share on other sites

You've got something wrong somewhere than, can you host your mission somewhere so we can download it?

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  

×