pierremgi 4853 Posted January 26, 2018 MGI GUN RUN Last update: 01/05/2020 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 career). - 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: MGI_CAS_MODULE_1 = this; MGI_CAS = compileFinal " if !(GUNRUNCAS) exitWith {}; private _isVirtual = ({_x isKindOf 'air'} count synchronizedObjects MGI_CAS_MODULE_1 ==0); private _pilot = player getVariable 'BIS_SUPP_selectedProvider'; private _veh = vehicle _pilot; private _home = getPos MGI_CAS_MODULE_1; private _trts = (_veh WeaponsTurret [-1]) select { getText (configfile >> 'CfgWeapons' >> _x >> 'nameSound') == 'cannon'}; waitUntil {!isNil {_pilot getVariable 'BIS_SUPP_requester'} && {!isNull (_pilot getVariable 'BIS_SUPP_requester')}}; private _requester = _pilot getVariable 'BIS_SUPP_requester'; 'Gun run requested' remoteExec ['hint',_requester]; waitUntil {!isnil {_pilot getVariable 'BIS_SUPP_supportRunCoords'}}; private _coords = _pilot getVariable 'BIS_SUPP_supportRunCoords'; private _alt = getTerrainHeightASL _coords; private _limit = [40,90] select (_veh distance2D _coords < 2500); _pilot setCombatMode 'BLUE'; _veh flyInHeightASL [_alt +500,_alt +500,_alt +500]; waitUntil {_veh distance2D _coords < 2000}; if (!isNil 'BIS_SUPP_laserTGT') then {deleteVehicle BIS_SUPP_laserTGT; BIS_SUPP_laserTGT = nil}; private _timer = diag_tickTime; _veh flyInHeightASL [_alt +100,_alt +100,_alt +100]; private _resultOK = false; 'In sight' remoteExec ['hint',_requester]; private _typeForIndep = (WEST getFriend RESISTANCE >0.6); private _tgttype = ['laserTargetE','laserTargetW'] select (side _veh == WEST or (side _veh == RESISTANCE && _typeForIndep)); private _tgt = createVehicle [_tgttype,_coords,[],0,'none']; if (count _trts > 0) then { _trt = _trts select 0; private _mags = (getArray (configfile >> 'CfgWeapons' >> _trt >> 'magazines')) arrayIntersect (_veh magazinesTurret [-1]); comment ""private _cnt = getNumber (configFile >> 'cfgMagazines' >> _mags select 0 >> 'count')""; _pilot setCombatMode 'RED'; _pilot reveal [_tgt,4]; _veh selectWeaponTurret [_trt,[-1]]; private _cnt =_veh magazineTurretAmmo [_veh currentMagazineTurret [-1],[-1]]; while {diag_tickTime < _timer + _limit} do { _tgt setPosASL (getPosASL _tgt vectorAdd [0,0,(0.18 * (_veh distance2D _tgt)) -270]); _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 120; deleteVehicle _veh}; "; 0 = MGI_CAS_MODULE_1 spawn { while {true} do { GUNRUNCAS = false; waitUntil {uiSleep 0.2; !isnil {player getVariable "BIS_SUPP_selectedProvider"}}; waitUntil {!isNil {player getVariable "BIS_SUPP_request"} && {(player getVariable "BIS_SUPP_request") #0 == "CAS_Bombing"} && {!isnull (player getVariable "BIS_SUPP_selectedProvider")}}; private _pilot = player getVariable "BIS_SUPP_selectedProvider"; private _veh = vehicle _pilot; private _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; isNil {player getVariable "BIS_SUPP_selectedProvider"} or {!isNil {player getVariable "BIS_SUPP_selectedProvider"} && 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 2 1 Share this post Link to post Share on other sites
Midnighters 152 Posted January 26, 2018 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
AZCoder 921 Posted January 26, 2018 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
pierremgi 4853 Posted January 27, 2018 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
Jnr4817 215 Posted January 27, 2018 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
pierremgi 4853 Posted January 27, 2018 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. 1 Share this post Link to post Share on other sites
Jnr4817 215 Posted January 28, 2018 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
pierremgi 4853 Posted February 1, 2018 added a condition to avoid some extra line in menu of the other supports. Share this post Link to post Share on other sites
Jnr4817 215 Posted February 9, 2018 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
pierremgi 4853 Posted February 9, 2018 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
pierremgi 4853 Posted February 19, 2018 Added a slope for gun run. Better accuracy. 1 Share this post Link to post Share on other sites
pierremgi 4853 Posted May 1, 2020 Corrected this (old) script! Feedback appreciated. (if the gun run doesn't appear at once in support menu, renew the call). 1 Share this post Link to post Share on other sites
Wiggleroom 0 Posted October 20, 2020 On 5/1/2020 at 5:44 AM, pierremgi said: Corrected this (old) script! Feedback appreciated. (if the gun run doesn't appear at once in support menu, renew the call). Is there any way to call support for a gun run? The script works well but is there anyway you can call it instead of it just happening ? Share this post Link to post Share on other sites
pierremgi 4853 Posted October 20, 2020 3 hours ago, Wiggleroom said: Is there any way to call support for a gun run? The script works well but is there anyway you can call it instead of it just happening ? For a reason I didn't find, this code works now inside virtual CAS module only. I failed to display the "gun run" menu for real CAS module... Share this post Link to post Share on other sites
Wiggleroom 0 Posted October 20, 2020 15 hours ago, pierremgi said: For a reason I didn't find, this code works now inside virtual CAS module only. I failed to display the "gun run" menu for real CAS module... So there’s no way to make gun run support? Is there a way to make it for a bombing run support module but use a script to have it use the cannon instead of bombs? Share this post Link to post Share on other sites
Wiggleroom 0 Posted October 21, 2020 On 5/1/2020 at 5:44 AM, pierremgi said: Corrected this (old) script! Feedback appreciated. (if the gun run doesn't appear at once in suppo 4 hours ago, Wiggleroom said: So there’s no way to make gun run support? Is there a way to make it for a bombing run support module but use a script to have it use the cannon instead of bombs? I tried it in a virtual module but the spawned plane just flies around and doesn’t shoot. 4 hours ago, Wiggleroom said: Share this post Link to post Share on other sites
beno_83au 1369 Posted October 21, 2020 @pierremgi Maybe I'm getting a little confused/lost in translation, but what I made a while back works fine for using the CAS Module: The only code I run to script the execution of the module is: params [ "_position","_direction",["_vehicle","B_Plane_CAS_01_F"],["_type",2], "_logic" ]; _logic = "Logic" createVehicleLocal _position; _logic setDir _direction; _logic setVariable ["vehicle",_vehicle]; _logic setVariable ["type",_type]; [_logic,nil,true] call BIS_fnc_moduleCAS; deleteVehicle _logic; So maybe you could make use of that in yours? Share this post Link to post Share on other sites