Home   Help Search Login Register  

Author Topic: Make a plane scramble from anywhere  (Read 1613 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Make a plane scramble from anywhere
« on: 26 May 2006, 23:03:56 »
A plane, a choper or whatever is able to fly, now you dont need runaways  ;)

Code: [Select]
;Mandoscramble
;By Mandoble
;Forces any plane to takeoff from its current position and heading
;AI doesn't need runaways anymore ;)
;
;Arguments:
;plane or object to put airborne
;Speed increase to start the climb (still not climbing) in m/s
;Horizontal speed increase after starting the climb in m/s
;Max climb rate increase in m/s
;Time to reach horizontal speed increase to start the climb
;Time to reach climb rate increase once climb is started
;Turn angle during climb in degrees relative to initial heading (0 if the plane should keep straight)
;Camera following the takeoff true/false
;
;Example:
; A plane will get 40 m/s extra horizontal speed in 8 seconds
; then the plane will start a climb for 15 seconds
; the climb rate will increase in 10 m/s during the climbing time (15 secs)
; the horizontal speed will increase in 90 m/s during the climbing time (15 secs)
; the plane will turn 30 degrees left in the climb
;[plane, 40, 90, 10, 8, 15, -30, false]exec"mandoscramble.sqs"
;

_plane     = _this select 0
_vhrunmax  = _this select 1
_vhmax     = _this select 2
_vvmax     = _this select 3
_runtime   = _this select 4
_climbtime = _this select 5
_turn      = _this select 6
_camera    = _this select 7

_delay = 0.01
_dir = getDir _plane
_runcycles    = _runtime / _delay
_runhvelinc   = _vhrunmax / _runcycles

_speedkm = speed _plane
_speed = _speedkm / 3.6
_climbrate = velocity _plane select 2
_climbcycles  = _climbtime / _delay
_climbhvelinc = (_vhmax - _vhrunmax) / _climbcycles
_climbvvelinc = _vvmax / _climbcycles
_turninc = _turn / _climbcycles

_spdh = 0.0
_spdv = 0.0
_i = 0

?_camera:_plane switchCamera "EXTERNAL"
driver _plane sideChat "Starting the takeoff"
#run
_vel = [sin(_dir)*(_spdh + _speed),cos(_dir)*(_spdh + _speed), 0]
_plane setVelocity _vel
_spdh = _spdh + _runhvelinc
_plane setDir _dir
~_delay
_i = _i + 1
?damage _plane > 0.3:goto "crash"
?_i < _runcycles: goto "run"

driver _plane sideChat "End of run, starting to climb"
_i = 0
#climb
_vel = [sin(_dir)*(_spdh + _speed),cos(_dir)*(_spdh + _speed), _climbrate + _spdv]
_plane setVelocity _vel
_spdh = _spdh + _climbhvelinc
_spdv = _spdv + _climbvvelinc
_plane setDir _dir
_dir = _dir + _turninc
~_delay
_i = _i + 1
?damage _plane > 0.3:goto "crash"
?_i < _climbcycles: goto "climb"
driver _plane sideChat "End of takeoff"
?_camera:player switchCamera "EXTERNAL"
exit

#crash
driver _plane sideChat "We got damaged, aborting takeoff"
?(damage _plane > 0.5):goto "eject"
#continue
~10
?_camera:player switchCamera "EXTERNAL"
exit

#eject
driver _plane sideChat "The damage is critical, ejecting!"
_crew = crew _plane
_i = 0
#jump
_unit = _crew select _i
_unit action ["EJECT", vehicle _unit]
_i = _i + 1
~0.5
?_i < count _crew: goto "jump"
goto "continue"

EDIT:
Modified to accept also a turning angle while climbing.
Damage checking included to abort takeoffs or even eject the crew.
« Last Edit: 27 May 2006, 10:57:09 by Mandoble »