@name Plane Testing
@inputs EGP:wirelink 
@outputs
@persist [E D]:entity [R]:array Height 
@persist T P Y H Mul K ThrustTimer Strike 

if (first() | duped() | dupefinished()) {
    runOnTick(1)
    E = entity():isWeldedTo()
    Height = 40
    E:setMass(50000)
    entity():setMass(0)
    R = players()
    R:insertEntity(1,E)
    rangerPersist(1)
    rangerFilter(R)
    
    EGP:egpClear()
    
    EGP:egpBox(1,vec2(256,756),vec2(30,80))
    EGP:egpColor(1,vec(0,0,0))
    
    EGP:egpAlign(3,1,1)
}

R1 = rangerOffset(999999,E:pos(),vec(0,0,-1))
H = R1:distance()
V = E:driver():isValid()
D = E:driver()
E:applyAngForce(-ang(-E:angVel()[3],E:angVel()[2],E:angVel()[1])*E:mass())

if (H <= Height) {
    E:applyForce((-E:vel()+vec(0,0,abs(H-Height)*10))*E:mass())
    E:applyAngForce((ang(E:angles():roll()*50,0,-E:angles():pitch()*50)-(ang(0,D:keyRight()-D:keyLeft(),0)*20))*E:mass())
}

if(H > Height & V | T > 650 & V) {
    Y = vec(D:eye():dot(E:right()),D:eye():dot(E:right()),0):y()
    P = vec(0,D:eye():dot(E:up()),D:eye():dot(E:up())):z()
    E:applyForce(E:toWorld(vec(-E:velL():x(),-E:velL():y(),-E:velL():z()/(1010-T))*E:mass()))  
    E:applyAngForce((ang(E:angles():roll(),0,-E:angles():pitch())+(ang(-P,-Y,Y)*100))*E:mass())
}

if (D:keyForward() & T < 980) {T += 2}
if (D:keyBack() | !V & T > 0) {T -= 3}
if (T < 0) {T = 0}
if (T > 980) {T = 980}

if (V) {E:applyForce(E:forward()*E:mass()*(T+Mul)*2/V)}

Mul -= E:angles()[3]/10

EGP:egpBox(2,vec2(256,756),vec2(25,T/13))
EGP:egpText(3,round(T/9.8) + "%",vec2(240,694))

if (Mul < -400) {Mul = -400}
if (Mul > 980) {Mul = 980}
if (Mul < 0 & E:angles()[3] > -35) {Mul += 2}
if (Mul > 0 & E:angles()[3] < 35) {Mul -= 0.1}

if (changed(D) & D | changed(players():count())) {
    R = array()
    R = players()
    for (I = 1,R:count()) {if (R[I,entity] == owner()) {R:remove(I)}}
}
