ACE3/addons/cargo/functions/fnc_setSize.sqf
SilentSpike fea2326488 Add cargo eden attributes (#4780)
- Add a ace_cargo_space attribute to vehicles to alter how much cargo they can carry.
- Add an ace_cargo_size attribute to objects to alter how much cargo space they consume.
- Add two public functions `fnc_setSize.sqf` and `fnc_setSpace.sqf` to update the cargo size/space respectively of any given object.
- Deprecate cargo makeLoadable module and public function.
- Added some macros to get the space/size of a config, making code more readable in places.
2017-05-31 23:54:57 +01:00

57 lines
1.5 KiB
Plaintext

/*
* Author: SilentSpike
* Set the cargo size of any object. Has global effect.
* Adds the load action menu if necessary.
* Negative size makes unloadable.
*
* Arguments:
* 0: Object <OBJECT>
* 1: Cargo size <NUMBER>
*
* Return Value:
* None
*
* Example:
* [cursorTarget, 3] call ace_cargo_fnc_setSize
*
* Public: Yes
*/
#include "script_component.hpp"
// Only run this after the settings are initialized
if !(EGVAR(common,settingsInitFinished)) exitWith {
EGVAR(common,runAtSettingsInitialized) pushBack [FUNC(setSize), _this];
};
params [
["_object",objNull,[objNull]],
["_size",nil,[0]] // Default can't be a number since all are valid
];
TRACE_2("setSize",_object,_size);
// Nothing to do here
if (
(isNil "_size") ||
{isNull _object} ||
{_size == _object getVariable [QGVAR(size), CARGO_SIZE(typeOf _object)]}
) exitWith {};
// Apply new size globally
// Necessary to update value, even if unloadable, as API could be used again
_object setVariable [QGVAR(canLoad), _size >= 0, true];
_object setVariable [QGVAR(size), _size, true];
// If no size no need for load action
if (_size < 0) exitWith {};
// If an existing ID is present, load action has already been added globally
private _jipID = _object getVariable QGVAR(setSize_jipID);
// Actions should be added to all future JIP players too
if (isNil "_jipID") then {
_jipID = [QGVAR(initObject), [_object]] call CBA_fnc_globalEventJIP;
// Store the ID for any future calls to this function
_object setVariable [QGVAR(setSize_jipID), _jipID, true];
};