From 0a71bd693103510636c6bf9795a2ff99564b9bb8 Mon Sep 17 00:00:00 2001 From: jonpas Date: Thu, 11 Jun 2015 19:46:16 +0200 Subject: [PATCH] Restricted sitting rotation --- addons/sitting/CfgVehicles.hpp | 10 +++++++- addons/sitting/functions/fnc_sit.sqf | 34 ++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/addons/sitting/CfgVehicles.hpp b/addons/sitting/CfgVehicles.hpp index cd7ec735e4..c915750d02 100644 --- a/addons/sitting/CfgVehicles.hpp +++ b/addons/sitting/CfgVehicles.hpp @@ -60,6 +60,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -0.45}; + GVAR(sitRotation) = 10; }; // Camping Chair class Land_CampingChair_V2_F: ThingX { @@ -68,6 +69,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -0.45}; + GVAR(sitRotation) = 45; }; // Chair (Plastic) class Land_ChairPlastic_F: ThingX { @@ -76,6 +78,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 90; GVAR(sitPosition[]) = {0, 0, -0.5}; + GVAR(sitRotation) = 5; }; // Chair (Wooden) class Land_ChairWood_F: ThingX { @@ -83,7 +86,8 @@ class CfgVehicles { MACRO_SEAT_ACTION GVAR(canSit) = 1; GVAR(sitDirection) = 180; - GVAR(sitPosition[]) = {0, 0, 0}; + GVAR(sitPosition[]) = {0, -0.05, 0}; + GVAR(sitRotation) = 75; }; // Office Chair class Land_OfficeChair_01_F: ThingX { @@ -92,6 +96,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, 0, -0.6}; + GVAR(sitRotation) = 15; }; // Rattan Chair class Land_RattanChair_01_F: ThingX { @@ -100,6 +105,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, -0.1, -1}; // Z must be -1 due to chair's geometry (magic floating seat point) + GVAR(sitRotation) = 2; }; // Field Toilet class Land_FieldToilet_F: ThingX { @@ -108,6 +114,7 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, 0.75, -1.1}; + GVAR(sitRotation) = 10; }; // Toiletbox class Land_ToiletBox_F: ThingX { @@ -116,5 +123,6 @@ class CfgVehicles { GVAR(canSit) = 1; GVAR(sitDirection) = 180; GVAR(sitPosition[]) = {0, 0.75, -1.1}; + GVAR(sitRotation) = 10; }; }; diff --git a/addons/sitting/functions/fnc_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index 4121813b41..1b02ce8e19 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -16,6 +16,8 @@ */ #include "script_component.hpp" +private ["_configFile", "_sitDirection", "_sitPosition", "_seatRotation", "_sitDirectionVisual"]; + PARAMS_2(_seat,_player); // Set global variable for standing up @@ -25,17 +27,41 @@ GVAR(seat) = _seat; _player switchMove "amovpknlmstpsraswrfldnon"; // Read config -private ["_sitDirection", "_sitPosition"]; -_sitDirection = getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(sitDirection)); -_sitPosition = getArray (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(sitPosition)); +_configFile = configFile >> "CfgVehicles" >> typeOf _seat; +_sitDirection = (getDir _seat) + getNumber (_configFile >> QGVAR(sitDirection)); +_sitPosition = getArray (_configFile >> QGVAR(sitPosition)); +_sitRotation = if (isNumber (_configFile >> QGVAR(sitRotation))) then {getNumber (_configFile >> QGVAR(sitRotation))} else {45}; // Apply default if config entry not present // Get random animation and perform it (before moving player to ensure correct placement) [_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation); // Set direction and position -_player setDir ((getDir _seat) + _sitDirection); +_player setDir _sitDirection; _player setPosASL (_seat modelToWorld _sitPosition) call EFUNC(common,positionToASL); // Set variables _player setVariable [QGVAR(isSitting), true]; _seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple people sitting on one seat + +// Add rotation control PFH +_sitDirectionVisual = getDirVisual _player; // Needed for precision and issues with using above directly +[{ + private ["_args", "_player", "_sitDirectionVisual", "_sitRotation", "_currentDirection"]; + _args = _this select 0; + _player = _args select 0; + _sitDirectionVisual = _args select 1; + _sitRotation = _args select 2; + + // Remove PFH if not sitting anymore + if !(_player getVariable [QGVAR(isSitting), false]) exitWith { + [_this select 1] call cba_fnc_removePerFrameHandler; + }; + + _currentDirection = getDir _player; + if (_currentDirection > _sitDirectionVisual + _sitRotation) exitWith { + _player setDir (_sitDirectionVisual + _sitRotation); + }; + if (_currentDirection < _sitDirectionVisual - _sitRotation) exitWith { + _player setDir (_sitDirectionVisual - _sitRotation); + }; +}, 0, [_player, _sitDirectionVisual, _sitRotation]] call CBA_fnc_addPerFrameHandler;