2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-05-31 22:54:57 +00:00
|
|
|
/*
|
2023-08-17 10:02:17 +00:00
|
|
|
* Author: kymckay
|
2023-11-17 23:07:28 +00:00
|
|
|
* Sets the cargo space of any object. Has global effect.
|
2017-05-31 22:54:57 +00:00
|
|
|
* Adds the cargo action menu if necessary.
|
|
|
|
*
|
|
|
|
* Arguments:
|
2023-11-17 23:07:28 +00:00
|
|
|
* 0: Vehicle <OBJECT> (default: objNull)
|
|
|
|
* 1: Cargo space <NUMBER> (default: nil)
|
2017-05-31 22:54:57 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [vehicle player, 20] call ace_cargo_fnc_setSpace
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
|
|
|
params [
|
2023-11-17 23:07:28 +00:00
|
|
|
["_vehicle", objNull, [objNull]],
|
|
|
|
["_space", nil, [0]] // default can't be a number since all are valid
|
2017-05-31 22:54:57 +00:00
|
|
|
];
|
2023-11-17 23:07:28 +00:00
|
|
|
TRACE_2("setSpace",_vehicle,_space);
|
2017-05-31 22:54:57 +00:00
|
|
|
|
|
|
|
// Nothing to do here
|
2023-11-17 23:07:28 +00:00
|
|
|
if (isNil "_space" || {isNull _vehicle}) exitWith {};
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2019-12-07 21:10:03 +00:00
|
|
|
// Account for cargo already in the vehicle
|
|
|
|
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
|
2023-11-17 23:07:28 +00:00
|
|
|
private _cargoSpace = _space;
|
|
|
|
|
2019-12-07 21:10:03 +00:00
|
|
|
{
|
2023-11-17 23:07:28 +00:00
|
|
|
_cargoSpace = _cargoSpace - ((_x call FUNC(getSizeItem)) max 0);
|
2019-12-07 21:10:03 +00:00
|
|
|
} forEach _loaded;
|
|
|
|
|
|
|
|
// If the new value is the same as the old, do nothing
|
2023-11-17 23:07:28 +00:00
|
|
|
if (_cargoSpace == (_vehicle call FUNC(getCargoSpaceLeft))) exitwith {};
|
2019-12-07 21:10:03 +00:00
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// Apply new space globally
|
|
|
|
// Necessary to update value, even if no space, as API could be used again
|
|
|
|
_vehicle setVariable [QGVAR(hasCargo), _space > 0, true];
|
2023-11-17 23:07:28 +00:00
|
|
|
_vehicle setVariable [QGVAR(space), _cargoSpace, true];
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Space should be added for all future JIP players too, regardless of space
|
|
|
|
private _jipID = format [QGVAR(spaceJipID_%1), hashValue _vehicle];
|
|
|
|
[QGVAR(initVehicle), _vehicle, _jipID] call CBA_fnc_globalEventJIP;
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// Remove from JIP queue if vehicle is deleted
|
|
|
|
if !(_vehicle getVariable [QGVAR(setSpaceRemoveJip), false]) then {
|
2017-09-16 20:18:28 +00:00
|
|
|
[_jipID, _vehicle] call CBA_fnc_removeGlobalEventJIP;
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
_vehicle setVariable [QGVAR(setSpaceRemoveJip), true, true];
|
2017-05-31 22:54:57 +00:00
|
|
|
};
|