2015-06-07 20:00:43 +00:00
|
|
|
/*
|
|
|
|
* Author: Jonpas
|
|
|
|
* Sits down the player.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Seat <OBJECT>
|
|
|
|
* 1: Player <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [seat, player] call ace_sitting_fnc_sit;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-07-05 15:07:34 +00:00
|
|
|
//#define DEBUG_MODE_FULL
|
2015-06-07 20:00:43 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-06-26 19:31:48 +00:00
|
|
|
private ["_configFile", "_sitDirection", "_sitPosition", "_sitRotation", "_sitDirectionVisual"];
|
2015-06-11 17:46:16 +00:00
|
|
|
|
2015-06-07 20:00:43 +00:00
|
|
|
PARAMS_2(_seat,_player);
|
|
|
|
|
|
|
|
// Set global variable for standing up
|
|
|
|
GVAR(seat) = _seat;
|
|
|
|
|
|
|
|
// Overwrite weird position, because Arma decides to set it differently based on current animation/stance...
|
|
|
|
_player switchMove "amovpknlmstpsraswrfldnon";
|
|
|
|
|
|
|
|
// Read config
|
2015-06-11 17:46:16 +00:00
|
|
|
_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
|
2015-06-07 20:00:43 +00:00
|
|
|
|
2015-06-09 14:48:58 +00:00
|
|
|
// Get random animation and perform it (before moving player to ensure correct placement)
|
|
|
|
[_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation);
|
|
|
|
|
2015-06-07 20:00:43 +00:00
|
|
|
// Set direction and position
|
2015-06-11 17:46:16 +00:00
|
|
|
_player setDir _sitDirection;
|
2015-07-07 01:46:54 +00:00
|
|
|
// No need for ATL/ASL as modelToWorld returns in format position
|
2015-07-04 20:43:16 +00:00
|
|
|
_player setPos (_seat modelToWorld _sitPosition);
|
2015-06-07 20:00:43 +00:00
|
|
|
|
|
|
|
// Set variables
|
2015-06-08 21:39:14 +00:00
|
|
|
_player setVariable [QGVAR(isSitting), true];
|
2015-06-07 20:00:43 +00:00
|
|
|
_seat setVariable [QGVAR(seatOccupied), true, true]; // To prevent multiple people sitting on one seat
|
2015-06-11 17:46:16 +00:00
|
|
|
|
|
|
|
// Add rotation control PFH
|
|
|
|
_sitDirectionVisual = getDirVisual _player; // Needed for precision and issues with using above directly
|
2015-07-05 15:07:34 +00:00
|
|
|
_seatPosOrig = getPosASL _seat;
|
2015-06-11 17:46:16 +00:00
|
|
|
[{
|
2015-07-05 15:07:34 +00:00
|
|
|
EXPLODE_5_PVT(_this select 0,_player,_sitDirectionVisual,_sitRotation,_seat,_seatPosOrig);
|
2015-06-11 17:46:16 +00:00
|
|
|
|
2015-06-26 19:31:48 +00:00
|
|
|
// Remove PFH if not sitting any more
|
2015-06-11 17:46:16 +00:00
|
|
|
if !(_player getVariable [QGVAR(isSitting), false]) exitWith {
|
|
|
|
[_this select 1] call cba_fnc_removePerFrameHandler;
|
2015-07-05 15:07:34 +00:00
|
|
|
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);
|
2015-06-11 17:46:16 +00:00
|
|
|
};
|
|
|
|
|
2015-06-11 19:51:41 +00:00
|
|
|
// Set direction to boundary when passing it
|
2015-06-26 19:31:48 +00:00
|
|
|
if (getDir _player > _sitDirectionVisual + _sitRotation) exitWith {
|
2015-06-11 17:46:16 +00:00
|
|
|
_player setDir (_sitDirectionVisual + _sitRotation);
|
|
|
|
};
|
2015-06-26 19:31:48 +00:00
|
|
|
if (getDir _player < _sitDirectionVisual - _sitRotation) exitWith {
|
2015-06-11 17:46:16 +00:00
|
|
|
_player setDir (_sitDirectionVisual - _sitRotation);
|
|
|
|
};
|
2015-08-04 07:34:31 +00:00
|
|
|
}, 0, [_player, _sitDirectionVisual, _sitRotation, _seat, _seatPosOrig]] call CBA_fnc_addPerFrameHandler;
|