Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. // "Superhero" Jump Script (ianbanks, Keyhole International)
  2. //
  3. // This script may be used and distributed in missions (.pbo files for use in
  4. // the "Missions" or "MPMissions" directory) provided that the mission is
  5. // both non-commercial and not used for profit, and this notice is not
  6. // removed or modified. All other uses require permission from "IanBanks" on
  7. // the Bohemia Interactive forums (http://forums.bistudio.com/).
  8. //
  9. // More specifically, use or distribution of this script (without express
  10. // permission) is prohibited in script collections (including "hack menus"),
  11. // and any kind of addon.
  12.  
  13. // Some buildings need manual adjustments to be able to land on:
  14. khi_jumpAdjustments = [
  15. ["Land_Ind_SiloVelke_02", 10],
  16. ["Land_Ind_SiloVelke_01", 16],
  17. ["Land_Ind_silomale", 10],
  18. ["Land_Vez_Silo", 19.5],
  19. ["Land_A_Castle_Bergfrit", 10],
  20. ["Land_A_Castle_Wall1_20", 15],
  21. ["Land_A_Castle_Donjon", 10],
  22. ["Land_Farm_WTower", 7],
  23. ["Land_Nasypka", 4.5]
  24. ];
  25.  
  26. // Disable local damage:
  27. player allowDamage false;
  28.  
  29. // Install a key handler:
  30. disableSerialization;
  31.  
  32. if (isNil "khi_jumpKeyInstalled") then
  33. {
  34. sleep 1;
  35.  
  36. private ["_display"];
  37.  
  38. _display = findDisplay 46;
  39. _display displayAddEventHandler
  40. ["KeyDown","_this call khi_keyDown; false"];
  41.  
  42. khi_jumpKeyInstalled = true;
  43.  
  44. khi_jumpRunning = false;
  45. khi_jumpTarget = [0, 0, 0];
  46. khi_jumpStopAt = 0;
  47. };
  48.  
  49. khi_keyDown =
  50. {
  51. if ((_this select 1) == 46) then
  52. {
  53. [] call khi_jumpRun;
  54. };
  55. };
  56.  
  57. // Called to make the current player jump onto his or her current
  58. // "cursorTarget". A single script thread is used to make in-flight
  59. // corrections.
  60. khi_jumpRun =
  61. {
  62. private ["_object", "_boundingHeight", "_adjustedHeight"];
  63.  
  64. _object = cursorTarget;
  65.  
  66. if (isNull _object) exitWith { };
  67.  
  68. _boundingHeight = ((boundingBox _object) select 1 select 2);
  69.  
  70. {
  71. if (typeOf _object == (_x select 0)) then
  72. {
  73. _boundingHeight = _boundingHeight + (_x select 1);
  74. }
  75. } forEach khi_jumpAdjustments;
  76.  
  77. khi_jumpTarget = getPosASL _object;
  78. khi_jumpTarget = [khi_jumpTarget select 0, khi_jumpTarget select 1,
  79. (khi_jumpTarget select 2) + _boundingHeight];
  80.  
  81. khi_jumpStopAt = time + 60;
  82.  
  83. if (!khi_jumpRunning) then
  84. {
  85. khi_jumpRunning = true;
  86.  
  87. [] spawn
  88. {
  89. private ["_playerGround", "_objectGround", "_v", "_vMag"];
  90.  
  91. while { true } do
  92. {
  93. [khi_jumpTarget] call khi_jump;
  94.  
  95. _playerGround =
  96. [getPos player select 0, getPos player select 1, 0];
  97. _objectGround =
  98. [khi_jumpTarget select 0, khi_jumpTarget select 1, 0];
  99.  
  100. if ((_objectGround distance _playerGround) < 20) exitWith { };
  101.  
  102. if (time > khi_jumpStopAt) exitWith { };
  103.  
  104. sleep 0.5;
  105.  
  106. _v = velocity player;
  107. _vMag =
  108. (_v select 0) * (_v select 0) +
  109. (_v select 1) * (_v select 1) +
  110. (_v select 2) * (_v select 2);
  111.  
  112. if (_vMag < 1) exitWith { };
  113. };
  114.  
  115. khi_jumpRunning = false;
  116.  
  117. if (animationState player == "halofreefall_non") then
  118. {
  119. waitUntil { vectorMagnitude velocity player < 1 };
  120.  
  121. player switchMove "";
  122. };
  123. };
  124. };
  125. };
  126.  
  127. // [positionasl _a], returns nil.
  128. // Called to send the player towards the ASL position "_a".
  129. khi_jump =
  130. {
  131. private ["_a", "_b", "_d", "_x", "_y"];
  132.  
  133. _a = getPosASL player;
  134. _b = _this select 0;
  135.  
  136. _d = [
  137. (_b select 0) - (_a select 0),
  138. (_b select 1) - (_a select 1),
  139. (_b select 2) - (_a select 2)];
  140.  
  141. _x = sqrt ((_d select 0) * (_d select 0) + (_d select 1) * (_d select 1));
  142.  
  143. _y = _d select 2;
  144.  
  145. if ((_x + _y) <= 0) exitWith { };
  146.  
  147. private ["_vxvy", "_vx", "_vy", "_v", "_sq"];
  148.  
  149. _vxvy = [_x, _y] call khi_getVelocityParabolic;
  150.  
  151. _vx = _vxvy select 0;
  152. _vy = _vxvy select 1;
  153.  
  154. _v = [
  155. (_d select 0) * _vx / _x,
  156. (_d select 1) * _vx / _x,
  157. _vy];
  158.  
  159. vehicle player setVelocity _v;
  160. };
  161.  
  162. // [number _x, number _y], returns [number _vx, number _vy].
  163. // Returns the velocity (_vx and _vy) required to hit the specified
  164. // relative point (given by _x and _y) at a comfortable downward angle.
  165. khi_getVelocityParabolic =
  166. {
  167. private ["_x", "_y", "_sq"];
  168.  
  169. _x = _this select 0;
  170. _y = _this select 1;
  171.  
  172. _sq = (sqrt (_x + _y));
  173. _vx = (2.21359 * _x) / _sq;
  174. _vy = -0.7 * (((-3.16228 * _x) / _sq) - ((6.32456 * _y) / _sq));
  175.  
  176. [_vx, _vy]
  177. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement