mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Split checkammo function
This commit is contained in:
parent
342b3c3a4c
commit
7b4487e8fc
@ -14,7 +14,7 @@ class Extended_PostInit_EventHandlers {
|
|||||||
class Extended_Take_EventHandlers {
|
class Extended_Take_EventHandlers {
|
||||||
class CAManBase {
|
class CAManBase {
|
||||||
class ACE_AmmoIndicatorReload {
|
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)};);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@ if !(hasInterface) exitWith {};
|
|||||||
{(vehicle ACE_player) isKindOf 'StaticWeapon'}) exitWith {false};
|
{(vehicle ACE_player) isKindOf 'StaticWeapon'}) exitWith {false};
|
||||||
|
|
||||||
// Statement
|
// Statement
|
||||||
[ACE_player, vehicle ACE_player, false] call FUNC(checkAmmo);
|
[ACE_player] call FUNC(checkAmmo);
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
[19, [false, true, false]],
|
[19, [false, true, false]],
|
||||||
|
@ -4,6 +4,7 @@ ADDON = false;
|
|||||||
|
|
||||||
PREP(canLinkBelt);
|
PREP(canLinkBelt);
|
||||||
PREP(checkAmmo);
|
PREP(checkAmmo);
|
||||||
|
PREP(displayAmmo);
|
||||||
PREP(startLinkingBelt);
|
PREP(startLinkingBelt);
|
||||||
|
|
||||||
ADDON = true;
|
ADDON = true;
|
||||||
|
@ -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.
|
* Count the ammo of the currently loaded magazine or count rifle grenades. Play animation and display message.
|
||||||
*
|
*
|
||||||
* Argument:
|
* Argument:
|
||||||
* 0: The player (Object)
|
* 0: Player <OBJECT>
|
||||||
* 1: The vehicle (Object)
|
* 1: Target. Optional, if not suplied the player counts his personal or static weapon ammo <OBJECT>
|
||||||
* 2: Skip the animation? Used after reloading (Bool)
|
|
||||||
*
|
*
|
||||||
* Return value:
|
* Return value:
|
||||||
* Nothing
|
* Nothing
|
||||||
@ -15,87 +13,24 @@
|
|||||||
|
|
||||||
#define COUNT_BARS 12
|
#define COUNT_BARS 12
|
||||||
|
|
||||||
private ["_unit", "_vehicle"];
|
EXPLODE_1_PVT(_this,_unit);
|
||||||
|
|
||||||
_unit = _this select 0;
|
private ["_target"];
|
||||||
_vehicle = _this select 1;
|
_target = vehicle _unit;
|
||||||
|
|
||||||
if (_unit != _vehicle && !(_vehicle isKindOf "StaticWeapon")) then {
|
if (count _this > 1) then {
|
||||||
_vehicle = _unit;
|
_target = _this select 1;
|
||||||
};
|
|
||||||
|
|
||||||
[_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;
|
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
_count = _ammo;
|
|
||||||
};
|
|
||||||
|
|
||||||
// grenade launcher
|
// If the unit is on foot, count it's own ammo
|
||||||
} else {
|
if (_unit == _target) exitWith {};
|
||||||
_showNumber = true;
|
|
||||||
|
|
||||||
_count = if (_magazine != "") then {
|
// If it's mounted on a movile weapon, count it's own ammo
|
||||||
{_x == _magazine} count (magazines _vehicle + [_magazine])
|
if !(_target isKindOf "StaticWeapon") then {
|
||||||
} else {
|
_target = _unit;
|
||||||
{_x in getArray (configFile >> "CfgWeapons" >> _weapon >> _muzzle >> "Magazines")} count magazines _vehicle
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if !(_skipDelay) then {
|
_unit playActionNow "Gear";
|
||||||
_vehicle playActionNow "Gear";
|
|
||||||
sleep 1
|
|
||||||
};
|
|
||||||
|
|
||||||
_text = if (_showNumber) then {
|
[FUNC(displayAmmo), [_target], 1, 0.1] call EFUNC(common,waitAndExecute);
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
94
addons/reload/functions/fnc_displayAmmo.sqf
Normal file
94
addons/reload/functions/fnc_displayAmmo.sqf
Normal 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);
|
Loading…
Reference in New Issue
Block a user