From 34dea7d971e02f17eb778ffdbe2f6dca9eada2b2 Mon Sep 17 00:00:00 2001 From: jonpas Date: Sat, 4 Jul 2015 22:43:16 +0200 Subject: [PATCH 1/3] Fixed #1796 sitting above ground level --- addons/sitting/functions/fnc_sit.sqf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/sitting/functions/fnc_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index 1944cb21902..d7536c5fbb4 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -37,7 +37,8 @@ _sitRotation = if (isNumber (_configFile >> QGVAR(sitRotation))) then {getNumber // Set direction and position _player setDir _sitDirection; -_player setPosASL (_seat modelToWorld _sitPosition) call EFUNC(common,positionToASL); +// Can NOT use ASL/ATL as modelToWorld returns absolute world position +_player setPos (_seat modelToWorld _sitPosition); // Set variables _player setVariable [QGVAR(isSitting), true]; From cb210f92a0b828f9f76cd8d2a05b428652e87d3d Mon Sep 17 00:00:00 2001 From: jonpas Date: Sun, 5 Jul 2015 17:07:34 +0200 Subject: [PATCH 2/3] Prevented sitting on flipped chairs, Stand when chair gets knocked away/otherwise moves --- addons/sitting/XEH_clientInit.sqf | 6 ++--- addons/sitting/XEH_preInit.sqf | 1 + addons/sitting/functions/fnc_canSit.sqf | 8 ++++-- .../sitting/functions/fnc_handleInterrupt.sqf | 6 ++--- .../sitting/functions/fnc_hasChairMoved.sqf | 27 +++++++++++++++++++ addons/sitting/functions/fnc_sit.sqf | 13 +++++++-- 6 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 addons/sitting/functions/fnc_hasChairMoved.sqf diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index e2bf1b23c19..e95d1f17d92 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -7,6 +7,6 @@ if !(hasInterface) exitWith {}; ["isNotSitting", {!((_this select 0) getVariable [QGVAR(isSitting), false])}] call EFUNC(common,addCanInteractWithCondition); // Handle interruptions -["medical_onUnconscious", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); -["SetHandcuffed", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); -["SetSurrendered", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); +["medical_onUnconscious", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); +["SetHandcuffed", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); +["SetSurrendered", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); diff --git a/addons/sitting/XEH_preInit.sqf b/addons/sitting/XEH_preInit.sqf index 86912ada6b2..1649aaba2bd 100644 --- a/addons/sitting/XEH_preInit.sqf +++ b/addons/sitting/XEH_preInit.sqf @@ -6,6 +6,7 @@ PREP(canSit); PREP(canStand); PREP(getRandomAnimation); PREP(handleInterrupt); +PREP(hasChairMoved); PREP(moduleInit); PREP(sit); PREP(stand); diff --git a/addons/sitting/functions/fnc_canSit.sqf b/addons/sitting/functions/fnc_canSit.sqf index c9762e265cb..c34281e4963 100644 --- a/addons/sitting/functions/fnc_canSit.sqf +++ b/addons/sitting/functions/fnc_canSit.sqf @@ -14,9 +14,13 @@ * * Public: No */ +//#define DEBUG_MODE_FULL #include "script_component.hpp" PARAMS_2(_seat,_player); -// Sitting enabled, is seat object and not occupied -(GVAR(enable) && {getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(canSit)) == 1} && {isNil{_seat getVariable QGVAR(seatOccupied)}}) +// Sitting enabled, is seat object, not occupied and standing up (or not on a big slope) +GVAR(enable) && +{getNumber (configFile >> "CfgVehicles" >> typeOf _seat >> QGVAR(canSit)) == 1} && +{isNil{_seat getVariable QGVAR(seatOccupied)}} && +{round (vectorUp _seat select 0) == 0 && {round (vectorUp _seat select 1) == 0} && {round (vectorUp _seat select 2) == 1}} diff --git a/addons/sitting/functions/fnc_handleInterrupt.sqf b/addons/sitting/functions/fnc_handleInterrupt.sqf index 8127e924efd..1a620bb190e 100644 --- a/addons/sitting/functions/fnc_handleInterrupt.sqf +++ b/addons/sitting/functions/fnc_handleInterrupt.sqf @@ -3,13 +3,13 @@ * Handles interruptions of sitting, like killed or unconsciousness. * * Arguments: - * 0: Player + * Player * * Return Value: * None * * Example: - * [player] call ace_sitting_fnc_handleInterrupt; + * player call ace_sitting_fnc_handleInterrupt; * * Public: No */ @@ -18,5 +18,5 @@ PARAMS_1(_player); if (_player getVariable [QGVAR(isSitting), false]) then { - [_player] call FUNC(stand); + _player call FUNC(stand); }; diff --git a/addons/sitting/functions/fnc_hasChairMoved.sqf b/addons/sitting/functions/fnc_hasChairMoved.sqf new file mode 100644 index 00000000000..fe56438878c --- /dev/null +++ b/addons/sitting/functions/fnc_hasChairMoved.sqf @@ -0,0 +1,27 @@ +/* + * Author: Jonpas + * Checks if chair moved from original position. + * + * Arguments: + * 0: Seat + * 1: Seat Position + * + * Return Value: + * None + * + * Example: + * [seat, seatPos] call ace_sitting_fnc_hasChairMoved; + * + * Public: No + */ +//#define DEBUG_MODE_FULL +#include "script_component.hpp" + +PARAMS_2(_seat,_seatPosOrig); + +TRACE_2("Chair position",_seatPosOrig,getPosASL _seat); + +// Check each coordinate due to possibility of tiny movements in simulation +(getPosASL _seat) select 0 < (_seatPosOrig select 0) - 0.01 || {(getPosASL _seat) select 0 > (_seatPosOrig select 0) + 0.01} || +{(getPosASL _seat) select 1 < (_seatPosOrig select 1) - 0.01 || {(getPosASL _seat) select 1 > (_seatPosOrig select 1) + 0.01}} || +{(getPosASL _seat) select 2 < (_seatPosOrig select 2) - 0.01 || {(getPosASL _seat) select 2 > (_seatPosOrig select 2) + 0.01}} diff --git a/addons/sitting/functions/fnc_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index d7536c5fbb4..b8b1bf69bc1 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -14,6 +14,7 @@ * * Public: No */ +//#define DEBUG_MODE_FULL #include "script_component.hpp" private ["_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_sitDirectionVisual"]; @@ -46,12 +47,20 @@ _seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple peop // Add rotation control PFH _sitDirectionVisual = getDirVisual _player; // Needed for precision and issues with using above directly +_seatPosOrig = getPosASL _seat; [{ - EXPLODE_3_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation); + EXPLODE_5_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation,_seat,_seatPosOrig); // Remove PFH if not sitting any more if !(_player getVariable [QGVAR(isSitting), false]) exitWith { [_this select 1] call cba_fnc_removePerFrameHandler; + TRACE_1("Remove PFH",_player getVariable [ARR_2(QGVAR(isSitting),false)]); + }; + + // Stand up if chair moves + if ([_seat, _seatPosOrig] call FUNC(hasChairMoved)) exitWith { + _player call FUNC(stand); + TRACE_2("Chair moved",getPosASL _seat,_seatPosOrig); }; // Set direction to boundary when passing it @@ -61,4 +70,4 @@ _sitDirectionVisual = getDirVisual _player; // Needed for precision and issues w if (getDir _player < _sitDirectionVisual - _sitRotation) exitWith { _player setDir (_sitDirectionVisual - _sitRotation); }; -}, 0, [_player, _sitDirectionVisual, _sitRotation]] call cba_fnc_addPerFrameHandler; +}, 0, [_player, _sitDirectionVisual, _sitRotation, _seat, _seatPosOrig]] call cba_fnc_addPerFrameHandler; From 815b7984aaa5a7d710138eac1d69a787ac54350d Mon Sep 17 00:00:00 2001 From: jonpas Date: Tue, 7 Jul 2015 03:46:54 +0200 Subject: [PATCH 3/3] Fixed event statement arguments, reworded comment --- addons/sitting/XEH_clientInit.sqf | 5 ++--- addons/sitting/functions/fnc_handleInterrupt.sqf | 2 +- addons/sitting/functions/fnc_sit.sqf | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/sitting/XEH_clientInit.sqf b/addons/sitting/XEH_clientInit.sqf index e95d1f17d92..1e477cd952e 100644 --- a/addons/sitting/XEH_clientInit.sqf +++ b/addons/sitting/XEH_clientInit.sqf @@ -7,6 +7,5 @@ if !(hasInterface) exitWith {}; ["isNotSitting", {!((_this select 0) getVariable [QGVAR(isSitting), false])}] call EFUNC(common,addCanInteractWithCondition); // Handle interruptions -["medical_onUnconscious", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); -["SetHandcuffed", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); -["SetSurrendered", {_player call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); +["medical_onUnconscious", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); +["SetHandcuffed", {_this call DFUNC(handleInterrupt)}] call EFUNC(common,addEventhandler); diff --git a/addons/sitting/functions/fnc_handleInterrupt.sqf b/addons/sitting/functions/fnc_handleInterrupt.sqf index 1a620bb190e..fb326351950 100644 --- a/addons/sitting/functions/fnc_handleInterrupt.sqf +++ b/addons/sitting/functions/fnc_handleInterrupt.sqf @@ -3,7 +3,7 @@ * Handles interruptions of sitting, like killed or unconsciousness. * * Arguments: - * Player + * 0: Player * * Return Value: * None diff --git a/addons/sitting/functions/fnc_sit.sqf b/addons/sitting/functions/fnc_sit.sqf index b8b1bf69bc1..6959bd47783 100644 --- a/addons/sitting/functions/fnc_sit.sqf +++ b/addons/sitting/functions/fnc_sit.sqf @@ -38,7 +38,7 @@ _sitRotation = if (isNumber (_configFile >> QGVAR(sitRotation))) then {getNumber // Set direction and position _player setDir _sitDirection; -// Can NOT use ASL/ATL as modelToWorld returns absolute world position +// No need for ATL/ASL as modelToWorld returns in format position _player setPos (_seat modelToWorld _sitPosition); // Set variables