@name HeliControl2
@inputs Pod:wirelink Prop:entity 
@outputs 
@persist FC FM Rotation Spin 
@trigger 
runOnTick(1)

if (first() | dupefinished()) {
    FC = 9
    
    holoCreate(1)
    holoModel(1,"models/sprops/mechanics/misc/ratchet_15t_l.mdl")
    holoPos(1,Prop:toWorld(vec(0,38,14)))
    holoAng(1,Prop:toWorld(ang(0,90,90)))
    holoParent(1,Prop)
    
    holoCreate(2)
    holoModel(2,"models/sprops/mechanics/misc/ratchet_15t_s.mdl")
    holoPos(2,Prop:toWorld(vec(5,35,10)))
    holoAng(2,Prop:toWorld(ang(0,90,90)))
    holoParent(2,Prop)
    
    holoCreate(3)
    holoModel(3,"models/sprops/mechanics/misc/ratchet_30t_s.mdl")
    holoPos(3,Prop:toWorld(vec(-5,38,14)))
    holoAng(3,Prop:toWorld(ang(0,90,90)))
    holoParent(3,Prop)
    
    holoCreate(4)
    holoModel(4,"models/xqm/helicopterrotor.mdl")
    holoPos(4,Prop:toWorld(vec(0,36,67)))
    holoAng(4,Prop:toWorld(ang(-90,0,180)))
    holoScale(4,vec(3,3,3))
    holoParent(4,Prop)
    holoClipEnabled(4,1,1)
    holoClip(4,vec(6,0,0),vec(1,0,0),0)
    
    holoCreate(5)
    holoModel(5,"models/xqm/helicopterrotor.mdl")
    holoPos(5,Prop:toWorld(vec(3,210,57)))
    holoAng(5,Prop:toWorld(ang(0,0,180)))
    holoScale(5,vec(0.6,0.6,0.6))
    holoParent(5,Prop)
    holoClipEnabled(5,1,1)
    holoClip(5,vec(1,0,0),vec(1,0,0),0)
}

local Seat = Pod["Entity",entity]
local Driver = Seat:driver()
local W = Driver:keyForward()
local A = Driver:keyLeft()
local S = Driver:keyBack()
local D = Driver:keyRight()
local R = Driver:keyReload()
local Mouse1 = Driver:keyAttack1()
local Mouse2 = Driver:keyAttack2()
local Space = Driver:keyJump()
local Shift = Driver:keySprint()
local Active = Driver:isPlayer()
local Ang = Driver:eyeAngles():yaw()

FM = clamp(FM,0,1)
Spin = clamp(Spin,20,115)

if (Active) {
    Spin += 0.3
    FM += 0.0035
    Rotation += Spin-20
    
    Prop:applyForce((Prop:up()*(FC+((Space-Shift)*4))-(Prop:vel()*vec(0.0025,0.0025,0.005)))*Prop:mass()*3.35*FM)
    Prop:applyAngForce((ang((Mouse1-Mouse2)*30,(A-D)*60,(W-S)*30)-(Prop:angles()*ang(1.5,0,1.5))-Prop:angVel()*0.75)*Prop:mass()*2.5*FM)
    
    holoAng(1,holoEntity(1):toWorld(ang(0,10*FM,0)))
    holoAng(2,holoEntity(2):toWorld(ang(0,30*FM,0)))
    holoAng(3,holoEntity(3):toWorld(ang(0,25*FM,0)))
    holoAng(4,Prop:toWorld(ang(-90,Rotation*FM,180)))
    holoAng(5,Prop:toWorld(ang(0,0,180+Rotation*FM)))
} else {
    Spin -= 0.25
    FM -= 0.0035
    Rotation -= FM
    
    holoAng(4,Prop:toWorld(ang(-90,Rotation*FM,180)))
    holoAng(5,Prop:toWorld(ang(0,0,180+Rotation*FM)))
}
#[
if (changed(Active)) {
    if (Active) {
        Prop:soundPlay(0,0,"vehicles/airboat/fan_blade_idle_loop1.wav")
        soundVolume(0,0.3)
        Prop:soundPlay(1,2,"vehicles/apc/apc_start_loop3.wav")
        soundStop(2)
    } 
    if(changed(!Active) & !Active){
        Prop:soundPlay(2,0,"vehicles/apc/apc_shutdown.wav")
    }
}

soundPitch(0,Spin + sqrt(Prop:vel():length()+100))
soundVolume(0,Spin-20)
