Restricted sitting rotation

This commit is contained in:
jonpas 2015-06-11 19:46:16 +02:00
parent 46020259fd
commit 0a71bd6931
2 changed files with 39 additions and 5 deletions

View File

@ -60,6 +60,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, -0.1, -0.45}; GVAR(sitPosition[]) = {0, -0.1, -0.45};
GVAR(sitRotation) = 10;
}; };
// Camping Chair // Camping Chair
class Land_CampingChair_V2_F: ThingX { class Land_CampingChair_V2_F: ThingX {
@ -68,6 +69,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, -0.1, -0.45}; GVAR(sitPosition[]) = {0, -0.1, -0.45};
GVAR(sitRotation) = 45;
}; };
// Chair (Plastic) // Chair (Plastic)
class Land_ChairPlastic_F: ThingX { class Land_ChairPlastic_F: ThingX {
@ -76,6 +78,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 90; GVAR(sitDirection) = 90;
GVAR(sitPosition[]) = {0, 0, -0.5}; GVAR(sitPosition[]) = {0, 0, -0.5};
GVAR(sitRotation) = 5;
}; };
// Chair (Wooden) // Chair (Wooden)
class Land_ChairWood_F: ThingX { class Land_ChairWood_F: ThingX {
@ -83,7 +86,8 @@ class CfgVehicles {
MACRO_SEAT_ACTION MACRO_SEAT_ACTION
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, 0, 0}; GVAR(sitPosition[]) = {0, -0.05, 0};
GVAR(sitRotation) = 75;
}; };
// Office Chair // Office Chair
class Land_OfficeChair_01_F: ThingX { class Land_OfficeChair_01_F: ThingX {
@ -92,6 +96,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, 0, -0.6}; GVAR(sitPosition[]) = {0, 0, -0.6};
GVAR(sitRotation) = 15;
}; };
// Rattan Chair // Rattan Chair
class Land_RattanChair_01_F: ThingX { class Land_RattanChair_01_F: ThingX {
@ -100,6 +105,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, -0.1, -1}; // Z must be -1 due to chair's geometry (magic floating seat point) GVAR(sitPosition[]) = {0, -0.1, -1}; // Z must be -1 due to chair's geometry (magic floating seat point)
GVAR(sitRotation) = 2;
}; };
// Field Toilet // Field Toilet
class Land_FieldToilet_F: ThingX { class Land_FieldToilet_F: ThingX {
@ -108,6 +114,7 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, 0.75, -1.1}; GVAR(sitPosition[]) = {0, 0.75, -1.1};
GVAR(sitRotation) = 10;
}; };
// Toiletbox // Toiletbox
class Land_ToiletBox_F: ThingX { class Land_ToiletBox_F: ThingX {
@ -116,5 +123,6 @@ class CfgVehicles {
GVAR(canSit) = 1; GVAR(canSit) = 1;
GVAR(sitDirection) = 180; GVAR(sitDirection) = 180;
GVAR(sitPosition[]) = {0, 0.75, -1.1}; GVAR(sitPosition[]) = {0, 0.75, -1.1};
GVAR(sitRotation) = 10;
}; };
}; };

View File

@ -16,6 +16,8 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
private ["_configFile", "_sitDirection", "_sitPosition", "_seatRotation", "_sitDirectionVisual"];
PARAMS_2(_seat,_player); PARAMS_2(_seat,_player);
// Set global variable for standing up // Set global variable for standing up
@ -25,17 +27,41 @@ GVAR(seat) = _seat;
_player switchMove "amovpknlmstpsraswrfldnon"; _player switchMove "amovpknlmstpsraswrfldnon";
// Read config // Read config
private ["_sitDirection", "_sitPosition"]; _configFile = configFile >> "CfgVehicles" >> typeOf _seat;
_sitDirection = getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(sitDirection)); _sitDirection = (getDir _seat) + getNumber (_configFile >> QGVAR(sitDirection));
_sitPosition = getArray (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(sitPosition)); _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) // Get random animation and perform it (before moving player to ensure correct placement)
[_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation); [_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation);
// Set direction and position // Set direction and position
_player setDir ((getDir _seat) + _sitDirection); _player setDir _sitDirection;
_player setPosASL (_seat modelToWorld _sitPosition) call EFUNC(common,positionToASL); _player setPosASL (_seat modelToWorld _sitPosition) call EFUNC(common,positionToASL);
// Set variables // Set variables
_player setVariable [QGVAR(isSitting), true]; _player setVariable [QGVAR(isSitting), true];
_seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple people sitting on one seat _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;