2016-02-20 22:11:50 +00:00
|
|
|
// by esteldunedain
|
2015-01-18 20:05:32 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-09-11 14:58:26 +00:00
|
|
|
if (!hasInterface) exitWith {};
|
2015-01-18 20:05:32 +00:00
|
|
|
|
|
|
|
// Add keybinds
|
2015-05-28 19:59:04 +00:00
|
|
|
["ACE3 Weapons", QGVAR(checkAmmo), localize LSTRING(checkAmmo),
|
2015-03-05 07:32:26 +00:00
|
|
|
{
|
|
|
|
// Conditions: canInteract
|
2016-01-06 21:42:02 +00:00
|
|
|
if !([ACE_player, vehicle ACE_player, ["isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {false};
|
2015-03-05 07:32:26 +00:00
|
|
|
// Conditions: specific
|
2016-02-20 21:41:24 +00:00
|
|
|
if !(ACE_player call CBA_fnc_canUseWeapon || {(vehicle ACE_player) isKindOf "StaticWeapon"}) exitWith {false};
|
2015-01-18 20:05:32 +00:00
|
|
|
|
2015-03-05 07:32:26 +00:00
|
|
|
// Statement
|
2015-03-07 16:32:31 +00:00
|
|
|
[ACE_player] call FUNC(checkAmmo);
|
2015-03-05 07:32:26 +00:00
|
|
|
true
|
|
|
|
},
|
2015-03-05 08:51:24 +00:00
|
|
|
{false},
|
2015-11-30 15:45:20 +00:00
|
|
|
[19, [false, true, false]], false] call CBA_fnc_addKeybind;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
2016-05-24 16:58:27 +00:00
|
|
|
[QGVAR(syncAmmo), {
|
2015-05-12 04:51:42 +00:00
|
|
|
//To propagate the setAmmo change, do it on all clients
|
2016-01-06 21:42:02 +00:00
|
|
|
params ["_unit", "_weapon", "_ammo"];
|
2016-05-24 16:58:27 +00:00
|
|
|
TRACE_3("syncAmmo EH",_unit,_weapon,_ammo);
|
2016-01-06 21:42:02 +00:00
|
|
|
|
2015-05-12 04:51:42 +00:00
|
|
|
_unit setAmmo [_weapon, _ammo];
|
2016-05-22 15:29:05 +00:00
|
|
|
}] call CBA_fnc_addEventHandler;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Listen for attempts to link ammo
|
2016-05-24 18:51:10 +00:00
|
|
|
[QGVAR(linkedAmmo), {
|
2016-01-06 21:42:02 +00:00
|
|
|
params ["_receiver", "_giver", "_magazine"];
|
2015-02-20 05:45:17 +00:00
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _magazineType = currentMagazine _receiver;
|
|
|
|
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Return the magazine if it's the wrong type
|
|
|
|
if (_magazineType != (_magazine select 0)) exitWith {
|
2016-05-24 18:51:10 +00:00
|
|
|
[QGVAR(returnedAmmo), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent;
|
2015-02-20 05:45:17 +00:00
|
|
|
};
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _ammoCount = _receiver ammo currentWeapon _receiver;
|
|
|
|
private _ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Return the magazine if the belt is full or empty
|
|
|
|
if ((_ammoCount == 0) || _ammoMissing == 0) exitWith {
|
2016-05-24 18:51:10 +00:00
|
|
|
[QGVAR(returnedAmmo), [_giver,_receiver,_magazine], [_giver]] call CBA_fnc_targetEvent;
|
2015-02-20 05:45:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add the ammo
|
2016-01-06 21:42:02 +00:00
|
|
|
private _ammoAdded = _ammoMissing min (_magazine select 1);
|
2016-05-24 16:58:27 +00:00
|
|
|
[QGVAR(syncAmmo), [_receiver, currentWeapon _receiver, _ammoCount + _ammoAdded]] call CBA_fnc_globalEvent;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
if ((_magazine select 1) - _ammoAdded > 0) then {
|
2016-05-24 18:51:10 +00:00
|
|
|
[QGVAR(returnedAmmo), [_giver, _receiver, [_magazineType, (_magazine select 1) - _ammoAdded]], [_giver]] call CBA_fnc_targetEvent;
|
2015-02-20 05:45:17 +00:00
|
|
|
};
|
2016-05-22 15:29:05 +00:00
|
|
|
}] call CBA_fnc_addEventHandler;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Listen for returned magazines
|
2016-05-24 18:51:10 +00:00
|
|
|
[QGVAR(returnedAmmo), {
|
2016-01-06 21:42:02 +00:00
|
|
|
params ["_receiver", "", "_magazine"];
|
|
|
|
TRACE_2("returnedAmmo EH",_receiver,_magazine);
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
_receiver addMagazine _magazine;
|
2016-05-22 15:29:05 +00:00
|
|
|
}] call CBA_fnc_addEventHandler;
|