Skip to content

Commit

Permalink
Cargo - Add object variable for custom interaction delay (#10308)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCandianVendingMachine authored Sep 17, 2024
1 parent 6c2eacc commit 038dce8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PREP(canUnloadItem);
PREP(deployCancel);
PREP(deployConfirm);
PREP(getCargoSpaceLeft);
PREP(getDelayItem);
PREP(getNameItem);
PREP(getSelectedItem);
PREP(getSizeItem);
Expand Down
2 changes: 1 addition & 1 deletion addons/cargo/functions/fnc_deployConfirm.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (!isNull GVAR(itemPreviewObject) && {[GVAR(selectedItem), GVAR(interactionVeh
// Position is AGL for unloading event
private _position = ASLToAGL getPosASL GVAR(itemPreviewObject);
private _direction = getDir GVAR(itemPreviewObject);
private _duration = GVAR(loadTimeCoefficient) * (GVAR(selectedItem) call FUNC(getSizeItem));
private _duration = [GVAR(selectedItem), false] call FUNC(getDelayItem);

// If unload time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
Expand Down
26 changes: 26 additions & 0 deletions addons/cargo/functions/fnc_getDelayItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "..\script_component.hpp"
/*
* Author: tcvm
* Gets the delay duration an item should take to load/unload.
*
* Arguments:
* 0: Item <OBJECT> or <TEXT>
* 1: If delay is for paradrop context <BOOLEAN>
*
* Return Value:
* Item load/unload duration <NUMBER>
*
* Example:
* [cursorObject, false] call ace_cargo_fnc_getDelayItem
*
* Public: No
*/

params ["_item", "_isParadrop"];

if ((_item isEqualType objNull) && {_item getVariable [QGVAR(delay), -1] >= 0}) exitWith {
_item getVariable QGVAR(delay) // return
};

([GVAR(loadTimeCoefficient), GVAR(paradropTimeCoefficent)] select _isParadrop) * (_item call FUNC(getSizeItem)) // return

2 changes: 1 addition & 1 deletion addons/cargo/functions/fnc_startLoadIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (isNull _vehicle) exitWith {

// Start progress bar
if ([_item, _vehicle] call FUNC(canLoadItemIn)) then {
private _duration = GVAR(loadTimeCoefficient) * (_item call FUNC(getSizeItem));
private _duration = [_item, false] call FUNC(getDelayItem);

// If load time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
Expand Down
4 changes: 2 additions & 2 deletions addons/cargo/functions/fnc_startUnload.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (GVAR(interactionParadrop)) exitWith {
// Close the cargo menu
closeDialog 0;

private _duration = GVAR(paradropTimeCoefficent) * (_item call FUNC(getSizeItem));
private _duration = [_item, true] call FUNC(getDelayItem);

// If drop time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
Expand Down Expand Up @@ -81,7 +81,7 @@ if ([_item, GVAR(interactionVehicle), _unit] call FUNC(canUnloadItem)) then {
// Close the cargo menu
closeDialog 0;

private _duration = GVAR(loadTimeCoefficient) * (_item call FUNC(getSizeItem));
private _duration = [_item, false] call FUNC(getDelayItem);

// If unload time is 0, don't show a progress bar
if (_duration <= 0) exitWith {
Expand Down
20 changes: 15 additions & 5 deletions docs/wiki/framework/cargo-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ Note that this function can be used to make objects loadable/unloadable (set to
* [object, 3] call ace_cargo_fnc_setSize
```

### 4.3 Adjusting cargo space of a vehicle
### 4.3 Setting Custom Load/Unload Time

```sqf
object setVariable ["ace_cargo_delay", <TIME IN SECONDS>]
```

This will override the load/unload time calculation and instead set it to the value as specified. This value will _not_ be affected by any scaling coefficients, but will instead always take as long as the set delay.

To disable, remove the variable with `object setVariable ["ace_cargo_delay", nil]` or set the delay to a negative value, e.g.: `object setVariable ["ace_cargo_delay", -1]`.

### 4.4 Adjusting cargo space of a vehicle

`ace_cargo_fnc_setSpace`
Note that this function can be used to enable/disable a vehicle's cargo space (set to `0` to disable).
Expand All @@ -134,7 +144,7 @@ Note that this function can be used to enable/disable a vehicle's cargo space (s
* [vehicle, 20] call ace_cargo_fnc_setSpace
```

### 4.4 Load cargo into vehicle
### 4.5 Load cargo into vehicle

`ace_cargo_fnc_loadItem` (Also callable from CBA event `ace_loadCargo`)
Note first argument can be a in-game object or a classname of an object type.
Expand All @@ -155,7 +165,7 @@ Note first argument can be a in-game object or a classname of an object type.
* [object, vehicle] call ace_cargo_fnc_loadItem
```

### 4.5 Unload cargo from vehicle
### 4.6 Unload cargo from vehicle

`ace_cargo_fnc_unloadItem` (Also callable from CBA event `ace_unloadCargo`)

Expand All @@ -172,7 +182,7 @@ Note first argument can be a in-game object or a classname of an object type.
* [object, vehicle] call ace_cargo_fnc_unloadItem
```

### 4.6 Remove/ Delete cargo from vehicle (Added in ACE3 3.11.0)
### 4.7 Remove/ Delete cargo from vehicle (Added in ACE3 3.11.0)

`ace_cargo_fnc_removeCargoItem`

Expand All @@ -190,7 +200,7 @@ Note first argument can be a in-game object or a classname of an object type.
* [crate_7, truck] call ace_cargo_fnc_removeCargoItem
```

### 4.7 Disable cargo renaming via script
### 4.8 Disable cargo renaming via script

```sqf
cargoBox setVariable ["ace_cargo_noRename", true, _disableGlobally]
Expand Down

0 comments on commit 038dce8

Please sign in to comment.