Split checkammo function

This commit is contained in:
Nicolás Badano 2015-03-06 01:32:47 -03:00
parent 342b3c3a4c
commit 7b4487e8fc
5 changed files with 118 additions and 88 deletions

View File

@ -14,7 +14,7 @@ class Extended_PostInit_EventHandlers {
class Extended_Take_EventHandlers {
class CAManBase {
class ACE_AmmoIndicatorReload {
clientTake = QUOTE(if (_this select 0 == ACE_player && {(_this select 1) in [ARR_3(uniformContainer (_this select 0), vestContainer (_this select 0), backpackContainer (_this select 0))]} && {_this select 2 == currentMagazine (_this select 0)}) then {[ARR_3(_this select 0, vehicle (_this select 0), true)] call FUNC(checkAmmo)};);
clientTake = QUOTE(if (_this select 0 == ACE_player && {(_this select 1) in [ARR_3(uniformContainer (_this select 0), vestContainer (_this select 0), backpackContainer (_this select 0))]} && {_this select 2 == currentMagazine (_this select 0)}) then {[ARR_2(_this select 0, vehicle (_this select 0))] call FUNC(displayAmmo)};);
};
};
};

View File

@ -15,7 +15,7 @@ if !(hasInterface) exitWith {};
{(vehicle ACE_player) isKindOf 'StaticWeapon'}) exitWith {false};
// Statement
[ACE_player, vehicle ACE_player, false] call FUNC(checkAmmo);
[ACE_player] call FUNC(checkAmmo);
true
},
[19, [false, true, false]],

View File

@ -4,6 +4,7 @@ ADDON = false;
PREP(canLinkBelt);
PREP(checkAmmo);
PREP(displayAmmo);
PREP(startLinkingBelt);
ADDON = true;

View File

@ -1,12 +1,10 @@
/*
* Author: commy2
*
* Author: commy2 and CAA-Picard
* Count the ammo of the currently loaded magazine or count rifle grenades. Play animation and display message.
*
* Argument:
* 0: The player (Object)
* 1: The vehicle (Object)
* 2: Skip the animation? Used after reloading (Bool)
* 0: Player <OBJECT>
* 1: Target. Optional, if not suplied the player counts his personal or static weapon ammo <OBJECT>
*
* Return value:
* Nothing
@ -15,87 +13,24 @@
#define COUNT_BARS 12
private ["_unit", "_vehicle"];
EXPLODE_1_PVT(_this,_unit);
_unit = _this select 0;
_vehicle = _this select 1;
private ["_target"];
_target = vehicle _unit;
if (_unit != _vehicle && !(_vehicle isKindOf "StaticWeapon")) then {
_vehicle = _unit;
if (count _this > 1) then {
_target = _this select 1;
} else {
// If the unit is on foot, count it's own ammo
if (_unit == _target) exitWith {};
// If it's mounted on a movile weapon, count it's own ammo
if !(_target isKindOf "StaticWeapon") then {
_target = _unit;
};
};
[_vehicle, currentWeapon _vehicle, currentMuzzle _vehicle, currentMagazine _vehicle, _this select 2] spawn {
_vehicle = _this select 0;
_weapon = _this select 1;
_muzzle = _this select 2;
_magazine = _this select 3;
_skipDelay = _this select 4;
_unit playActionNow "Gear";
if (currentWeapon _vehicle == "") exitWith {};
if (typeName _muzzle != "STRING") then {_muzzle = _weapon};
_showNumber = false;
_ammo = 0;
_maxRounds = 1;
_count = 0;
// not grenade launcher
if (_muzzle == _weapon) then {
_maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count") max 1;
_ammo = _vehicle ammo _weapon;
if (_maxRounds >= COUNT_BARS) then {
_count = round (COUNT_BARS * _ammo / _maxRounds);
if (_ammo > 0) then {_count = _count max 1};
if (_ammo < _maxRounds) then {_count = _count min (COUNT_BARS - 1)};
} else {
_count = _ammo;
};
// grenade launcher
} else {
_showNumber = true;
_count = if (_magazine != "") then {
{_x == _magazine} count (magazines _vehicle + [_magazine])
} else {
{_x in getArray (configFile >> "CfgWeapons" >> _weapon >> _muzzle >> "Magazines")} count magazines _vehicle
};
};
if !(_skipDelay) then {
_vehicle playActionNow "Gear";
sleep 1
};
_text = if (_showNumber) then {
parseText format ["<t align='center' >%1x</t>", _count]
} else {
_color = [
2 * (1 - _ammo / _maxRounds) min 1,
2 * _ammo / _maxRounds min 1,
00
];
_string = "";
for "_a" from 1 to _count do {
_string = _string + "|";
};
_text = [_string, _color] call EFUNC(common,stringToColoredText);
_string = "";
for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do {
_string = _string + "|";
};
composeText [
_text,
[_string, [0.5, 0.5, 0.5]] call EFUNC(common,stringToColoredText)
]
};
_picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
[_text, _picture] call EFUNC(common,displayTextPicture);
};
[FUNC(displayAmmo), [_target], 1, 0.1] call EFUNC(common,waitAndExecute);

View File

@ -0,0 +1,94 @@
/*
* Author: commy2 and CAA-Picard
* Display the ammo of the currently loaded magazine of the target or count rifle grenades.
*
* Argument:
* 0: Target <OBJECT>
*
* Return value:
* Nothing
*/
#include "script_component.hpp"
#define COUNT_BARS 12
EXPLODE_1_PVT(_this,_target);
private ["_weapon","_muzzle","_magazine","_showNumber","_ammo","_maxRounds","_count","_text","_color","_picture"];
_weapon = currentWeapon _target;
_muzzle = currentMuzzle _target;
_magazine = currentMagazine _target;
// currentWeapon returns "" for static weapons before they are shot once
if (_target isKindOf "StaticWeapon") then {
if (_weapon == "") then {
if (count (weapons _target) == 1) then {
_weapon = (weapons _target) select 0;
_muzzle = _weapon;
};
};
};
if (_weapon == "") exitWith {};
if (typeName _muzzle != "STRING") then {_muzzle = _weapon};
_showNumber = false;
_ammo = 0;
_maxRounds = 1;
_count = 0;
// not grenade launcher
if (_muzzle == _weapon) then {
_maxRounds = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count") max 1;
_ammo = _target ammo _weapon;
if (_maxRounds >= COUNT_BARS) then {
_count = round (COUNT_BARS * _ammo / _maxRounds);
if (_ammo > 0) then {_count = _count max 1};
if (_ammo < _maxRounds) then {_count = _count min (COUNT_BARS - 1)};
} else {
_count = _ammo;
};
// grenade launcher
} else {
_showNumber = true;
_count = if (_magazine != "") then {
{_x == _magazine} count (magazines _target + [_magazine])
} else {
{_x in getArray (configFile >> "CfgWeapons" >> _weapon >> _muzzle >> "Magazines")} count magazines _target
};
};
_text = if (_showNumber) then {
parseText format ["<t align='center' >%1x</t>", _count]
} else {
_color = [
2 * (1 - _ammo / _maxRounds) min 1,
2 * _ammo / _maxRounds min 1,
00
];
_string = "";
for "_a" from 1 to _count do {
_string = _string + "|";
};
_text = [_string, _color] call EFUNC(common,stringToColoredText);
_string = "";
for "_a" from (_count + 1) to (_maxRounds min COUNT_BARS) do {
_string = _string + "|";
};
composeText [
_text,
[_string, [0.5, 0.5, 0.5]] call EFUNC(common,stringToColoredText)
]
};
_picture = getText (configFile >> "CfgMagazines" >> _magazine >> "picture");
[_text, _picture] call EFUNC(common,displayTextPicture);