Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: chairSitDown.sqf
- Author: aeroson, mcFlaw
- Version: 0.1.1
- Based on chair script by MacRae
- Usage:
- Place a Camping Chair on the map.
- Add this to the Camping chair Init:
- 0 = [this] execVM "chairSitDown.sqf";
- */
- #define PREFIX aero
- #define COMPONENT chairSitDown
- #define DOUBLES(A,B) ##A##_##B
- #define TRIPLES(A,B,C) ##A##_##B##_##C
- #define QUOTE(A) #A
- #define CONCAT(A,B) A####B
- #define GVAR(A) TRIPLES(PREFIX,COMPONENT,A)
- #define QGVAR(A) QUOTE(GVAR(A))
- if(!isNil{GVAR(addSitDownAction)}) exitWith {
- _this call GVAR(addSitDownAction);
- };
- // wiki help:
- // unit addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, positionInModel, radius, radiusView, showIn3D, available, textDefault, textToolTip]
- // Parameters array passed to the script upon activation in _this variable is: [target, caller, ID, arguments]
- GVAR(isSitting) = false;
- GVAR(remote_anim_sitDown) = {
- private["_unit"];
- _unit = _this select 0;
- _unit setVariable [QGVAR(isSitting), true];
- while {animationState _unit != "crew" && _unit getVariable [QGVAR(isSitting), false]} do {
- _unit switchMove "crew";
- sleep 1;
- };
- };
- GVAR(remote_anim_standUp) = {
- private["_unit"];
- _unit = _this select 0;
- _unit switchMove "Stand";
- _unit setVariable [QGVAR(isSitting), false];
- };
- GVAR(addSitDownAction) = {
- _chair = _this select 0;
- _chair addAction ["<t color='#0099FF'>Sit Down</t>", { _this call GVAR(sitDown) }, 0, 100, true, true, "", format["!%1", QGVAR(isSitting)] ];
- };
- GVAR(sitDown) = {
- private ["_chair", "_unit", "_ID"];
- if(GVAR(isSitting)) then {
- if(!isNil{GVAR(constantlySetRotHandle)}) then {
- terminate GVAR(constantlySetRotHandle);
- };
- };
- GVAR(isSitting)=true;
- _chair = _this select 0;
- _unit = _this select 1;
- _ID = _unit addAction ["<t color='#0099FF'>Stand Up</t>", { _this call GVAR(standUp) }, 0, 100, true, true, ""];
- [_chair, _unit, _ID] spawn {
- private ["_chair", "_unit", "_ID", "_pos", "_dirOffset", "_chairClassNames", "_chairDirOffsets", "_index", "_pos", "_dir", "_wasSimulationEnabledChair", "_wasSimulationEnabledUnit", "_enableSimulationHandle"];
- _chair = _this select 0;
- _unit = _this select 1;
- _ID = _this select 2;
- _chairClassNames = ["Land_Chair_EP1", "Land_ChairPlastic_F"]; // only these two have +90, others have +180
- _chairDirOffsets = [90 , 90 ];
- _dirOffset = 180;
- _index = _chairClassNames find (typeOf _chair);
- if(_index != -1) then {
- _dirOffset = _chairDirOffsets select _index;
- };
- _pos = getPos _chair;
- _dir = (getDir _chair) + _dirOffset;
- _unit setVelocity [0,0,-1];
- [[_unit], QGVAR(remote_anim_sitDown)] spawn BIS_fnc_MP;
- #define INITIAL_Z_OFFSET 0.5
- _unit setPos [_pos select 0, _pos select 1, (_pos select 2) + INITIAL_Z_OFFSET];
- _wasSimulationEnabledChair = simulationEnabled _chair;
- _chair enableSimulation false;
- _wasSimulationEnabledUnit = simulationEnabled _unit;
- _enableSimulationHandle = _unit spawn {
- sleep 0.4;
- _this enableSimulation false;
- };
- while{alive _unit && GVAR(isSitting)} do {
- _unit setDir _dir;
- sleep 0.01;
- };
- _chair enableSimulation _wasSimulationEnabledChair;
- _unit enableSimulation _wasSimulationEnabledUnit;
- terminate _enableSimulationHandle;
- GVAR(isSitting)=false;
- [[_unit], QGVAR(remote_anim_standUp)] spawn BIS_fnc_MP;
- _unit removeAction _ID;
- };
- };
- GVAR(standUp) = {
- GVAR(isSitting)=false;
- };
- _this call GVAR(addSitDownAction);
Advertisement
Add Comment
Please, Sign In to add comment