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
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-09-26 22:40:59 +00:00
|
|
|
private ["_actionID", "_configFile", "_sitDirection", "_sitPosition", "_seatPosOrig"];
|
2015-06-11 17:46:16 +00:00
|
|
|
|
2015-08-07 13:12:24 +00:00
|
|
|
params ["_seat", "_player"];
|
2015-06-07 20:00:43 +00:00
|
|
|
|
|
|
|
// Overwrite weird position, because Arma decides to set it differently based on current animation/stance...
|
|
|
|
_player switchMove "amovpknlmstpsraswrfldnon";
|
|
|
|
|
2015-09-11 15:25:46 +00:00
|
|
|
// Add scroll-wheel action to release object
|
2015-09-01 19:03:28 +00:00
|
|
|
_actionID = _player addAction [
|
|
|
|
format ["<t color='#FFFF00'>%1</t>", localize LSTRING(Stand)],
|
|
|
|
QUOTE((_this select 0) call FUNC(stand)),
|
|
|
|
nil,
|
|
|
|
20,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
"GetOut",
|
|
|
|
QUOTE(_this call FUNC(canStand))
|
|
|
|
];
|
|
|
|
|
2015-06-07 20:00:43 +00:00
|
|
|
// 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));
|
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)
|
2015-08-08 00:13:14 +00:00
|
|
|
[_player, call FUNC(getRandomAnimation), 2] call EFUNC(common,doAnimation); // Correctly places when using non-transitional animations
|
|
|
|
[_player, "", 1] call EFUNC(common,doAnimation); // Correctly applies animation's config values (such as disallow throwing of grenades, intercept keybinds... etc).
|
2015-06-09 14:48:58 +00:00
|
|
|
|
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
|
|
|
|
2015-09-26 23:31:23 +00:00
|
|
|
// Set variables, save seat object on player
|
2015-09-26 23:37:19 +00:00
|
|
|
_player setVariable [QGVAR(isSitting), [_seat, _actionID]];
|
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
|
|
|
|
2015-09-11 15:25:46 +00:00
|
|
|
|
2015-09-11 15:27:08 +00:00
|
|
|
// Add automatical stand PFH in case of interruptions
|
2015-09-11 15:25:46 +00:00
|
|
|
_seatPosOrig = getPosASL _seat;
|
2015-06-11 17:46:16 +00:00
|
|
|
[{
|
2015-08-07 13:12:24 +00:00
|
|
|
params ["_args", "_pfhId"];
|
2015-09-11 14:46:51 +00:00
|
|
|
_args params ["_player", "_seat", "_seatPosOrig"];
|
2015-08-07 13:12:24 +00:00
|
|
|
|
2015-06-26 19:31:48 +00:00
|
|
|
// Remove PFH if not sitting any more
|
2015-09-26 23:31:23 +00:00
|
|
|
if (isNil {_player getVariable QGVAR(isSitting)}) exitWith {
|
2015-09-11 14:46:51 +00:00
|
|
|
[_pfhId] call CBA_fnc_removePerFrameHandler;
|
2015-08-07 13:12:24 +00:00
|
|
|
TRACE_1("Remove PFH",_player getVariable [ARR_2(QGVAR(isSitting), false)]);
|
2015-07-05 15:07:34 +00:00
|
|
|
};
|
|
|
|
|
2015-09-11 15:55:28 +00:00
|
|
|
// Stand up if chair gets deleted or moved
|
|
|
|
if (isNull _seat || !((getPosASL _seat) isEqualTo _seatPosOrig)) exitWith {
|
2015-07-05 15:07:34 +00:00
|
|
|
_player call FUNC(stand);
|
|
|
|
TRACE_2("Chair moved",getPosASL _seat,_seatPosOrig);
|
2015-06-11 17:46:16 +00:00
|
|
|
};
|
2015-09-11 14:46:51 +00:00
|
|
|
}, 0, [_player, _seat, _seatPosOrig]] call CBA_fnc_addPerFrameHandler;
|