Cargo - Add checks for adding cargo via config (#9999)

* Add checks for cargo via config

* Update fnc_initVehicle.sqf

* Use loaded number instead of intended number
This commit is contained in:
johnb432 2024-05-22 08:32:46 +02:00 committed by GitHub
parent 99d7e4d57b
commit 052f1c95a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 8 deletions

View File

@ -7,9 +7,10 @@
* 0: Item to be loaded <STRING> or <OBJECT>
* 1: Holder object (vehicle) <OBJECT>
* 2: Amount <NUMBER> (default: 1)
* 3: Ignore interaction distance and stability checks <BOOL> (default: false)
*
* Return Value:
* None
* Objects loaded <NUMBER>
*
* Example:
* ["ACE_Wheel", cursorObject] call ace_cargo_fnc_addCargoItem
@ -17,21 +18,29 @@
* Public: No
*/
params ["_item", "_vehicle", ["_amount", 1]];
TRACE_3("params",_item,_vehicle,_amount);
params ["_item", "_vehicle", ["_amount", 1], ["_ignoreInteraction", false]];
TRACE_4("params",_item,_vehicle,_amount,_ignoreInteraction);
private _loaded = 0;
// Get config sensitive case name
if (_item isEqualType "") then {
_item = _item call EFUNC(common,getConfigName);
for "_i" from 1 to _amount do {
[_item, _vehicle] call FUNC(loadItem);
if !([_item, _vehicle, _ignoreInteraction] call FUNC(loadItem)) exitWith {};
_loaded = _loaded + 1;
};
} else {
[_item, _vehicle] call FUNC(loadItem);
_loaded = parseNumber ([_item, _vehicle, _ignoreInteraction] call FUNC(loadItem));
_item = typeOf _item;
};
TRACE_1("loaded",_loaded);
// Invoke listenable event
["ace_cargoAdded", [_item, _vehicle, _amount]] call CBA_fnc_globalEvent;
["ace_cargoAdded", [_item, _vehicle, _loaded]] call CBA_fnc_globalEvent;
_loaded // return

View File

@ -52,14 +52,21 @@ if (isServer) then {
private _cargoClassname = "";
private _cargoCount = 0;
private _loaded = 0;
{
_cargoClassname = getText (_x >> "type");
_cargoCount = getNumber (_x >> "amount");
TRACE_3("adding ACE_Cargo",configName _x,_cargoClassname,_cargoCount);
TRACE_3("adding ace_cargo",configName _x,_cargoClassname,_cargoCount);
["ace_addCargo", [_cargoClassname, _vehicle, _cargoCount]] call CBA_fnc_localEvent;
// Ignore stability check (distance check is also ignored with this, but it's ignored by default if item is a string)
_loaded = [_cargoClassname, _vehicle, _cargoCount, true] call FUNC(addCargoItem);
// Let loop continue until the end, so that it prints everything into the rpt (there might be smaller items that could still fit in cargo)
if (_loaded != _cargoCount) then {
WARNING_5("%1 (%2) could not fit %3 %4 inside its cargo, only %5 were loaded.",_vehicle,_type,_cargoCount,_cargoClassname,_loaded);
};
} forEach ("true" configClasses (_config >> QUOTE(ADDON) >> "cargo"));
};