aeroson

Arma 3: Chair sit down script

Nov 8th, 2014
1,143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. /*
  2.  
  3. Name: chairSitDown.sqf
  4. Author: aeroson, mcFlaw
  5. Version: 0.1.1
  6. Based on chair script by MacRae
  7.  
  8. Usage:
  9. Place a Camping Chair on the map.
  10. Add this to the Camping chair Init:
  11. 0 = [this] execVM "chairSitDown.sqf";
  12.  
  13. */
  14.  
  15.  
  16.  
  17.  
  18. #define PREFIX aero
  19. #define COMPONENT chairSitDown
  20.  
  21.  
  22. #define DOUBLES(A,B) ##A##_##B
  23. #define TRIPLES(A,B,C) ##A##_##B##_##C
  24. #define QUOTE(A) #A
  25. #define CONCAT(A,B) A####B
  26.  
  27. #define GVAR(A) TRIPLES(PREFIX,COMPONENT,A)
  28. #define QGVAR(A) QUOTE(GVAR(A))
  29.  
  30.  
  31.  
  32. if(!isNil{GVAR(addSitDownAction)}) exitWith {
  33. _this call GVAR(addSitDownAction);
  34. };
  35.  
  36.  
  37. // wiki help:
  38. // unit addAction [title, script, arguments, priority, showWindow, hideOnUse, shortcut, condition, positionInModel, radius, radiusView, showIn3D, available, textDefault, textToolTip]
  39. // Parameters array passed to the script upon activation in _this variable is: [target, caller, ID, arguments]
  40.  
  41.  
  42.  
  43. GVAR(isSitting) = false;
  44.  
  45.  
  46.  
  47. GVAR(remote_anim_sitDown) = {
  48. private["_unit"];
  49. _unit = _this select 0;
  50. _unit setVariable [QGVAR(isSitting), true];
  51. while {animationState _unit != "crew" && _unit getVariable [QGVAR(isSitting), false]} do {
  52. _unit switchMove "crew";
  53. sleep 1;
  54. };
  55. };
  56.  
  57.  
  58. GVAR(remote_anim_standUp) = {
  59. private["_unit"];
  60. _unit = _this select 0;
  61. _unit switchMove "Stand";
  62. _unit setVariable [QGVAR(isSitting), false];
  63. };
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. GVAR(addSitDownAction) = {
  71.  
  72. _chair = _this select 0;
  73. _chair addAction ["<t color='#0099FF'>Sit Down</t>", { _this call GVAR(sitDown) }, 0, 100, true, true, "", format["!%1", QGVAR(isSitting)] ];
  74.  
  75. };
  76.  
  77.  
  78.  
  79. GVAR(sitDown) = {
  80.  
  81. private ["_chair", "_unit", "_ID"];
  82.  
  83. if(GVAR(isSitting)) then {
  84. if(!isNil{GVAR(constantlySetRotHandle)}) then {
  85. terminate GVAR(constantlySetRotHandle);
  86. };
  87. };
  88. GVAR(isSitting)=true;
  89.  
  90. _chair = _this select 0;
  91. _unit = _this select 1;
  92. _ID = _unit addAction ["<t color='#0099FF'>Stand Up</t>", { _this call GVAR(standUp) }, 0, 100, true, true, ""];
  93.  
  94. [_chair, _unit, _ID] spawn {
  95.  
  96. private ["_chair", "_unit", "_ID", "_pos", "_dirOffset", "_chairClassNames", "_chairDirOffsets", "_index", "_pos", "_dir", "_wasSimulationEnabledChair", "_wasSimulationEnabledUnit", "_enableSimulationHandle"];
  97.  
  98. _chair = _this select 0;
  99. _unit = _this select 1;
  100. _ID = _this select 2;
  101.  
  102. _chairClassNames = ["Land_Chair_EP1", "Land_ChairPlastic_F"]; // only these two have +90, others have +180
  103. _chairDirOffsets = [90 , 90 ];
  104. _dirOffset = 180;
  105.  
  106. _index = _chairClassNames find (typeOf _chair);
  107. if(_index != -1) then {
  108. _dirOffset = _chairDirOffsets select _index;
  109. };
  110.  
  111. _pos = getPos _chair;
  112. _dir = (getDir _chair) + _dirOffset;
  113.  
  114. _unit setVelocity [0,0,-1];
  115. [[_unit], QGVAR(remote_anim_sitDown)] spawn BIS_fnc_MP;
  116.  
  117. #define INITIAL_Z_OFFSET 0.5
  118. _unit setPos [_pos select 0, _pos select 1, (_pos select 2) + INITIAL_Z_OFFSET];
  119.  
  120. _wasSimulationEnabledChair = simulationEnabled _chair;
  121. _chair enableSimulation false;
  122.  
  123. _wasSimulationEnabledUnit = simulationEnabled _unit;
  124.  
  125. _enableSimulationHandle = _unit spawn {
  126. sleep 0.4;
  127. _this enableSimulation false;
  128. };
  129.  
  130. while{alive _unit && GVAR(isSitting)} do {
  131. _unit setDir _dir;
  132. sleep 0.01;
  133. };
  134.  
  135. _chair enableSimulation _wasSimulationEnabledChair;
  136. _unit enableSimulation _wasSimulationEnabledUnit;
  137.  
  138. terminate _enableSimulationHandle;
  139.  
  140. GVAR(isSitting)=false;
  141.  
  142. [[_unit], QGVAR(remote_anim_standUp)] spawn BIS_fnc_MP;
  143.  
  144. _unit removeAction _ID;
  145.  
  146. };
  147.  
  148. };
  149.  
  150.  
  151.  
  152. GVAR(standUp) = {
  153.  
  154. GVAR(isSitting)=false;
  155.  
  156. };
  157.  
  158.  
  159.  
  160. _this call GVAR(addSitDownAction);
Advertisement
Add Comment
Please, Sign In to add comment