Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ PREP(setSize);
PREP(setSpace);
PREP(startLoadIn);
PREP(startUnload);
PREP(unloadCarryItem);
PREP(unloadItem);
PREP(validateCargoSpace);
2 changes: 0 additions & 2 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
GVAR(interactionParadrop) = false;
createDialog QGVAR(menu);
};

// TOOO maybe drag/carry the unloaded item?
}] call CBA_fnc_addEventHandler;

[QGVAR(serverUnload), {
Expand Down
29 changes: 29 additions & 0 deletions addons/cargo/functions/fnc_unloadCarryItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "script_component.hpp"
/*
* Author: GhostIsSpooky
* Dragging integration. Unloader starts carrying unloaded object.
*
* Arguments:
* 0: Unloader <OBJECT>
* 1: Item <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, object] call ace_cargo_fnc_unloadCarryItem
*
* Public: No
*/
params ["_unloader", "_object"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params ["_unloader", "_object"];
TRACE_2("unloadCarryItem-start",_unloader,_object);

if !(["ace_dragging"] call EFUNC(common,isModLoaded)) exitWith {};

// When unloading attached objects, this code will run before server has finished moving object to the safe position
[{
    params ["_unloader", "_object"];
    (_unloader distance _object) < 10
}, {
    params ["_unloader", "_object"];
    TRACE_2("unloadCarryItem-unloaded",_unloader,_object);
    if ([_unloader, _object] call EFUNC(dragging,canCarry)) exitWith {
        [_unloader, _object] call EFUNC(dragging,startCarry);
    };
    if ([_unloader, _object] call EFUNC(dragging,canDrag)) exitWith {
        [_unloader, _object] call EFUNC(dragging,startDrag);
    };
}, _this, 1.1, { TRACE_1("unloadCarryItem-failed to unload nearby player",_this); }] call CBA_fnc_waitUntilAndExecute;

When unloading a object type in mp the distance check in dragging was failing

ace_cargo_fnc_unloadItem calls QGVAR(serverUnload) and then immeditly calls unloadCarryItem
but it takes a bit for the server to actually move the object down to where the player is

this adds a little delay so all that can happen (only local mp it's 4 frames)
It's possible for this to fail if the unload position is away from the player, but that's just something that can happen and not really an error

also I was worried about collision and physx but it seemed to behave ok
I also switched the nested if statements to the superior exitWith style

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't have access to anything that can (conveniently) commit atm, but works for me. Thanks for testing.


if !(["ace_dragging"] call EFUNC(common,isModLoaded)) exitWith {};

switch (true) do {
case ([_unloader, _object] call EFUNC(dragging,canCarry)): {
[_unloader, _object] call EFUNC(dragging,startCarry);
};
case ([_unloader, _object] call EFUNC(dragging,canDrag)): {
[_unloader, _object] call EFUNC(dragging,startDrag);
};
};
Comment thread
LinkIsGrim marked this conversation as resolved.
Outdated
4 changes: 4 additions & 0 deletions addons/cargo/functions/fnc_unloadItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ if (_object isEqualType objNull) then {
[QEGVAR(common,fixCollision), _object] call CBA_fnc_localEvent;
[QEGVAR(common,fixPosition), _object] call CBA_fnc_localEvent;
};

// Dragging integration
[_unloader, _object] call FUNC(unloadCarryItem);

// Invoke listenable event
["ace_cargoUnloaded", [_object, _vehicle, "unload"]] call CBA_fnc_globalEvent;
true