ACE3/addons/reload/functions/fnc_startLinkingBelt.sqf
esteldunedain 18f09b9310 Rename events:
- ace_addedHeartRateAdjustment -> ace_heartRateAdjustmentAdded
- ace_cargoAddedByClass -> ace_cargoByClassAdded
- ace_enteredCardiacArrest -> ace_cardiacArrestEntered
- ace_itemAddedToTriageCard -> ace_triageCardItemAdded
- ace_reload_linkedAmmo ->  ace_reload_ammoLinked
- ace_reload_returnedAmmo -> ace_reload_ammoReturned
- ace_treatmentSuccess ->  ace_treatmentSucceded
- ace_common_engineOn -> ace_common_setEngine
- ace_explosives_clientRequestOrientations -> ace_explosives_requestOrientations
- ace_explosives_serverSendOrientations -> ace_explosives_sendOrientations
- ace_interaction_lampTurnOff -> ace_interaction_setLampOff
- ace_interaction_lampTurnOn -> ace_interaction_setLampOn
- ace_overheating_spareBarrelsLoadCoolest -> ace_overheating_loadCoolestSpareBarrel
- ace_overheating_spareBarrelsSendTemperatureHint -> ace_overheating_sendSpareBarrelTemperatureHint
Close #3533
2016-06-24 10:45:13 -03:00

67 lines
2.0 KiB
Plaintext

/*
* Author: esteldunedain
* Start linking the belt
*
* Arguments:
* 0: Player <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* None
*/
#include "script_component.hpp"
params ["_player", "_target"];
if (vehicle _target != _target) exitWith {false};
private _magazineType = currentMagazine _target;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false};
// Check if the ammo is not empty or full
private _ammoCount = _target ammo currentWeapon _target;
// 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
private _maxAmmo = 0;
{
_maxAmmo = _maxAmmo max (_x select 1);
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});
if (_maxAmmo == 0) exitWith {};
// Condition to call each frame
private _condition = {
(_this select 0) params ["_player", "_target"];
([_player, _target, []] call EFUNC(common,canInteractWith)) && ((_player distance _target) < 3) && ((speed _target) < 1)
};
private _onFinish = {
(_this select 0) params ["_player", "_target", "_magazine"];
// Raise event on remote unit
[QGVAR(ammoLinked), [_target, _player, _magazine], [_target]] call CBA_fnc_targetEvent;
};
private _onFailure = {
EXPLODE_3_PVT((_this select 0),_player,_target,_magazine);
[_player, "AmovPknlMstpSrasWrflDnon", 1] call EFUNC(common,doAnimation);
// Add back the magazine with the former ammo count
_player addMagazine _magazine;
};
_player playActionNow "PutDown";
// Remove the magazine with maximum remaining ammo
[_player, _magazineType, _maxAmmo] call EFUNC(common,removeSpecificMagazine);
// Call progress bar
[4, [_player, _target, [_magazineType, _maxAmmo]], _onFinish, _onFailure, (localize LSTRING(LinkingBelt)), _condition] call EFUNC(common,progressBar);