Linkingbelt refactoring (#5213)

* Linking belt refatoring

startLinking belt now uses canLinkBelt so if condition needs to be changed then you can do it on one position.

* Fixed requested change

Fixed requested change

* simplified it even more

canLinkBelt now returns a value over 0 if success and -1 if something is not right.

* Fixed bug where if error we would not exit

Fixed bug where if error we would not exit

* changed name on canLinkBelt

Changed name to better reflect the function of the function.

* Author hype

* fixed return value info

fixed return value info

* fix header
This commit is contained in:
Phyma 2017-05-29 20:49:21 +02:00 committed by PabstMirror
parent 3b7a3047cd
commit 95ade30d56
4 changed files with 12 additions and 20 deletions

View File

@ -6,7 +6,7 @@ class CfgVehicles {
class GVAR(LinkBelt) {
displayName = CSTRING(LinkBelt);
distance = 2.0;
condition = QUOTE([ARR_2(_player, _target)] call FUNC(canLinkBelt));
condition = QUOTE(([ARR_2(_player, _target)] call FUNC(getAmmoToLinkBelt)) > 0);
statement = QUOTE([ARR_2(_player, _target)] call FUNC(startLinkingBelt));
};
class GVAR(CheckAmmo) {

View File

@ -1,6 +1,6 @@
PREP(canCheckAmmo);
PREP(canLinkBelt);
PREP(getAmmoToLinkBelt);
PREP(checkAmmo);
PREP(displayAmmo);
PREP(startLinkingBelt);

View File

@ -1,5 +1,5 @@
/*
* Author: esteldunedain
* Author: esteldunedain, phyma
* Check if the target has an MG equiped with belt system that the player can link
*
* Arguments:
@ -7,10 +7,10 @@
* 1: Target <OBJECT>
*
* Return Value:
* Can link belt<BOOL>
* Maximum ammo of magazine (-1 on error) <NUMBER>
*
* Example:
* [player, cursorObject] call ace_reload_fnc_canLinkBelt;
* [player, cursorObject] call ace_reload_fnc_getAmmoToLinkBelt;
*
* Public: No
*/
@ -18,18 +18,18 @@
params ["_player", "_target"];
if (vehicle _target != _target) exitWith {false};
if (vehicle _target != _target) exitWith {-1};
private _magazineType = currentMagazine _target;
private _magazineCfg = configFile >> "CfgMagazines" >> _magazineType;
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {false};
if (getNumber (_magazineCfg >> "ACE_isBelt") == 0) exitWith {-1};
// 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};
if (_ammoCount == 0 || getNumber (_magazineCfg >> "count") - _ammoCount == 0) exitWith {-1};
// Check if the player has any of the same magazines
// Calculate max ammo
@ -39,4 +39,4 @@ private _maxAmmo = 0;
_maxAmmo = _maxAmmo max (_x select 1);
} forEach (magazinesAmmo _player select {_x select 0 == _magazineType});
_maxAmmo > 0
_maxAmmo

View File

@ -17,19 +17,11 @@ if (vehicle _target != _target) exitWith {false};
private _magazineType = currentMagazine _target;
private _canLink = [_player, _target] call FUNC(canLinkBelt);
if ( !_canLink ) exitWith {} ;
private _maxAmmo = [_player, _target] call FUNC(getAmmoToLinkBelt);
// 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 {};
//if _maxAmmo is below 0 we quit
if (_maxAmmo <= 0) exitWith {};
// Condition to call each frame
private _condition = {