diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 35b0f5c3fe..6f9dcb5d3a 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -161,3 +161,12 @@ _vehicle setFuel _fuelLevel; ["displayTextStructured", FUNC(displayTextStructured)] call FUNC(addEventhandler); ["displayTextPicture", FUNC(displayTextPicture)] call FUNC(addEventhandler); + +["lockVehicle", { + _this setVariable [QGVAR(lockStatus), locked _this]; + _this lock 2 +}] call FUNC(addEventhandler); + +["unlockVehicle", { + _this lock (_this getVariable [QGVAR(lockStatus), locked _this]) +}] call FUNC(addEventhandler); diff --git a/addons/common/functions/fnc_claim.sqf b/addons/common/functions/fnc_claim.sqf index cf960ac462..73317ee876 100644 --- a/addons/common/functions/fnc_claim.sqf +++ b/addons/common/functions/fnc_claim.sqf @@ -1,7 +1,20 @@ -// by commy2 +/* + * Author: commy2 + * + * Unit claims the ownership over an object. This is used to prevent multiple players from draging the same ammo box or using up the same wheel when repairing etc. + * + * Arguments: + * 0: Unit that claims another object. ObjNull to remove claim. (Object) + * 1: The object that gets claimed. (Object) + * 2: Lock the claimed object aswell? (Bool) + * + * Return Value: + * NONE + * + */ #include "script_component.hpp" -private ["_unit", "_target", "_lockTarget", "_owner"]; +private ["_unit", "_target", "_lockTarget"]; _unit = _this select 0; _target = _this select 1; @@ -9,20 +22,26 @@ _lockTarget = _this select 2; if (isNil "_lockTarget") then {_lockTarget = false}; -_owner = _target getVariable ["ACE_isUsedBy", objNull]; +private "_owner"; +_owner = _target getVariable [QGVAR(owner), objNull]; if (!isNull _owner && {!isNull _unit} && {_unit != _owner}) then { diag_log text "[ACE] ERROR: Claiming already owned object."; }; -_target setVariable ["ACE_isUsedBy", _unit, true]; +// transfer this immediately +_target setVariable [QGVAR(owner), _unit, true]; +// lock target object if (_lockTarget) then { - if (!isNull _unit) then { - [_target, "{_locked = locked _this; _this setVariable ['ACE_lockStatus', _locked]; _this lock 2}", _target] call FUNC(execRemoteFnc); - } else { - [_target, "{_this lock (_this getVariable ['ACE_lockStatus', locked _this])}", _target] call FUNC(execRemoteFnc); - }; + if (!isNull _unit) then { + ["lockVehicle", _target, _target] call FUNC(targetEvent); + } else { + ["unlockVehicle", _target, _target] call FUNC(targetEvent); + }; }; -//systemChat str locked _target; systemChat str (_target getVariable ['ACE_lockStatus', locked _target]); +/* +systemChat str locked _target; +systemChat str (_target getVariable [QGVAR(lockStatus), locked _target]); +*/ diff --git a/addons/common/functions/fnc_owned.sqf b/addons/common/functions/fnc_owned.sqf index 4fa1dbeb98..5588c23781 100644 --- a/addons/common/functions/fnc_owned.sqf +++ b/addons/common/functions/fnc_owned.sqf @@ -1,8 +1,19 @@ -// by commy2 +/* + * Author: commy2 + * + * Counterpart of ace_common_fnc_claim. Check if the given object is claimed by another unit. + * + * Arguments: + * 0: Any object. (Object) + * + * Return Value: + * Is this object claimed by someone? + * + */ #include "script_component.hpp" -private "_object"; +private "_target"; -_object = _this select 0; +_target = _this select 0; -!isNull (_object getVariable ["ACE_isUsedBy", objNull]) +!isNull (_target getVariable [QGVAR(owner), objNull])