From 122cb8b96c542e795df8a9a5a3221d707c1a694e Mon Sep 17 00:00:00 2001 From: "DESKTOP-UH65DCE\\MusTanG" Date: Sat, 23 Sep 2017 20:58:48 -0500 Subject: [PATCH] Gunner and Driver Turrets Reload and remove mags from gunner and driver turrets. Will expand for more slots --- .../EPOCH_vehicle_checkTurretAmmo.sqf | 39 +++++++++++++++++++ .../EPOCH_vehicle_removeTurretAmmo.sqf | 30 ++++++++++++++ .../CfgActionMenu/CfgActionMenu_core.hpp | 16 ++++++++ .../CfgActionMenu/CfgActionMenu_self.hpp | 28 +++++++++++++ .../Configs/CfgClientFunctions.hpp | 2 + 5 files changed, 115 insertions(+) create mode 100644 Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf create mode 100644 Sources/epoch_code/compile/vehicles/EPOCH_vehicle_removeTurretAmmo.sqf diff --git a/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf b/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf new file mode 100644 index 00000000..27aa764d --- /dev/null +++ b/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf @@ -0,0 +1,39 @@ +/* + Author: DirtySanchez - ported from DonkeyPunch eXpoch http://DonkeyPunch.INFO + + Contributors: + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf +*/ +params["_weaponTurret", "_turretPath"]; + +if(isNil {_weaponTurret})exitWith{diag_log "[EpochDebug] checkTurretAmmo _weaponTurret was nil"}; + +if(isNil {_turretPath})exitWith{diag_log "[EpochDebug] checkTurretAmmo _turretPath was nil"}; + +private _ammoCount = 0; +private _ammoTurret = getArray(configFile >> "CfgWeapons" >> _weaponTurret >> "magazines"); +private _items = magazines player; +private _availAmmo = _items arrayIntersect _ammoTurret; +if (count _availAmmo == 0) then +{ + [format["You need a can of %1 or any of its variants",_ammoTurret select 0],5] call Epoch_message; +} +else +{ + private _ammo = _availAmmo select 0; + private _magazinesAmmoFull = magazinesAmmoFull player; + { + if((_x select 0) isEqualTo _ammo) then { + _ammoCount = _x select 1; + _magazinesAmmoFull = []; + }; + }forEach _magazinesAmmoFull; + [format["You have added 1 can of %1 with %2 rounds",_ammo,_ammoCount],5] call Epoch_message; + vehicle player addMagazineTurret [_ammo,_turretPath,_ammoCount]; + player removeMagazine _ammo; +}; \ No newline at end of file diff --git a/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_removeTurretAmmo.sqf b/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_removeTurretAmmo.sqf new file mode 100644 index 00000000..f8883c25 --- /dev/null +++ b/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_removeTurretAmmo.sqf @@ -0,0 +1,30 @@ +/* + + Author: DirtySanchez - ported from DonkeyPunch eXpoch http://DonkeyPunch.INFO + + Contributors: + + Licence: + Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike + + Github: + https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_removeTurretAmmo.sqf +*/ +params["_weaponTurret", "_turretPath"]; + +if(isNil {_weaponTurret})exitWith{diag_log "[EpochDebug] removeTurretAmmo _weaponTurret was nil"}; + +if(isNil {_turretPath})exitWith{diag_log "[EpochDebug] removeTurretAmmo _turretPath was nil"}; + +private _magsTurretDetails = magazinesAmmo vehicle player; +if(_magsTurretDetails isEqualTo [])exitWith{ + private _nameTurret = getText(configFile >> "CfgWeapons" >> _weaponTurret >> "displayName"); + [format["The %1 does not have any ammo",_nameTurret],5] call Epoch_message; +}; + +private _magsTurret = (_magsTurretDetails select 0) select 0; +private _magAmmo = (_magsTurretDetails select 0) select 1; +[format["You have removed 1 can of %1 with %2 rounds",_magsTurret, _magAmmo],5] call Epoch_message; +player addMagazine [_magsTurret,_magAmmo]; +vehicle player removeMagazineTurret [_magsTurret,_turretPath]; +reload vehicle player; \ No newline at end of file diff --git a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_core.hpp b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_core.hpp index 44ea4652..e5154f9a 100644 --- a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_core.hpp +++ b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_core.hpp @@ -32,6 +32,22 @@ class CfgActionMenu dyna_canAcceptTrade = "if (!(isNull EPOCH_pendingP2ptradeTarget) && alive EPOCH_pendingP2ptradeTarget) then {((EPOCH_pendingP2ptradeTarget isKindOf 'Man') && (dyna_cursorTarget isEqualTo EPOCH_pendingP2ptradeTarget))} else {false}"; dyna_locked = "locked dyna_cursorTarget in [2,3]"; dyna_lockedInVehicle = "locked vehicle player in [2,3]"; + + dyna_inDriver = "driver vehicle player == player"; + dyna_inTurret = "gunner vehicle player == player"; + dyna_vehicleRoleEmpty = "((assignedVehicleRole player) isEqualTo [])"; + + dyna_blockTurrets = "['Horn', 'MiniCarHorn', 'SportCarHorn', 'TruckHorn2', 'TruckHorn', 'BikeHorn', 'CarHorn', 'TruckHorn3']"; + + dyna_weaponsTurret = "if!(dyna_vehicleRoleEmpty)then{(vehicle player) weaponsTurret ((assignedVehicleRole player) select 1)}else{nil}"; + dyna_weaponsTurretPath = "if(!isNil {dyna_weaponsTurret})then{((assignedVehicleRole player) select 1)}else{nil}"; + dyna_weaponsTurretMags = "if(!isNil {dyna_weaponsTurret})then{vehicle player magazinesTurret dyna_weaponsTurretPath}else{[]}"; + + dyna_driverTurret = "if(dyna_inDriver)then{vehicle player weaponsTurret[-1]}else{nil}"; + dyna_driverTurretMags = "if(!isNil {dyna_driverTurret})then{vehicle player magazinesTurret[-1]}else{[]}"; + + dyna_isGunning = "if(dyna_inVehicle && dyna_inTurret && !dyna_inDriver)then{(!isNil {dyna_weaponsTurret})}else{false}"; + dyna_isDriving = "if(dyna_inVehicle && dyna_inDriver)then{(!isNil {dyna_driverTurret})}else{false}"; }; class self diff --git a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp index 6197635c..04609651 100644 --- a/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp +++ b/Sources/epoch_config/Configs/CfgActionMenu/CfgActionMenu_self.hpp @@ -163,3 +163,31 @@ class ServicePoint tooltipcode = "Ignatz_Rearm2 select 0"; }; }; +class veh_gunnerRearm +{ + condition = "if(dyna_isGunning)then{!((dyna_weaponsTurret select 0) in dyna_blockTurrets)}else{false}"; + action = "[dyna_weaponsTurret select 0, dyna_weaponsTurretPath] call EPOCH_vehicle_checkTurretAmmo"; + icon = "x\addons\a3_epoch_code\Data\UI\buttons\Rearm.paa"; + tooltipcode = "if(!isNil {dyna_weaponsTurret})then{format['Add Mag to %1',getText(configFile >> 'CfgWeapons' >> dyna_weaponsTurret select 0 >> 'displayName')]}else{''}"; +}; +class veh_gunnerRemoveAmmo +{ + condition = "dyna_isGunning && !(dyna_weaponsTurretMags isEqualTo [])"; + action = "[dyna_weaponsTurret select 0, dyna_weaponsTurretPath] call EPOCH_vehicle_removeTurretAmmo"; + icon = "x\addons\a3_epoch_code\Data\UI\buttons\RemoveMag.paa"; + tooltipcode = "if(!isNil {dyna_weaponsTurret})then{format['Remove Mag from %1',getText(configFile >> 'CfgWeapons' >> dyna_weaponsTurret select 0 >> 'displayName')]}else{''}"; +}; +class veh_driverRearm +{ + condition = "if(dyna_isDriving)then{!((dyna_driverTurret select 0) in dyna_blockTurrets)}else{false}"; + action = "[dyna_driverTurret select 0, [-1]] call EPOCH_vehicle_checkTurretAmmo"; + icon = "x\addons\a3_epoch_code\Data\UI\buttons\Rearm.paa"; + tooltipcode = "if(!isNil {dyna_driverTurret})then{format['Add Mag to %1',getText(configFile >> 'CfgWeapons' >> dyna_driverTurret select 0 >> 'displayName')]}else{''}"; +}; +class veh_driverRemoveAmmo +{ + condition = "dyna_isDriving && !(dyna_driverTurretMags isEqualTo [])"; + action = "[dyna_driverTurret select 0, [-1]] call EPOCH_vehicle_removeTurretAmmo"; + icon = "x\addons\a3_epoch_code\Data\UI\buttons\RemoveMag.paa"; + tooltipcode = "if!(dyna_driverTurretMags isEqualTo [])then{format['Remove Mag of %1',dyna_driverTurretMags select 0]}else{''}"; +}; \ No newline at end of file diff --git a/Sources/epoch_config/Configs/CfgClientFunctions.hpp b/Sources/epoch_config/Configs/CfgClientFunctions.hpp index 1d4cdaab..0293173b 100644 --- a/Sources/epoch_config/Configs/CfgClientFunctions.hpp +++ b/Sources/epoch_config/Configs/CfgClientFunctions.hpp @@ -157,6 +157,8 @@ class CfgClientFunctions class client_upgradeVehicleCheck {}; class client_VehicleMaintananceCheck {}; class client_VehicleMaintananceDo {}; + class vehicle_checkTurretAmmo {}; + class vehicle_removeTurretAmmo {}; }; class missions {