Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // "Superhero" Jump Script (ianbanks, Keyhole International)
- //
- // This script may be used and distributed in missions (.pbo files for use in
- // the "Missions" or "MPMissions" directory) provided that the mission is
- // both non-commercial and not used for profit, and this notice is not
- // removed or modified. All other uses require permission from "IanBanks" on
- // the Bohemia Interactive forums (http://forums.bistudio.com/).
- //
- // More specifically, use or distribution of this script (without express
- // permission) is prohibited in script collections (including "hack menus"),
- // and any kind of addon.
- // Some buildings need manual adjustments to be able to land on:
- khi_jumpAdjustments = [
- ["Land_Ind_SiloVelke_02", 10],
- ["Land_Ind_SiloVelke_01", 16],
- ["Land_Ind_silomale", 10],
- ["Land_Vez_Silo", 19.5],
- ["Land_A_Castle_Bergfrit", 10],
- ["Land_A_Castle_Wall1_20", 15],
- ["Land_A_Castle_Donjon", 10],
- ["Land_Farm_WTower", 7],
- ["Land_Nasypka", 4.5]
- ];
- // Disable local damage:
- player allowDamage false;
- // Install a key handler:
- disableSerialization;
- if (isNil "khi_jumpKeyInstalled") then
- {
- sleep 1;
- private ["_display"];
- _display = findDisplay 46;
- _display displayAddEventHandler
- ["KeyDown","_this call khi_keyDown; false"];
- khi_jumpKeyInstalled = true;
- khi_jumpRunning = false;
- khi_jumpTarget = [0, 0, 0];
- khi_jumpStopAt = 0;
- };
- khi_keyDown =
- {
- if ((_this select 1) == 46) then
- {
- [] call khi_jumpRun;
- };
- };
- // Called to make the current player jump onto his or her current
- // "cursorTarget". A single script thread is used to make in-flight
- // corrections.
- khi_jumpRun =
- {
- private ["_object", "_boundingHeight", "_adjustedHeight"];
- _object = cursorTarget;
- if (isNull _object) exitWith { };
- _boundingHeight = ((boundingBox _object) select 1 select 2);
- {
- if (typeOf _object == (_x select 0)) then
- {
- _boundingHeight = _boundingHeight + (_x select 1);
- }
- } forEach khi_jumpAdjustments;
- khi_jumpTarget = getPosASL _object;
- khi_jumpTarget = [khi_jumpTarget select 0, khi_jumpTarget select 1,
- (khi_jumpTarget select 2) + _boundingHeight];
- khi_jumpStopAt = time + 60;
- if (!khi_jumpRunning) then
- {
- khi_jumpRunning = true;
- [] spawn
- {
- private ["_playerGround", "_objectGround", "_v", "_vMag"];
- while { true } do
- {
- [khi_jumpTarget] call khi_jump;
- _playerGround =
- [getPos player select 0, getPos player select 1, 0];
- _objectGround =
- [khi_jumpTarget select 0, khi_jumpTarget select 1, 0];
- if ((_objectGround distance _playerGround) < 20) exitWith { };
- if (time > khi_jumpStopAt) exitWith { };
- sleep 0.5;
- _v = velocity player;
- _vMag =
- (_v select 0) * (_v select 0) +
- (_v select 1) * (_v select 1) +
- (_v select 2) * (_v select 2);
- if (_vMag < 1) exitWith { };
- };
- khi_jumpRunning = false;
- if (animationState player == "halofreefall_non") then
- {
- waitUntil { vectorMagnitude velocity player < 1 };
- player switchMove "";
- };
- };
- };
- };
- // [positionasl _a], returns nil.
- // Called to send the player towards the ASL position "_a".
- khi_jump =
- {
- private ["_a", "_b", "_d", "_x", "_y"];
- _a = getPosASL player;
- _b = _this select 0;
- _d = [
- (_b select 0) - (_a select 0),
- (_b select 1) - (_a select 1),
- (_b select 2) - (_a select 2)];
- _x = sqrt ((_d select 0) * (_d select 0) + (_d select 1) * (_d select 1));
- _y = _d select 2;
- if ((_x + _y) <= 0) exitWith { };
- private ["_vxvy", "_vx", "_vy", "_v", "_sq"];
- _vxvy = [_x, _y] call khi_getVelocityParabolic;
- _vx = _vxvy select 0;
- _vy = _vxvy select 1;
- _v = [
- (_d select 0) * _vx / _x,
- (_d select 1) * _vx / _x,
- _vy];
- vehicle player setVelocity _v;
- };
- // [number _x, number _y], returns [number _vx, number _vy].
- // Returns the velocity (_vx and _vy) required to hit the specified
- // relative point (given by _x and _y) at a comfortable downward angle.
- khi_getVelocityParabolic =
- {
- private ["_x", "_y", "_sq"];
- _x = _this select 0;
- _y = _this select 1;
- _sq = (sqrt (_x + _y));
- _vx = (2.21359 * _x) / _sq;
- _vy = -0.7 * (((-3.16228 * _x) / _sq) - ((6.32456 * _y) / _sq));
- [_vx, _vy]
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement