ACE3/addons/reloadlaunchers/functions/fnc_load.sqf

88 lines
3.0 KiB
Plaintext
Raw Permalink Normal View History

#include "..\script_component.hpp"
2015-03-18 19:17:53 +00:00
/*
* Author: commy2, johnb43, drofseh
* Start reloading a launcher, reload started by the unit who has the missile.
2015-03-18 19:17:53 +00:00
*
2016-06-18 09:50:41 +00:00
* Arguments:
* 0: Unit executing the reload <OBJECT>
* 1: Unit equipped with the launcher <OBJECT>
* 2: Launcher name <STRING>
* 3: Missile name <STRING>
2015-03-18 19:17:53 +00:00
*
2016-06-18 09:50:41 +00:00
* Return Value:
* None
*
* Example:
* [player, cursorTarget, "launch_RPG32_F", "RPG32_F"] call ace_reloadlaunchers_fnc_load
2016-04-28 03:58:47 +00:00
*
* Public: No
2015-03-18 19:17:53 +00:00
*/
2016-04-28 03:58:47 +00:00
params ["_unit", "_target", "_weapon", "_magazine"];
TRACE_4("params",_unit,_target,_weapon,_magazine);
2015-03-18 19:17:53 +00:00
private _config = configFile >> "CfgWeapons" >> _weapon >> QGVAR(buddyReloadTime);
private _reloadTime = if (isNumber _config) then {
getNumber _config
} else {
getNumber (configFile >> "CfgWeapons" >> _weapon >> "magazineReloadTime") min 2.5
};
2015-03-18 19:17:53 +00:00
// Play animation
2015-03-22 13:05:31 +00:00
[_unit] call EFUNC(common,goKneeling);
2015-03-18 19:17:53 +00:00
// Notify unit that is being reloaded that reload has been started
[QGVAR(reloadStarted), [_unit, _target], _target] call CBA_fnc_targetEvent;
// Show progress bar
private _onSuccess = {
(_this select 0) params ["_unit", "_target", "_weapon", "_magazine"];
// Check if the unit has any of the same magazines and calculate max ammo
private _maxAmmo = 0;
{
_maxAmmo = _maxAmmo max (_x select 1);
} forEach (magazinesAmmo _unit select {(_x select 0) == _magazine});
// Check if the launcher can still be loaded; If possible, then try to remove magazine
if !(_maxAmmo > 0 && {[_unit, _target, _weapon, _magazine] call FUNC(canLoad)} && {[_unit, _magazine, _maxAmmo] call EFUNC(common,removeSpecificMagazine)}) exitWith {
// Notify unit that was being reloaded that reload has been stopped
[QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent;
// Notify reloading unit about failure
if (GVAR(displayStatusText)) then {
[LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured);
};
};
2015-03-22 13:05:31 +00:00
// Reload target's launcher
[QGVAR(reloadLauncher), [_unit, _target, _weapon, _magazine, _maxAmmo], _target] call CBA_fnc_targetEvent;
// Notify reloading unit about success
if (GVAR(displayStatusText)) then {
[LSTRING(LauncherLoaded)] call EFUNC(common,displayTextStructured);
};
2015-03-22 13:05:31 +00:00
};
private _onFailure = {
(_this select 0) params ["_unit", "_target"];
// Notify unit that was being reloaded that reload has been stopped
[QGVAR(reloadAborted), [_unit, _target], _target] call CBA_fnc_targetEvent;
// Notify reloading unit about failure
if (GVAR(displayStatusText)) then {
[LSTRING(LauncherNotLoaded)] call EFUNC(common,displayTextStructured);
};
2015-03-22 13:05:31 +00:00
};
private _condition = {
(_this select 0) params ["_unit", "_target"];
(_this select 0) call FUNC(canLoad) && {_unit distance _target < 4}
2015-03-22 13:05:31 +00:00
};
[_reloadTime, [_unit, _target, _weapon, _magazine], _onSuccess, _onFailure, LLSTRING(LoadingLauncher), _condition, ["isNotInside", "isNotSwimming"]] call EFUNC(common,progressBar);