@name Scout Heli
@inputs [Pod Cam EyePod]:wirelink
@persist Ignition UpMul RUpMul MulDiv HoloTurnVel View
@persist [Data]:table
@persist CA:angle CP:vector
@persist IDS:array
@model models/hunter/blocks/cube2x2x2.mdl
if(first())
{
    E = entity()
    
    setMass(128*250)
    runOnTick(1)
    #E:propFreeze(1)
    E:propGravity(1)
    #E:setColor(255,255,255,0)
    #E:propNotSolid(0)
    
    IDS=array("STEAM_0:1:19680709","STEAM_0:0:33994222","STEAM_0:1:46794844","STEAM_0:0:32759932","STEAM_0:1:39388754","STEAM_0:1:19926533")
    
    Data["MouseSpeed",number] = 0.8
    
    function entity:turnTo(Tarang:angle)
    {
        V = This:toLocal(rotationVector(quat(Tarang)/quat(This))+This:pos())
        This:applyTorque((100*V - 15*This:angVelVector())*This:inertia()/3)
    }
    function entity:goto(Vector:vector)
    {
        This:applyForce(((Vector-This:pos())*5-This:vel())*This:mass())   
    }
    function number entity:cm()
    {
        local Mass = 0
        for(I=1,This:getConstraints():count())
        {
            Mass+=This:getConstraints()[I,entity]:mass()
        }
        return This:mass()+Mass
    }

    UpMul = E:cm()*9
    #UpMul = E:cm()*15.5
    #UpMul = E:cm()*18.25
    
    holoCreate(50)
    holoModel(50,"hq_cone")
    holoAng(50,E:toWorld(ang(-90,90,0)))
    holoPos(50,E:toWorld(vec(0,0,50)))
    holoParent(50,E)
    
    #phoenix_storms/FuturisticTrackRamp_1-2
    
    holoCreate(2,E:toWorld(vec(0,0,65)))
    holoCreate(3,holoEntity(2):toWorld(vec(150,0,4)))
    holoCreate(4,holoEntity(2):toWorld(vec(-150,0,4)))
    
    holoAng(3,E:toWorld(ang(89,0,0)))
    holoAng(4,E:toWorld(ang(89,180,0)))
    
    holoModel(2,"hq_rcylinder")
    holoModel(3,"hq_cylinder")
    holoModel(4,"hq_cylinder")
    
    holoColor(3,vec(75))
    holoColor(4,vec(75))
    
    holoMaterial(2,"phoenix_storms/FuturisticTrackRamp_1-2")
    holoMaterial(3,"models/shiny")
    holoMaterial(4,"models/shiny")
    
    holoScale(2,vec(1,1,0.5))
    holoScale(3,vec(0.2,0.8,301/12))
    holoScale(4,vec(0.2,0.8,301/12))
    
    holoParent(2,E)
    holoParent(3,2)
    holoParent(4,2)
    
    #[
    holoCreate(1000)
    holoModel(1000,E:model())
    holoAlpha(1000,75)
    holoParent(1000,E)
    holoCreate(1001)
    holoModel(1001,E:model())
    holoAlpha(1001,75)
    holoParent(1001,E)
    holoScale(1001,vec(-0.99))
    ]#
}

Vel = E:vel():z()

#Pod Controls
W = Pod["W",number]
A = Pod["A",number]
S = Pod["S",number]
D = Pod["D",number]
R = Pod["R",number]
F = Pod["Light",number]
Active = Pod["Active",number]
Alt = Pod["Alt",number]
Space = Pod["Space",number]
Shift = Pod["Shift",number]
Seat = Pod["Entity",entity]
Driver = Pod["Entity",entity]:driver()

#EyePod Controls
MouseX = -EyePod["X",number]
MouseY = EyePod["Y",number]

if(changed(Alt)&Alt)
{
    View = !View
    print(View)
}

Cam["Activated",number]=!View
#Cam["Parent",entity]=E
if(View)
{
    Cam["Position",vector]=Pod["Entity",entity]:toWorld(vec(1,0,45))
    Cam["Angle",angle]=E:toWorld(ang(0,-90,0))
}else
{
    CP = E:toWorld(vec(0,400,0)):setZ(0)+vec(0,0,200)
    Cam["Position",vector]=E:toWorld(vec(0,400,0)):setZ(0)+vec(0,0,200)
    CA = (E:pos()-CP):toAngle():setPitch(0)+ang(15,0,0)
    Cam["Angle",angle]=(E:pos()-CP):toAngle():setPitch(0)+ang(15,0,0)
}
#clamp(T:pos():distance(E:pos())/10,10,100)

if(changed(Active))
{
    Ignition = Active
}

if(Ignition)
{
    if(changed(Ignition))
    {
        soundPlay("ignition",0,"NPC_AttackHelicopter.Rotors")
        soundVolume("ignition",2)
    }
    if(MulDiv < 100)
    {
        MulDiv+=0.125
    }
}else
{
    if(changed(Ignition))
    {
        soundStop("ignition")
    }
    if(MulDiv > 0)
    {
        MulDiv-=0.25
    }
}

if(changed(Active)&Active)
{
    for(I=1,IDS:count())
    {
        if(Driver:steamID()==IDS[I,string])
        {
            Valid = 1
            break
        }else
        {
            Valid = 0
        }
    }
    if(Valid)
    {
        Seat:hintDriver("Welcome, "+Driver:name(),3)
        print(Driver:name()+" is entering and is allowed into your vehicle")
    }else
    {
        Seat:hintDriver("You're not welcome on this vehicle...",3)
        print(Driver:name()+" is entering your vehicle, but is not allowed. Terminating user.")
        Seat:killPod()
    }
}

RUpMul = (UpMul/100)*MulDiv

soundPitch("ignition",MulDiv*1.1)

if(MulDiv>0)
{
    holoAng(2,holoEntity(2):toWorld(ang(0,MulDiv,0)))
}

P = MouseY*Data["MouseSpeed",number]
Y = (A-D)*8
R = MouseX*Data["MouseSpeed",number]

Ang = ang(R,Y,P)
FinalAng = (((Ang-E:angVel()/5)*350)*MulDiv/100)

applyAngForce(FinalAng*(E:cm()/128))
    
OffsetUp = (((W-S)*(300+(Shift*125)))*E:cm()/128)*MulDiv/100
VelStop = (-E:vel():setZ(0)*20*(E:vel():length()/110))*Space*5+1
E:applyForce(VelStop+E:up()*(RUpMul+OffsetUp))

if(duped()|dupefinished())
{
    reset()
}
