Cargo - setSpace checks for existing cargo (#7133)

This commit is contained in:
pterolatypus 2019-12-07 21:10:03 +00:00 committed by jonpas
parent bcbffcff26
commit b3c5a72dae
2 changed files with 13 additions and 3 deletions

View File

@ -125,6 +125,7 @@ PiZZADOX <509thParachuteInfantry@gmail.com>
Phyma <sethramstrom@gmail.com> Phyma <sethramstrom@gmail.com>
pokertour pokertour
Professor <lukas.trneny@wo.cz> Professor <lukas.trneny@wo.cz>
Pterolatypus <pterolatypus@gmail.com>
QuickDagger QuickDagger
rakowozz rakowozz
ramius86 <pasini86@hotmail.com> ramius86 <pasini86@hotmail.com>

View File

@ -31,14 +31,23 @@ TRACE_2("setSpace",_vehicle,_size);
// Nothing to do here // Nothing to do here
if ( if (
(isNil "_space") || (isNil "_space") ||
{isNull _vehicle} || {isNull _vehicle}
{_space == _vehicle getVariable [QGVAR(space), CARGO_SPACE(typeOf _vehicle)]}
) exitWith {}; ) exitWith {};
// Account for cargo already in the vehicle
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
private _newSpace = _space;
{
_newSpace = _newSpace - ([_x] call FUNC(getSizeItem));
} forEach _loaded;
// If the new value is the same as the old, do nothing
if (_newSpace == (_vehicle getVariable [QGVAR(space), CARGO_SPACE(typeOf _vehicle)])) exitwith {};
// Apply new space globally // Apply new space globally
_vehicle setVariable [QGVAR(space), _newSpace, true];
// Necessary to update value, even if no space, as API could be used again // Necessary to update value, even if no space, as API could be used again
_vehicle setVariable [QGVAR(hasCargo), _space > 0, true]; _vehicle setVariable [QGVAR(hasCargo), _space > 0, true];
_vehicle setVariable [QGVAR(space), _space, true];
// If no cargo space no need for cargo menu // If no cargo space no need for cargo menu
if (_space <= 0) exitWith {}; if (_space <= 0) exitWith {};