mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
CSW - Fix AI reloading from GroundWeaponHolder (#8399)
* fix fnc_ai_handleFired * remove debug messages * use banana instead of FakePrimaryWeapon * switch from dummy item to new weaponholder * use exitWith instead of break
This commit is contained in:
parent
82a8350fb4
commit
a4f24cbe3d
@ -1,7 +1,7 @@
|
||||
#include "script_component.hpp"
|
||||
/*
|
||||
* Author: esteldunedain
|
||||
* Removes a magazine from the unit that has an specific ammo count
|
||||
* Removes a magazine from the unit or object that has a specific ammo count
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
@ -9,7 +9,7 @@
|
||||
* 2: Ammo count <NUMBER>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
* Magazine Removed <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* [bob, "magazine", 5] call ace_common_fnc_removeSpecificMagazine
|
||||
@ -21,62 +21,35 @@ params [["_unit", objNull, [objNull]], ["_magazineType", "", [""]], ["_ammoCount
|
||||
|
||||
private _isRemoved = false;
|
||||
|
||||
// Check uniform
|
||||
private _magazines = magazinesAmmoCargo uniformContainer _unit select {_x select 0 == _magazineType};
|
||||
private _index = _magazines find [_magazineType, _ammoCount];
|
||||
private _fnc_removeMagazine = {
|
||||
params ["_container", "_magArray"];
|
||||
_magArray params ["_magazineType", "_ammoCount"];
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
{
|
||||
_unit removeItemFromUniform (_x select 0);
|
||||
false
|
||||
} count _magazines;
|
||||
private _allMagazines = magazinesAmmoCargo _container;
|
||||
private _specificMagazineIndex = _allMagazines findIf {_x isEqualTo _magArray};
|
||||
_allMagazines deleteAt _specificMagazineIndex;
|
||||
|
||||
{
|
||||
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then {
|
||||
_isRemoved = true;
|
||||
} else {
|
||||
(uniformContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1];
|
||||
if (_specificMagazineIndex > -1) exitWith {
|
||||
clearMagazineCargoGlobal _container;
|
||||
private _containerType = typeOf _container;
|
||||
if (_containerType in ["GroundWeaponHolder", "WeaponHolderSimulated"]) then {
|
||||
_container = createVehicle [_containerType, getPosATL _container, [], 0, "CAN_COLLIDE"];
|
||||
};
|
||||
false
|
||||
} count _magazines;
|
||||
{
|
||||
_container addMagazineAmmoCargo [_x select 0, 1, _x select 1];
|
||||
} forEach _allMagazines;
|
||||
true
|
||||
};
|
||||
false
|
||||
};
|
||||
|
||||
// Check vest
|
||||
_magazines = magazinesAmmoCargo vestContainer _unit select {_x select 0 == _magazineType};
|
||||
_index = _magazines find [_magazineType, _ammoCount];
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
{
|
||||
_unit removeItemFromVest (_x select 0);
|
||||
false
|
||||
} count _magazines;
|
||||
|
||||
{
|
||||
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then {
|
||||
_isRemoved = true;
|
||||
} else {
|
||||
(vestContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1];
|
||||
};
|
||||
false
|
||||
} count _magazines;
|
||||
private _containerArray = [_unit];
|
||||
if (_unit isKindOf "CAManBase") then {
|
||||
_containerArray = [uniformContainer _unit, vestContainer _unit, backpackContainer _unit];
|
||||
};
|
||||
|
||||
// Check backpack
|
||||
_magazines = magazinesAmmoCargo backpackContainer _unit select {_x select 0 == _magazineType};
|
||||
_index = _magazines find [_magazineType, _ammoCount];
|
||||
{
|
||||
if ([_x, [_magazineType, _ammoCount]] call _fnc_removeMagazine) exitWith {_isRemoved = true};
|
||||
} forEach _containerArray;
|
||||
|
||||
if (_index > -1) exitWith {
|
||||
{
|
||||
_unit removeItemFromBackpack (_x select 0);
|
||||
false
|
||||
} count _magazines;
|
||||
|
||||
{
|
||||
if (!_isRemoved && (_x isEqualTo [_magazineType,_ammoCount])) then {
|
||||
_isRemoved = true;
|
||||
} else {
|
||||
(backpackContainer _unit) addMagazineAmmoCargo [_x select 0, 1, _x select 1];
|
||||
};
|
||||
false
|
||||
} count _magazines;
|
||||
};
|
||||
_isRemoved
|
||||
|
@ -56,7 +56,7 @@ private _reloadNeededAmmo = -1;
|
||||
};
|
||||
} forEach _cswMagazines;
|
||||
} forEach _compatibleMags;
|
||||
} forEach ([_gunner] + (_staticWeapon nearEntities [["groundWeaponHolder", "ReammoBox_F"], 10]));
|
||||
} forEach ([_gunner] + (_staticWeapon nearSupplies 10));
|
||||
if (_reloadMag == "") exitWith {TRACE_1("could not find mag",_reloadMag);};
|
||||
|
||||
// Figure out what we can add from the magazines we have
|
||||
@ -74,11 +74,7 @@ TRACE_4("",_reloadSource,_reloadMag,_reloadNeededAmmo,_bestAmmoToSend);
|
||||
if (_bestAmmoToSend == -1) exitWith {ERROR("No ammo");};
|
||||
|
||||
// Remove the mag from the source
|
||||
if (_reloadSource isKindOf "CaManBase") then {
|
||||
[_reloadSource, _reloadMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
|
||||
} else {
|
||||
[_reloadSource, _reloadMag, 1, _bestAmmoToSend] call CBA_fnc_removeMagazineCargo;
|
||||
};
|
||||
[_reloadSource, _reloadMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
|
||||
|
||||
private _timeToLoad = 1;
|
||||
if (!isNull(configOf _staticWeapon >> QUOTE(ADDON) >> "ammoLoadTime")) then {
|
||||
|
Loading…
Reference in New Issue
Block a user