ACE3/addons/cargo/functions/fnc_handleDestroyed.sqf
johnb432 d1f0dc5e83
Cargo - Improve various aspects (#9617)
* Update CfgVehicles.hpp

* Cargo cleanup

* Update menu.hpp

* Updated status effect key

* Update fnc_onMenuOpen.sqf

* Update fnc_onMenuOpen.sqf

* fix comment from merge

* nil interaction GVARs on menu close

* fix carry bug

* Fix floating objects in MP

* Updated ace_cargoAdded doc

* Fix progress bar prematurely stopping

* Finer cursor object selection

---------

Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
2023-11-17 20:07:28 -03:00

46 lines
1.2 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: mharis001, Glowbal
* Handles an object being destroyed/deleted.
* If object contained loaded cargo, the cargo is deleted.
* If object was loaded cargo, it's removed from loaded cargo list.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* cursorObject call ace_cargo_fnc_handleDestroyed
*
* Public: No
*/
params ["_object"];
private _loaded = _object getVariable [QGVAR(loaded), []];
if (_loaded isNotEqualTo []) then {
// Delete all cargo
{
if (_x isEqualType objNull) then {
detach _x;
deleteVehicle _x;
};
} forEach _loaded;
// In case vehicle is killed, but not deleted, reset loaded list
_object setVariable [QGVAR(loaded), [], true];
};
// Update remaining cargo space, if loaded as cargo in a vehicle
private _vehicle = attachedTo _object;
if (!isNull _vehicle && {_object in (_vehicle getVariable [QGVAR(loaded), []])}) then {
private _cargoSpace = _vehicle call FUNC(getCargoSpaceLeft);
private _itemSize = (_object call FUNC(getSizeItem)) max 0; // don't let negative size items increase space
_vehicle setVariable [QGVAR(space), _cargoSpace + _itemSize, true];
};