ACE3/addons/towing/functions/fnc_detachRope.sqf
Dystopian b54992b8fc
Towing - Fix some issues (#9007)
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
2024-02-05 15:54:51 -03:00

61 lines
1.8 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: Dystopian
* Detaches rope of given hook and gives rope item back.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Rope Hook <OBJECT>
* 2: Deleted object <OBJECT> (default: objNull)
*
* Return Value:
* None
*
* Example:
* [player, cursorObject] call ace_towing_fnc_detachRope
*
* Public: No
*/
params ["_unit", "_hook", ["_deletedObject", objNull]];
private _hookVars = _hook getVariable QGVAR(vars);
if (isNil "_hookVars") then { // this is hookParent
_hook = _hook getVariable QGVAR(hook);
_hookVars = _hook getVariable QGVAR(vars);
};
_hookVars params ["_parent", "_child", "_rope", "_ropeClass", "_hookParent"];
TRACE_8("detachRope",_unit,_parent,_child,_hook,_hookParent,_rope,_ropeClass,_deletedObject);
ropeDestroy _rope; // can run on client
if (!isNull _unit && {_ropeClass isNotEqualTo ""}) then {
[_unit, _ropeClass, true] call CBA_fnc_addItem;
};
{
detach _x;
deleteVehicle _x;
} forEach [_hook, _hookParent];
// cleanup object variables and EHs only if function isn't called from Deleted EH
if (isNull _deletedObject || {_parent isNotEqualTo _deletedObject}) then {
private _parentChildHooks = _parent getVariable [QGVAR(childHooks), []];
_parentChildHooks = _parentChildHooks - [_hook];
_parent setVariable [QGVAR(childHooks), _parentChildHooks, true];
if (_parentChildHooks isEqualTo []) then {
[QGVAR(cleanupParent), _parent] call CBA_fnc_serverEvent;
};
};
if (isNull _deletedObject || {_child isNotEqualTo _deletedObject}) then {
private _childParentHooks = _child getVariable [QGVAR(parentHooks), []];
_childParentHooks = _childParentHooks - [_hook];
_child setVariable [QGVAR(parentHooks), _childParentHooks, true];
if (_childParentHooks isEqualTo []) then {
[QGVAR(detachChild), _child] call CBA_fnc_globalEvent;
};
};