Epoch/Sources/epoch_code/compile/vehicles/EPOCH_vehicle_checkTurretAmmo.sqf

62 lines
2.5 KiB
Plaintext
Raw Normal View History

/*
Author: DirtySanchez - ported from DonkeyPunch eXpoch http://DonkeyPunch.INFO
2017-10-05 18:59:52 +00:00
Contributors: He-Man
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
*/
2017-10-05 18:59:52 +00:00
private ["_ammoTurret","_availAmmo","_ammo","_magazinesAmmoFull","_readd","_selectedmag","_magAmmoCount","_return","_AllFlares","_removeveh","_readdveh"];
params["_vehicle","_weaponTurret", "_turretPath"];
2017-10-05 18:59:52 +00:00
// Fix for not reloadable Flares
if ((["flare", tolower _weaponTurret] call BIS_fnc_inString) || (["smoke", tolower _weaponTurret] call BIS_fnc_inString)) then {
_AllFlares = ((magazinesAllTurrets _vehicle) select {_x param [1] isequalto _turretPath}) select {(["flare", tolower (_x param [0])] call BIS_fnc_inString) || (["smoke", tolower (_x param [0])] call BIS_fnc_inString)};
_removeveh = [];
_readdveh = [];
{
_removeveh pushbackunique (_x select 0);
if !((_x select 2) isequalto 0) then {
_readdveh pushback _x;
};
} foreach _AllFlares;
{
_vehicle removeMagazinesTurret [_x,_turretPath];
} foreach _removeveh;
{
_vehicle addMagazineTurret [_x select 0, _turretPath, _x select 2];
} foreach _readdveh;
};
2017-10-05 18:59:52 +00:00
_ammoTurret = getArray(configFile >> "CfgWeapons" >> _weaponTurret >> "magazines");
_availAmmo = (magazines player) arrayIntersect _ammoTurret;
if (count _availAmmo == 0) then {
2017-10-15 16:19:41 +00:00
[format["You need a can of %1 or any of its variants",getText (configFile >> 'CfgMagazines' >> (_ammoTurret select 0) >> 'displayName')],5] call Epoch_message;
}
2017-10-05 18:59:52 +00:00
else {
_ammo = _availAmmo select 0;
_magazinesAmmoFull = magazinesAmmoFull player;
_readd = [];
{
if((_x select 0) isEqualTo _ammo) then {
2017-10-05 18:59:52 +00:00
_readd pushback _x;
};
2017-10-05 18:59:52 +00:00
} forEach _magazinesAmmoFull;
_selectedmag = _readd deleteat 0;
_magAmmoCount = _selectedmag select 1;
_vehicle addMagazineTurret [_ammo,_turretPath,_magAmmoCount];
player removeMagazines _ammo;
{
_return = _x call EPOCH_fnc_addMagazineOverflow;
} foreach _readd;
_vehicle call EPOCH_interact;
if !(EPOCH_arr_interactedObjs isEqualTo[]) then {
[EPOCH_arr_interactedObjs] remoteExec['EPOCH_server_save_vehicles', 2];
EPOCH_arr_interactedObjs = [];
};
2017-10-05 18:59:52 +00:00
[format["Added 1 can %1 with %2 rounds to %3",getText (configFile >> 'CfgMagazines' >> _ammo >> 'displayName'),_magAmmoCount,getText (configFile >> 'CfgWeapons' >> _weaponTurret >> 'displayName')],5] call Epoch_message;
};