fix belt linking issues

This commit is contained in:
Salluci 2023-06-30 03:43:09 +03:00
parent 22b93e2d03
commit 39f200b941
3 changed files with 28 additions and 14 deletions

View File

@ -10,7 +10,7 @@
* 2: Source of magazine <OBJECT>
* 3: Vehicle Magazine <STRING>
* 4: Ammo in magazine <NUMBER>
* 5: Unit or object to return ammo to <OBJECT>
* 5: Unit or object to return ammo to <OBJECT> (default: Source of magazine)
*
* Return Value:
* None
@ -21,7 +21,8 @@
* Public: No
*/
params ["_vehicle", "_turret", "_magSource", "_carryMag", "_ammoReceived", ["_returnTo", _magSource]];
params ["_vehicle", "_turret", "_magSource", "_carryMag", "_ammoReceived"];
private _returnTo = param [5, _magSource];
TRACE_6("reload_handleAddTurretMag",_vehicle,_turret,_magSource,_carryMag,_ammoReceived,_returnTo);
TRACE_2("",local _vehicle, _vehicle turretLocal _turret);

View File

@ -18,13 +18,13 @@
*/
params ["_unloadTo", "_carryMag", "_ammo"];
TRACE_3("reload_handleReturnAmmo",_unloadTo,_carryMag,_ammo);
TRACE_4("reload_handleReturnAmmo",_unloadTo,typeOf _unloadTo,_carryMag,_ammo);
private _carryMaxAmmo = getNumber (configFile >> "CfgMagazines" >> _carryMag >> "count");
private _fullMagazines = floor (_ammo / _carryMaxAmmo);
private _bulletsRemaining = _ammo % _carryMaxAmmo;
if (_unloadTo isKindOf "CaManBase") then {
if (_unloadTo isKindOf "CAManBase") then {
while {(_fullMagazines > 0) && {[_unloadTo, _carryMag] call CBA_fnc_canAddItem}} do {
_unloadTo addMagazine [_carryMag, _carryMaxAmmo];
_fullMagazines = _fullMagazines - 1;
@ -37,19 +37,21 @@ if (_unloadTo isKindOf "CaManBase") then {
if ((_fullMagazines == 0) && {_bulletsRemaining == 0}) exitWith {};
// Try to use existing container
private _container = _unloadTo getVariable [QGVAR(container), objNull];
if ((_container distance _unloadTo) > 10) then { _container = objNull; };
if (isNull _container) then {
_container = (nearestObjects [_unloadTo, [QGVAR(ammo_holder), "GroundWeaponHolder"], 10]) param [0, objNull];
// Try to use object inventory or existing container
private _container = _unloadTo;
if ((maxLoad _container) isEqualTo 0) then {
_container = _unloadTo getVariable [QGVAR(container), objNull];
if ((_container distance _unloadTo) > 10) then { _container = objNull; };
if (isNull _container) then {
_container = (nearestObjects [_unloadTo, [QGVAR(ammo_holder), "GroundWeaponHolder"], 10]) param [0, objNull];
};
};
if (isNull _container) then {
// Create ammo storage container
private _weaponRelPos = _unloadTo getRelPos RELATIVE_DIRECTION(270);
_weaponRelPos set [2, ((getPosATL _unloadTo) select 2) + 0.05];
_container = createVehicle [["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType), [0, 0, 0], [], 0, "NONE"];
_container = createVehicle [["GroundWeaponHolder", QGVAR(ammo_holder)] select GVAR(handleExtraMagazinesType), [0, 0, 0], [], 0, "CAN_COLLIDE"];
_unloadTo setVariable [QGVAR(container), _container, true];
_container setDir random [0, 180, 360];
_container setPosATL _weaponRelPos;
@ -59,7 +61,7 @@ if (isNull _container) then {
TRACE_2("Creating NEW Container",_container,_weaponRelPos);
};
TRACE_3("adding to container",_container,_fullMagazines,_bulletsRemaining);
TRACE_4("adding to container",_container,typeOf _container,_fullMagazines,_bulletsRemaining);
if (_fullMagazines > 0) then {
_container addMagazineAmmoCargo [_carryMag, _fullMagazines, _carryMaxAmmo];

View File

@ -51,8 +51,19 @@ private _onFinish = {
[_magSource, _carryMag, _bestAmmoToSend] call EFUNC(common,removeSpecificMagazine);
if (_bestAmmoToSend == 0) exitWith {};
TRACE_6("calling addTurretMag event",_vehicle,_turret,_magSource,_carryMag,_bestAmmoToSend, _unit);
[QGVAR(addTurretMag), [_vehicle, _turret, _magSource, _carryMag, _bestAmmoToSend, _unit]] call CBA_fnc_globalEvent;
// workaround for removeSpecificMagazine and WeaponHolders being deleted when empty, get the closest object of same type on the next frame
private _magSourcePos = getPosATL _magSource;
private _magSourceType = typeOf _magSource;
private _eventParams = [_vehicle, _turret, objNull, _carryMag, _bestAmmoToSend];
[{
params ["_args", "_magSourcePos", "_magSourceType"];
_args params ["_vehicle", "_turret", "_magSource", "_carryMag", "_bestAmmoToSend"];
_magSource = _magSourcePos nearestObject _magSourceType;
TRACE_6("calling addTurretMag event",_vehicle,_turret,_magSource,_carryMag,_bestAmmoToSend, _unit);
[QGVAR(addTurretMag), [_vehicle, _turret, _magSource, _carryMag, _bestAmmoToSend, _unit]] call CBA_fnc_globalEvent;
}, [_eventParams, _magSourcePos, _magSourceType]] call CBA_fnc_execNextFrame;
};