@name Swing Copters
@persist [E P D]:entity Pol Vel Pos Av Plng Hv Pg Bn By
if(first() | duped() | dupefinished())
{
    E = entity()
    P = E:isConstrainedTo()
    if(P:isVehicle())
    {
        runOnTick(1)
        
        #Body
        local BH = holoCreate(1,P:toWorld(vec(0,125,15)),vec(1.5),P:toWorld(ang(0,0,0)))
        holoModel(1,"hq_rcylinder_thick")
        holoColor(1,vec(255,150,25))
        holoDisableShading(1,1)
        holoEntity(1):soundPlay("heli",0,"vehicles/helicopter/helicopter_loop09louder.wav")
        soundPitch("heli",200)
        
        #Helmet Top
        holoCreate(2,BH:toWorld(vec(0,0,5)),vec(1.75),BH:angles())
        holoModel(2,"hq_dome")
        holoColor(2,vec(50,200,50))
        holoDisableShading(2,1)
        holoParent(2,1)
        
        #Helmet Rim
        holoCreate(3,BH:toWorld(vec(0,0,4.75)),vec(1.8),BH:angles())
        holoModel(3,"hq_torus")
        holoColor(3,vec(45,175,45))
        holoDisableShading(3,1)
        holoParent(3,1)
        
        #Left Eye
        holoCreate(4,BH:toWorld(vec(8,3.25,4)),vec(1),BH:angles())
        holoModel(4,"hq_sphere")
        holoDisableShading(4,1)
        holoParent(4,1)
        
        #Left Pupil
        holoCreate(5,holoEntity(4):pos()+holoEntity(4):forward():rotateAroundAxis(BH:right(),45)*5,vec(0.25),BH:angles())
        holoModel(5,"hq_sphere")
        holoColor(5,vec())
        holoParent(5,4)
        
        #Right Eye
        holoCreate(6,BH:toWorld(vec(8,-3.25,4)),vec(1),BH:angles())
        holoModel(6,"hq_sphere")
        holoDisableShading(6,1)
        holoParent(6,1)
        
        #Right Pupil
        holoCreate(7,holoEntity(6):pos()+holoEntity(6):forward():rotateAroundAxis(BH:right(),45)*5,vec(0.25),BH:angles())
        holoModel(7,"hq_sphere")
        holoColor(7,vec())
        holoParent(7,6)
        
        #Mouth
        holoCreate(8,BH:toWorld(vec(2.5,0,-4)),vec(1.25),BH:angles())
        holoModel(8,"hq_torus")
        holoColor(8,vec(216.75,85,21.2))
        holoDisableShading(8,1)
        holoParent(8,1)
        
        #Left appendage
        holoCreate(9,BH:toWorld(vec(0,9.75,-2)),vec(0.5),BH:angles())
        holoModel(9,"hq_sphere")
        holoDisableShading(9,1)
        holoParent(9,1)
        
        #Right appendage
        holoCreate(10,BH:toWorld(vec(0,-9.75,-2)),vec(0.5),BH:angles())
        holoModel(10,"hq_sphere")
        holoDisableShading(10,1)
        holoParent(10,1)
        
        #Propellers Center
        holoCreate(11,BH:toWorld(vec(0,0,24)),vec(0.5),BH:angles())
        holoModel(11,"hq_sphere")
        holoDisableShading(11,1)
        holoParent(11,1)
        
        #Propeller Left Prop
        holoCreate(12,holoEntity(11):toWorld(vec(0,24,0)),vec(0.65,3,0.65),BH:angles())
        holoModel(12,"hq_sphere")
        holoDisableShading(12,1)
        holoParent(12,11)
        
        #Propeller Left Prop
        holoCreate(13,holoEntity(11):toWorld(vec(0,-24,0)),vec(0.65,3,0.65),BH:angles())
        holoModel(13,"hq_sphere")
        holoDisableShading(13,1)
        holoParent(13,11)
        
        #Left Wall
        holoCreate(14,P:toWorld(vec(174,275,81)),vec(2,6,22),BH:angles())
        holoMaterial(14,"models/props_canal/metalcrate001d")
        holoDisableShading(14,1)
        holoParent(14,P)
        
        #Right Wall
        holoCreate(15,P:toWorld(vec(-174,275,81)),vec(2,6,22),BH:angles())
        holoMaterial(15,"models/props_canal/metalcrate001d")
        holoDisableShading(15,1)
        holoParent(15,P)
        
        #Right Beam
        holoCreate(16,P:toWorld(vec(0,275,0)),vec(1),BH:angles())
        holoModel(16,"models/props_junk/iBeam01a.mdl")
        holoMaterial(16,"models/props_pipes/pipeset_metal02")
        holoColor(16,vec(112,255,112))
        holoDisableShading(16,1)
        holoParent(16,P)
        
        #Left Beam
        holoCreate(17,P:toWorld(vec(0,275,0)),vec(1),BH:angles())
        holoModel(17,"models/props_junk/iBeam01a.mdl")
        holoMaterial(17,"models/props_pipes/pipeset_metal02")
        holoColor(17,vec(112,255,112))
        holoDisableShading(17,1)
        holoParent(17,P)
        
        #Left Hammer
        
        #Right Hammer
    }else
    {
        error("Spawn this E2 on a chair.")
    }
}

holoAng(11,holoEntity(11):toWorld(ang(0,Hv,0)))

D = P:driver()
DV = changed(D:isValid())
CPLNG = changed(Plng)
if(D:isValid())
{
    local K = D:keyAttack1()
    if(Plng)
    {
        if(CPLNG)
        {
            soundPlay("rl",0.2,"buttons/button24.wav")
            soundPitch("rl",150)
            
            Bn = 216
            By = random(-60,60)
        }
        
        if(Pg < 1)
        {
            Pg += 0.00625
            
            Hv = 20+(Pg*5)
            
            soundPitch("heli",200+(Pg*35))
            soundVolume("heli",0.0625+(Pg*0.0625))
        }
        
        if(changed(K)&K)
        {
            Pol = !Pol
        }
        Vel += (Pol ? 0.025 : -0.025) * Pg
        Pos += clamp(Vel,-2.75,2.75)*5.5 * Pg
        Av += ((Pol ? 30 : -30)-Av)/15 * Pg
        
        holoPos(1,P:toWorld(vec(clamp(Pos,-150,150),275,Pg*15)))
        holoAng(1,P:toWorld((Pg * ang(0,Av,clamp(-Av/4,-15,15))) - ang(0,90,0)))
        
        if(!inrange(Pos,-150,150))
        {
            propSpawn("models/props_junk/propane_tank001a.mdl",holoEntity(1):pos(),1):propBreak()
            Plng = 0
        }
        
        if(Bn > -48)
        {
            Bn -= 0.75 * Pg
            
            holoPos(16,P:toWorld(vec(By+175,275,Bn)))
            holoAlpha(16,clamp(1.75*(231-abs(Bn*1.25)),0,255))
            
            holoPos(17,P:toWorld(vec(By-175,275,Bn)))
            holoAlpha(17,clamp(1.75*(231-abs(Bn*1.25)),0,255))
        }else
        {
            Bn = 216
            By = random(-60,60)
        }
    }else
    {
        if(CPLNG | DV)
        {
            soundPitch("heli",200)
            soundVolume("heli",0.0625)
            
            soundPlay("strt",0.5,"buttons/button14.wav")
            soundPitch("strt",50)
            
            Pg = 0
            Pol = 0
            Pos = 0
            Av = 0
            Vel = 0
            Bn = 0
            Hv = 20
            
            holoAlpha(16,0)
            holoAlpha(17,0)
            
            P:hintDriver("Press Mouse 1 to begin!",10)
        }
        
        Plng = K
        
        holoPos(1,P:toWorld(vec(0,275,0)))
        holoAng(1,P:toWorld(ang(0,-90,0)))
    }
}else
{
    if(DV)
    {
        soundPitch("heli",200)
        soundVolume("heli",0.0625)
        
        Plng = 0
        Pg = 0
        Pol = 0
        Pos = 0
        Av = 0
        Vel = 0
        Bn = 0
        Hv = 20
        
        holoAlpha(16,0)
        holoAlpha(17,0)
    }
    Vel+=5
    holoPos(1,P:toWorld(vec(cos(Vel)*15,275,0)))
    holoAng(1,P:toWorld(ang(0,sin(Vel+35)*-24-90,sin(Vel+35)*7.5)))
}


