Skip to content

Commit

Permalink
Prevented sitting on flipped chairs, Stand when chair gets knocked aw…
Browse files Browse the repository at this point in the history
…ay/otherwise moves
  • Loading branch information
jonpas committed Jul 5, 2015
1 parent 34dea7d commit cb210f9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 10 deletions.
6 changes: 3 additions & 3 deletions addons/sitting/XEH_clientInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
1 change: 1 addition & 0 deletions addons/sitting/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PREP(canSit);
PREP(canStand);
PREP(getRandomAnimation);
PREP(handleInterrupt);
PREP(hasChairMoved);
PREP(moduleInit);
PREP(sit);
PREP(stand);
Expand Down
8 changes: 6 additions & 2 deletions addons/sitting/functions/fnc_canSit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
6 changes: 3 additions & 3 deletions addons/sitting/functions/fnc_handleInterrupt.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* Handles interruptions of sitting, like killed or unconsciousness.
*
* Arguments:
* 0: Player <OBJECT>
* Player <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player] call ace_sitting_fnc_handleInterrupt;
* player call ace_sitting_fnc_handleInterrupt;
*
* Public: No
*/
Expand All @@ -18,5 +18,5 @@
PARAMS_1(_player);

if (_player getVariable [QGVAR(isSitting), false]) then {
[_player] call FUNC(stand);
_player call FUNC(stand);
};
27 changes: 27 additions & 0 deletions addons/sitting/functions/fnc_hasChairMoved.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Author: Jonpas
* Checks if chair moved from original position.
*
* Arguments:
* 0: Seat <OBJECT>
* 1: Seat Position <ARRAY>
*
* 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}}
13 changes: 11 additions & 2 deletions addons/sitting/functions/fnc_sit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* Public: No
*/
//#define DEBUG_MODE_FULL
#include "script_component.hpp"

private ["_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_sitDirectionVisual"];
Expand Down Expand Up @@ -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
Expand All @@ -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;

0 comments on commit cb210f9

Please sign in to comment.