solve canInteract conflicts, fix #198

This commit is contained in:
commy2 2015-03-15 09:02:11 +01:00
parent db6e0fe99b
commit 876424695e
6 changed files with 158 additions and 18 deletions

View File

@ -7,6 +7,7 @@ ADDON = false;
PREP(addActionEventHandler);
PREP(addActionMenuEventHandler);
PREP(addCameraEventHandler);
PREP(addCanInteractWithConditon);
PREP(addCustomEventHandler);
PREP(addLineToDebugDraw);
PREP(addMapMarkerCreatedEventHandler);
@ -147,6 +148,7 @@ PREP(receiveRequest);
PREP(removeActionEventHandler);
PREP(removeActionMenuEventHandler);
PREP(removeCameraEventHandler);
PREP(removeCanInteractWithConditon);
PREP(removeCustomEventHandler);
PREP(removeMapMarkerCreatedEventHandler);
PREP(removeScrollWheelEventHandler);

View File

@ -0,0 +1,38 @@
/*
* Author: commy2
*
* Add a condition that gets checked by ace_common_fnc_canInteractWith.
*
* Arguments:
* 0: The conditions id. Used to remove later or as exception name. An already existing name overwrites. (String)
* 1: The condition to check. format of "_this" is "[_player, _target]". (Code)
*
* Return Value:
* Unit can interact?
*
*/
#include "script_component.hpp"
private ["_conditionName", "_conditionFunc"];
_conditionName = toLower (_this select 0);
_conditionFunc = _this select 1;
private ["_conditions", "_conditionNames", "_conditionFuncs"];
_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];
_conditionNames = _conditions select 0;
_conditionFuncs = _conditions select 1;
private "_index";
_index = _conditionNames find _conditionName;
if (_index == -1) then {
_index = count _conditionNames;
};
_conditionNames set [_index, _conditionName];
_conditionFuncs set [_index, _conditionFunc];
GVAR(InteractionConditions) = [_conditionNames, _conditionFuncs];

View File

@ -1,11 +1,47 @@
// by commy2
/*
* Author: commy2
*
* Check if the unit can interact.
*
* Arguments:
* 0: The player. (Object)
* 1: The interaction target. objNull to ignore. (Object)
* 2: Exceptions. What general conditions are to skip? (Array)
*
* Return Value:
* Unit can interact?
*
*/
#include "script_component.hpp"
private ["_unit", "_target", "_owner"];
private ["_unit", "_target", "_exceptions"];
_unit = _this select 0;
_target = _this select 1;
_exceptions = _this select 2;
_owner = _target getVariable ["ACE_isUsedBy", objNull];
// exit if the target is not free to interact
private "_owner";
_owner = _target getVariable [QGVAR(owner), objNull];
isNull _owner || {_unit == _owner} || {!isPlayer _owner}
if (!isNull _owner && {_unit != _owner} && {!([_owner] call FUNC(isPlayer))}) exitWith {false};
// check general conditions
private ["_conditions", "_conditionNames", "_conditionFuncs"];
_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];
_conditionNames = _conditions select 0;
_conditionFuncs = _conditions select 1;
private "_canInteract";
_canInteract = true;
{
if (!(_x in _exceptions) && {!([_unit, _target] call (_conditionFuncs select _forEachIndex))}) exitWith {
_canInteract = false;
};
} forEach _conditionNames;
_canInteract

View File

@ -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]);
*/

View File

@ -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])

View File

@ -0,0 +1,34 @@
/*
* Author: commy2
*
* Remove a condition that gets checked by ace_common_fnc_canInteractWith.
*
* Arguments:
* 0: The conditions id. (String)
*
* Return Value:
* Unit can interact?
*
*/
#include "script_component.hpp"
private "_conditionName";
_conditionName = toLower (_this select 0);
private ["_conditions", "_conditionNames", "_conditionFuncs"];
_conditions = missionNamespace getVariable [QGVAR(InteractionConditions), [[],[]]];
_conditionNames = _conditions select 0;
_conditionFuncs = _conditions select 1;
private "_index";
_index = _conditionNames find _conditionName;
if (_index == -1) exitWith {};
_conditionNames deleteAt _index;
_conditionFuncs deleteAt _index;
GVAR(InteractionConditions) = [_conditionNames, _conditionFuncs];