Jump to content

Recommended Posts

   MGI GUN RUN

Last update: 01/02/2018

 

Hi all,

Here is another script to add a specific gun run, calling a virtual or real CAS.

This script is to copy/paste inside BI init CAS module. Nothing more to do!

 

The code will search for "cannon" or "Gatling" in the pilot's weapon. So far, it doesn't work for gunners. You can see "no pilot cannon" in the sub-menu.

If you find some non-listed pilot's cannon, let me know.

 

Tips:

- Always place your module/aircraft at 2 km from a target area. It's far better for a straight-in approach. You can even place them outside of the map.

- Don' try to repeat the CAS too soon with a real aircraft. It will turn around the target without aiming it. Don't forget, pilots are dumb (I can say that referring to my own carrier).

- At this time, Buzzard is far more precise than Wipeout which generously spread ammo with poor efficiency.

 

 

Code to copy/paste in init field of the CAS module:

 

0 = this spawn {
  MGI_CAS_MODULE = _this;
  MGI_CAS = compileFinal "
  if !(GUNRUNCAS) exitWith {};
  private _isVirtual = ({_x isKindOf 'air'} count synchronizedObjects MGI_CAS_MODULE ==0);
  _pilot = player getVariable 'BIS_SUPP_selectedProvider';
  _veh = vehicle _pilot;
  _home = getPos MGI_CAS_MODULE;
  _trts = (_veh WeaponsTurret [-1]) select { getText (configfile >> 'CfgWeapons' >> _x >> 'nameSound') == 'cannon'};
  waitUntil {!isNull (_pilot getVariable 'BIS_SUPP_requester')};
  _requester = _pilot getVariable 'BIS_SUPP_requester';
  'Gun run requested' remoteExec ['hint',_requester];
  waitUntil {!isnil {_pilot getVariable 'BIS_SUPP_supportRunCoords'}};
  _coords = _pilot getVariable 'BIS_SUPP_supportRunCoords';
  _alt = getTerrainHeightASL _coords;
  _limit = [40,90] select (_veh distance2D _coords < 2500);
  _pilot setCombatMode 'BLUE';
  _veh flyInHeightASL [_alt +500,_alt +500,_alt +500];
  waitUntil {_veh distance2D _coords < 2000};
  _timer = diag_tickTime;
  _veh flyInHeightASL [_alt +100,_alt +100,_alt +100];
  _resultOK = false;
  'In sight'  remoteExec ['hint',_requester];
  _tgttype = ['laserTargetE','laserTargetW'] select (side _veh == WEST or (side _veh == RESISTANCE && WEST getFriend RESISTANCE >0.6));
  _tgt = createVehicle [_tgttype,_coords,[],0,'none'];
  if (count _trts > 0) then {
    _trt = _trts select 0;
    _mags = (getArray (configfile >> 'CfgWeapons' >> _trt >> 'magazines')) arrayIntersect (_veh magazinesTurret [-1]);
    _cnt = getNumber (configFile >> 'cfgMagazines' >> _mags select 0 >> 'count');
    _pilot setCombatMode 'RED';
    _pilot reveal [_tgt,4];
    while {diag_tickTime < _timer + _limit} do {
      _tgt setPosASL (getPosASL _tgt vectorAdd [0,0,(0.18 * (_veh distance2D _tgt)) -270]); 
      if (!isNil 'BIS_SUPP_laserTGT') then {deleteVehicle BIS_SUPP_laserTGT; BIS_SUPP_laserTGT = nil};
      _veh selectWeaponTurret [_trt,[-1]];
      _veh doTarget _tgt;
      if ((_veh weaponDirection _trt vectorCos (AGLToASL _coords vectorDiff (eyepos _pilot))) > 0.999) then {
       [[_veh,_trt], BIS_fnc_fire] remoteExec ['call',_veh];
        if (_veh magazineTurretAmmo [_veh currentMagazineTurret [-1],[-1]] < _cnt) then {_resultOK = true};
      } else {
        _pilot lookAt _tgt
      };
      uiSleep .01;
    };
  };
  if (!_resultOK) then {_pilot setVariable ['BIS_SUPP_failed',true]};
  (['Gun run aborted','Gun run terminated, resuming support'] select _resultOK) remoteExec ['hint',_requester];
  if !(_isVirtual) then {
    waitUntil {waypointType [group _veh,currentWaypoint group _veh] == 'MOVE'};
    [group _veh,currentWaypoint group _veh] setWaypointPosition [_home,0];
    [group _veh,currentWaypoint group _veh] setWaypointStatements ['true',''];
    _veh setFuel 1;
    {_veh setAmmo [_x, 2000]} forEach _trts;
  };
  _pilot setVariable ['BIS_SUPP_supporting',false];
  if (_isVirtual && alive _veh) then {uiSleep 180; deleteVehicle _veh};
  ";

  _this spawn {
    while {true} do {
      GUNRUNCAS = false;
      waituntil {uiSleep 0.2; ((player getVariable "BIS_SUPP_request") select 0 == "CAS_Bombing") && {!isnull (player getVariable "BIS_SUPP_selectedProvider")}};

      _pilot = player getVariable "BIS_SUPP_selectedProvider";
      _veh = vehicle _pilot;
      _trts = (_veh WeaponsTurret [-1]) select { getText (configfile >> "CfgWeapons" >> _x >> "nameSound") == "cannon"};
      private _cooldown = time - (_this getVariable ["BIS_SUPP_lastCall",time -122]) - ((_this getVariable ["BIS_SUPP_cooldown",0]) max 60);
      BIS_SUPP_commMenu = BIS_SUPP_commMenu + [
        [
          ["Gun run request",["No pilot cannon!",format ["wait for %1 sec",-(round _cooldown)]] select (_cooldown < 0)] select (count _trts == 0 or _cooldown <0),
          [4],
          "",
          -5,
          [[
            "expression","GUNRUNCAS = true; [] spawn MGI_CAS; player setVariable ['BIS_SUPP_ammoType', 0]"
          ]],
          "1",
          ["1","0"] select (count _trts == 0 or _cooldown < 0),
          "\A3\ui_f\data\IGUI\Cfg\WeaponCursors\cannon_gs.paa"
        ]
      ];
      uiSleep 0.1;
      showCommandingMenu "#USER:BIS_SUPP_commMenu";
      waituntil {uiSleep 0.2; isnull (player getVariable "BIS_SUPP_selectedProvider")};
    };
  };
};

 

Seems to be short?

It took me a lot of hours to find this solution. Feel free to test, comment, ask for some implementation.

Pierre

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Interesting solution, however I personally hate using the module init field, or any init field for that matter. Very hard to edit existing lines.

Share this post


Link to post
Share on other sites

True, it would be easy to just name the module and put that code into a script file with minimal changes. Or create the module dynamically in the script. Or have an editor module call the script in a script file. Pierre already did the hard part.

Share this post


Link to post
Share on other sites

The aim, here, is to add a gun "run request line" in the selected aircraft from 0-8 menu.

 

For course it's easier to addAction for your own CAS but you will have the same difficulty about selecting canon and spitting shells on any position on the map.

I'm still fond of better solution for better accuracy.

 

Corrected right now, the selection of aircraft with pilot's canon. The Gryphon was absent. Should better work in MP also as I discovered the need to remoteExec bis_fnc_fire.

Share this post


Link to post
Share on other sites

Will the aircraft still have the option to drop bombs, or do both a gun run and drop bombs.?

Share this post


Link to post
Share on other sites
7 minutes ago, Jnr4817 said:

Will the aircraft still have the option to drop bombs, or do both a gun run and drop bombs.?

The classic calls for unguided or guided are not changed. I just added a line for cannon run. And... not, both wasn't on my mind. But the pilot shifts lately in red combat mode (intended), so he can drop some extra bombs sometimes on enemies after the run. If you want both, you can remove the _pilot setcombatmode "blue" line (16th) and test like this.

 

  • Like 1

Share this post


Link to post
Share on other sites

WIll try.

 

Would using _pilot setskill 1 or _veh setskill 1

 

be of any help to improve the AI ability to aim or hit the target with the gun run?

 

Thanks

Reed

Share this post


Link to post
Share on other sites

added a condition to avoid some extra line in menu of the other supports.

Share this post


Link to post
Share on other sites

After a gun run is complete, is the cooldown set to 60 seconds before another can be called?

 

Once the gun run is complete on the target or area you called, does the aircraft fly around for a set time and look for additional targets?

 

Reed

Share this post


Link to post
Share on other sites

Cooldown is set to 120 sec.

While gunning the pilot is set to combat RED and stays RED until:

-  further GUN RUN (real CAS). That means he stays RED returning back to home (module position). Place this module out of the map.

- deletion (virtual CAS)

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

×