@name gay plane e2
@inputs EGP:wirelink EyePod:wirelink
@outputs
@persist [Base P]:entity Vel:vector Thr Fire Wait Rockets:array Side Stall
if(first())
{
    runOnTick(1)
    Base = entity():isWeldedTo()
    Thr = 0
    Base:setMass(50000)
    Base:propGravity(1)
   
    timer("find_chair", 100)
   
    holoCreate(7)
    holoPos(7, Base:toWorld(vec(-60, 0, 5)))
    holoAng(7, Base:toWorld(ang(-90, 0, 0)))
    holoParent(7, Base)
    holoModel(7, "models/xqm/afterburner1.mdl")
}
 
if(clk("find_chair"))
{    
    findByClass("prop_vehicle_prisoner_pod")
    findSortByDistance(Base:pos())
   
    if(find():model() == "models/nova/airboat_seat.mdl" & find():owner() == owner())
    {
        P = find()
        P:setPos(Base:toWorld(vec(0, 0, 5))) #Mess with that vector to change the offset position of the chair
        P:setAng(Base:toWorld(ang(0, 270, 0))) #If you DO want your chair to face backwards or something, go ahead and mess with this
       
        timer("parent", 20)
        stoptimer("find_chair")
    }
}
 
if(clk("parent"))
{
    stoptimer("parent")
       
    P:parentTo(Base)
}
 
Vel = Base:velL()
Base:applyForce(Base:toWorldAxis(-Vel * vec(0.0015, 0.035, abs(Vel:x() / 10000) + 0.005)) * Base:mass())
 
Dri = P:driver()
Active = P:driver():isValid()
if(Active)
{
    W = Dri:keyForward()
    A = Dri:keyLeft()
    S = Dri:keyBack()
    D = Dri:keyRight()
    Spc = Dri:keyJump()
    Shift = Dri:keySprint()
    M1 = Dri:keyAttack1()
    M2 = Dri:keyAttack2()
    R = Dri:keyReload()
    Alt = Dri:keyWalk()
    F = Dri:keyPressed("F")
   
    Fire++
}
 
if(Vel:x() < 500 & Base:vel():length() > 10 & Active){
    Stall = 1
} else {
    Stall = 0
}
 
rangerFilter(Base)
rangerFilter(entity())
rangerFilter(P)
Ranger = rangerOffset(999999999, Base:toWorld(vec(60, 0, 0)), Base:forward())
 
#EGP
EGP:egp3DTracker(2, Base:pos() + Base:vel())
EGP:egp3DTracker(6, Ranger:position() + Base:right() * -35)
EGP:egp3DTracker(7, Ranger:position() + Base:right() * 35)
 
if(first()|changed(Dri))
{
    EGP:egpCircleOutline(1, EGP:egpPos(2), vec2(10, 10))
    EGP:egpParent(1, 2)
    EGP:egpColor(1, vec(0, 255, 0))
   
    EGP:egpBox(12, EGP:egpPos(2) + vec2(17, 0), vec2(15, 1))
    EGP:egpParent(12, 2)
    EGP:egpColor(12, vec(0, 255, 0))
   
    EGP:egpBox(13, EGP:egpPos(2) + vec2(-17, 0), vec2(15, 1))
    EGP:egpParent(13, 2)
    EGP:egpColor(13, vec(0, 255, 0))
   
    EGP:egpBox(14, EGP:egpPos(2) + vec2(0, -17), vec2(1, 15))
    EGP:egpParent(14, 2)
    EGP:egpColor(14, vec(0, 255, 0))
   
    EGP:egpText(3, "SPD: " + Base:vel():length(), vec2(egpScrW(Dri) * 0.47, egpScrH(Dri) * 0.9))
    EGP:egpSize(3, 40)
    EGP:egpColor(3, vec(0, 255, 0))
   
    EGP:egpText(4, "THROT: " + Thr, vec2(egpScrW(Dri) * 0.47, egpScrH(Dri) * 0.95))
    EGP:egpSize(4, 40)
    EGP:egpColor(4, vec(0, 255, 0))
   
    EGP:egpText(5, " *  * STALLING *  * ", vec2(egpScrW(Dri) * 0.45, egpScrH(Dri) * 0.5))
    EGP:egpSize(5, 40)
    EGP:egpColor(5, vec(255, 70, 70))    
   
    EGP:egpTriangleOutline(8, EGP:egpPos(6) + vec2(15, -7.5), EGP:egpPos(6) + vec2(-15, -7.5), EGP:egpPos(6) + vec2(0, 15 * sqrt(3) - 7.5))
    EGP:egpParent(8, 6)
    EGP:egpColor(8, vec(255, 0, 0))
   
    EGP:egpTriangleOutline(9, EGP:egpPos(7) + vec2(15, -7.5), EGP:egpPos(6) + vec2(-15, -7.5), EGP:egpPos(6) + vec2(0, 15 * sqrt(3) - 7.5))
    EGP:egpParent(9, 7)
    EGP:egpColor(9, vec(255, 0, 0))
   
    EGP:egpLine(10, EGP:egpPos(7), vec2(egpScrW(Dri), egpScrH(Dri)))
    EGP:egpParent(10, 7)
    EGP:egpColor(10, vec(0, 255, 0))
   
    EGP:egpLine(11, EGP:egpPos(6), vec2(-egpScrW(Dri), egpScrH(Dri)))
    EGP:egpParent(11, 6)
    EGP:egpColor(11, vec(0, 255, 0))
}
 
EGP:egpSetText(3, "SPD: " + round(toUnit("knots", Base:vel():length())))#+" kts")
EGP:egpSetText(4, "THROT: " + Thr)#+"%") wtf how does this add ops?
 
if(changed(Stall))
{
    EGP:egpAlpha(5, Stall * 255)
   
    if(Stall)
    {
        P:soundPlay(4, 1, "hl1/fvox/warning.wav")
        P:soundPlay(5, 0.276, "buttons/blip2.wav")
    }
}
if(changed(Side))
{
    EGP:egpColor(8, vec(255, 255 * !Side, 255 * !Side))
    EGP:egpColor(9, vec(255, 255 * Side, 255 * Side))
}
#EGP
 
if(changed(Alt)){
    EyePod["Enable", number] = !Alt
}
 
# Good controls
Base:applyAngForce((ang(clamp(EyePod["Y", number] * 0.2, -2, 2), (A - D) * 0.7, clamp(EyePod["X", number] * 0.2, -5, 5)) * Base:mass() * clamp(Vel:x()/10, 0, 150)) + ((-Base:angVel() * Base:mass()) * (clamp(Vel:x()/600, 0, 3))))
#print(4, toString(EyePod["X", number] * 0.2))
#Gay Controls (inverts Y, and does other GAY things)
#Base:applyAngForce((ang( -EyePod["Y", number] * 0.1,  -EyePod["X", number] * 0.4, (D - A) * 0.4) * Base:mass() * Vel:x()/10) + (( -Base:angVel() * Base:mass()) * (clamp(Vel:x()/600, 0, 5))))
 
if(W | S)
{
    Thr  += (W - S)
}
Thr = clamp(Thr, 0, 100)
 
Base:applyForce(Base:forward() * Thr/10 * Base:mass())
 
Afterburning = Thr > 70
if(changed(Afterburning))
{
    if(Afterburning)
    {
        holoCreate(1)
        holoModel(1, "models/effects/muzzleflash/minigunmuzzle.mdl")
        holoParent(1, Base)
        holoPos(1, Base:toWorld(vec(-70, 0, 5)))
        holoDisableShading(1, 1)
       
        for(I = 2, 6)
        {
            holoCreate(I)
            holoModel(I, "models/buildables/sentry3_rockets.mdl")
            holoParent(I, Base)
            holoPos(I, Base:toWorld(vec(-100 - I, 0, 5)))
            holoAlpha(I, 0)
            holoAng(I, Base:toWorld(ang(0, 0, 360/I)))
        }
       
        Base:soundPlay(6, 0, "thrusters/jet02.wav")
        EGP:egpColor(4, vec(255, 150, 50))
    }
    else
    {
        for(I = 1, 6)
        {
            holoDelete(I)
        }
        soundStop(6, 1)
        EGP:egpColor(4, vec(0, 255, 0))
    }
}
 
holoAng(1, Base:toWorld(ang(180, 0, Fire * 99.123)))
holoScale(1, vec((Thr / 100) * 1.5, 1, 1))
 
if(changed(Active))
{
    if(Active)
    {
        Base:soundPlay(1, 0, "thrusters/jet03.wav")
        Base:soundPlay(2, 0, "thrusters/jet04.wav")
    }
    else
    {
        soundStop(1, 1)
        soundStop(2, 1)
        Thr = 0
    }
}
 
soundPitch(1, clamp(Vel:x()/15, 0, 135))
soundPitch(2, Thr)
 
 
if(M1 & propCanCreate() & !Wait)
{
    propSpawnEffect(0)
   
    Prop = propSpawn("models/props_phx/amraam.mdl", Base:toWorld(vec(60, -35 + (Side * 70), 0)), Base:toWorld(ang(0, 0, 0)), 0)
    Prop:propGravity(0)
    Prop:propDrag(0)
    Prop:setAlpha(0)
    Prop:setTrails(0.5, 10, 1, "trails/smoke", vec(255, 255, 255), 255)
    Prop:applyForce(Prop:forward() * 10000 * Prop:mass())
    Prop:soundPlay(4, 0, "thrusters/rocket04.wav")
    Prop:setMass(5000)
   
    Rockets:pushEntity(Prop)
   
    Wait = 1
    timer("wait", 150)
    Side = !Side
}
 
if(clk("wait"))
{
    Wait = 0
}
 
rangerFilter(Rockets)
foreach(K, Rocket:entity = Rockets)
{
    RRanger = rangerOffset(200, Rocket:toWorld(vec(0, 0, 0)), Rocket:vel())
   
    if(RRanger:hit())
    {
        Rockets:remove(K)
        Rocket:propBreak()
    }
}
 
for(Item = 1, Rockets:count())
{
    if(!Rockets[Item, entity]:isValid())
    {
        Rockets:remove(Item)
    }  
}

#[
#EXPIRIMENTAL FLARES
if(changed(Spc)&Spc){
    P1 = propSpawn("models/sprops/rectangles/size_60/rect_60x108x3.mdl",Base:toWorld(vec(0,40,0)),Base:toWorld(ang(0,0,90)),0)
    P2 = propSpawn("models/sprops/rectangles/size_60/rect_60x108x3.mdl",Base:toWorld(vec(0,-40,0)),Base:toWorld(ang(0,0,90)),0)
    P3 = propSpawn("models/sprops/rectangles/size_54/rect_54x78x3.mdl",Base:toWorld(vec(-70,0,0)),Base:toWorld(ang(0,90,90)),0)
    
    P1:setMass(50)
    P2:setMass(50)
    P3:setMass(50)
    
    P1:applyForce(-P1:up()*P1:mass()*2000)
    P2:applyForce(P2:up()*P2:mass()*2000)
    P3:applyForce(-P3:up()*P3:mass()*2000)
    
    Flares:pushEntity(P1)
    Flares:pushEntity(P2)
    Flares:pushEntity(P3)
}
foreach(F, Flare:entity = Flares){
    timer("flare"+F,3000)
    if(clk("flare"+F)){
        Flares:remove(F)
        Flare:propBreak()
        stoptimer("flare"+F)
    }   
}
