2015-02-20 05:45:17 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: esteldunedain
|
2015-02-20 05:45:17 +00:00
|
|
|
* Start linking the belt
|
|
|
|
*
|
|
|
|
* Argument:
|
|
|
|
* 0: Player <OBJECT>
|
|
|
|
* 1: Target <OBJECT>
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* None
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
params ["_player", "_target"];
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
if (vehicle _target != _target) exitWith {false};
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _magazineType = currentMagazine _target;
|
|
|
|
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
|
|
|
|
|
2015-02-20 05:45:17 +00:00
|
|
|
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false};
|
|
|
|
|
|
|
|
// Check if the ammo is not empty or full
|
2016-01-06 21:42:02 +00:00
|
|
|
private _ammoCount = _target ammo currentWeapon _target;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Exit if the belt is full or empty
|
|
|
|
if ((_ammoCount == 0) || (getNumber (_magazineCfg >> "count") - _ammoCount) == 0) exitWith {false};
|
|
|
|
|
|
|
|
// Check if the player has any of the same same magazines
|
|
|
|
// Calculate max ammo it can link
|
2016-01-06 21:42:02 +00:00
|
|
|
private _maxAmmo = 0;
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
_maxAmmo = _maxAmmo max (_x select 1);
|
2016-02-06 10:58:31 +00:00
|
|
|
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
if (_maxAmmo == 0) exitWith {};
|
|
|
|
|
|
|
|
// Condition to call each frame
|
2016-01-06 21:42:02 +00:00
|
|
|
private _condition = {
|
|
|
|
(_this select 0) params ["_player", "_target"];
|
2015-03-15 12:00:10 +00:00
|
|
|
([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1)
|
2015-02-20 05:45:17 +00:00
|
|
|
};
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _onFinish = {
|
|
|
|
(_this select 0) params ["_player", "_target", "_magazine"];
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Raise event on remote unit
|
2016-05-22 15:29:05 +00:00
|
|
|
["linkedAmmo", [_target, _player, _magazine], [_target]] call CBA_fnc_targetEvent;
|
2015-02-20 05:45:17 +00:00
|
|
|
};
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _onFailure = {
|
2015-02-20 05:45:17 +00:00
|
|
|
EXPLODE_3_PVT((_this select 0),_player,_target,_magazine);
|
2015-04-18 03:40:37 +00:00
|
|
|
[_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Add back the magazine with the former ammo count
|
|
|
|
_player addMagazine _magazine;
|
|
|
|
};
|
|
|
|
|
2015-03-24 03:34:41 +00:00
|
|
|
_player playActionNow "PutDown";
|
2015-02-20 05:45:17 +00:00
|
|
|
|
|
|
|
// Remove the magazine with maximum remaining ammo
|
|
|
|
[_player, _magazineType, _maxAmmo] call EFUNC(common,removeSpecificMagazine);
|
|
|
|
|
|
|
|
// Call progress bar
|
2015-05-28 19:59:04 +00:00
|
|
|
[4, [_player, _target, [_magazineType, _maxAmmo]], _onFinish, _onFailure, (localize LSTRING(LinkingBelt)), _condition] call EFUNC(common,progressBar);
|