2015-03-24 04:18:00 +00:00
|
|
|
// by esteldunedain
|
2015-01-18 20:05:32 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
if !(hasInterface) exitWith {};
|
|
|
|
|
|
|
|
// Add keybinds
|
2015-03-05 07:32:26 +00:00
|
|
|
["ACE3", QGVAR(checkAmmo), localize "STR_ACE_Reload_checkAmmo",
|
|
|
|
{
|
|
|
|
// Conditions: canInteract
|
2015-03-20 22:55:39 +00:00
|
|
|
if !([ACE_player, objNull, []] call EFUNC(common,canInteractWith)) exitWith {false};
|
2015-03-05 07:32:26 +00:00
|
|
|
// Conditions: specific
|
|
|
|
if !([ACE_player] call EFUNC(common,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-03-05 07:32:26 +00:00
|
|
|
[19, [false, true, false]], false] call cba_fnc_addKeybind;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Listen for attempts to link ammo
|
|
|
|
["linkedAmmo", {
|
|
|
|
EXPLODE_3_PVT(_this,_receiver,_giver,_magazine);
|
|
|
|
diag_log "linkedAmmo";
|
|
|
|
diag_log _this;
|
|
|
|
|
|
|
|
private ["_magazineCfg","_magazineType"];
|
|
|
|
_magazineType = currentMagazine _receiver;
|
|
|
|
_magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
|
|
|
|
|
|
|
|
// Return the magazine if it's the wrong type
|
|
|
|
if (_magazineType != (_magazine select 0)) exitWith {
|
|
|
|
["returnedAmmo", [_giver], [_giver,_receiver,_magazine]] call EFUNC(common,targetEvent);
|
|
|
|
};
|
|
|
|
|
|
|
|
private ["_ammoCount","_ammoMissing","_ammoAdded","_ammoRemaining"];
|
|
|
|
_ammoCount = _receiver ammo currentWeapon _receiver;
|
|
|
|
_ammoMissing = getNumber (_magazineCfg >> "count") - _ammoCount;
|
|
|
|
|
|
|
|
// Return the magazine if the belt is full or empty
|
|
|
|
if ((_ammoCount == 0) || _ammoMissing == 0) exitWith {
|
|
|
|
["returnedAmmo", [_giver], [_giver,_receiver,_magazine]] call EFUNC(common,targetEvent);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add the ammo
|
|
|
|
_ammoAdded = _ammoMissing min (_magazine select 1);
|
|
|
|
_receiver setAmmo [currentWeapon _receiver, _ammoCount + _ammoAdded];
|
|
|
|
|
|
|
|
if ((_magazine select 1) - _ammoAdded > 0) then {
|
|
|
|
["returnedAmmo", [_giver], [_giver,_receiver,[_magazineType,(_magazine select 1) - _ammoAdded]]] call EFUNC(common,targetEvent);
|
|
|
|
};
|
|
|
|
|
|
|
|
}] call EFUNC(common,addEventhandler);
|
|
|
|
|
|
|
|
|
|
|
|
// Listen for returned magazines
|
|
|
|
["returnedAmmo", {
|
|
|
|
EXPLODE_3_PVT(_this,_receiver,_giver,_magazine);
|
|
|
|
diag_log "returnedAmmo";
|
|
|
|
diag_log _this;
|
|
|
|
|
|
|
|
_receiver addMagazine _magazine;
|
|
|
|
}] call EFUNC(common,addEventhandler);
|