@name Roflcopter
@persist [E P M HE]:entity FC FM WM WTM B
@persist [P2H_Mod P2H_Color P2H_Mat P2H_Pos P2H_Ang]:array P2H_Int P2H_Offset P2H_Ready
if(first())
{
    runOnTick(1)
    
    entity():setColor(0,0,0,0)
    
    E = entity():isConstrainedTo()
    if(E:isValid())
    {
        E:setMass(50000)
        
        if(E:isVehicle())
        {
            selfDestruct()
        }else
        {
            P = E:isConstrainedTo()
        }
    }else
    {
        selfDestruct()
    }
    
    FC = 9
    
    E:soundPlay("ign",0,"NPC_AttackHelicopter.Rotors")
    soundPitch("ign",0)
    
    HE = holoCreate(1,E:toWorld(vec(-25,0,5)))
    holoAng(1,E:toWorld(ang(180,0,0)))
    holoParent(1,E)
    holoAlpha(1,0)
    
    while(perf())
    {
        holoCreate(2,HE:toWorld(vec(-1.1999,0.002,-95)),vec(1),HE:toWorld(ang(0,-90,0)))
        holoAlpha(2,0)
        holoParent(2,E)
        
        local R = array("models/sprops/misc/alphanum/alphanum_r.mdl","models/sprops/misc/alphanum/alphanum_o.mdl","models/sprops/misc/alphanum/alphanum_f.mdl","models/sprops/misc/alphanum/alphanum_l.mdl","models/sprops/misc/alphanum/alphanum_colon.mdl","models/sprops/misc/alphanum/alphanum_l.mdl","models/sprops/misc/alphanum/alphanum_o.mdl","models/sprops/misc/alphanum/alphanum_l.mdl","models/sprops/misc/alphanum/alphanum_colon.mdl","models/sprops/misc/alphanum/alphanum_r.mdl","models/sprops/misc/alphanum/alphanum_o.mdl","models/sprops/misc/alphanum/alphanum_f.mdl","models/sprops/misc/alphanum/alphanum_l.mdl")
        for(I=3,15)
        {
            local N = I-2
            holoCreate(I,holoEntity(2):toWorld(vec(N*15-105,0,0)),vec(1),holoEntity(2):toWorld(ang(180,0,0)))
            holoModel(I,R[N,string])
            holoMaterial(I,"models/debug/debugwhite")
            holoDisableShading(I,1)
            holoParent(I,2)
        }
        
        holoCreate(16,HE:toWorld(vec(90,-5,-52.5)),vec(1),HE:toWorld(ang()))
        holoAlpha(16,0)
        holoParent(16,E)
        
        local R = array("models/sprops/misc/alphanum/alphanum_l.mdl","models/sprops/misc/alphanum/alphanum_o.mdl","models/sprops/misc/alphanum/alphanum_l.mdl")
        for(I=17,19)
        {
            N = I-16
            holoCreate(I,holoEntity(16):toWorld(vec(0,0,N*15-30)),vec(1),HE:toWorld(ang(180,0,0)))
            holoModel(I,R[N,string])
            holoMaterial(I,"models/debug/debugwhite")
            holoDisableShading(I,1)
            holoParent(I,16)
        }
    }
}

if(first())
{
    P2H_Int = 0
    P2H_Offset = 20
    P2H_Mod = array("models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_i.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_i.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_rbracket.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_i.mdl","models/sprops/misc/alphanum/alphanum_i.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_rbracket.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_equal.mdl","models/sprops/misc/alphanum/alphanum_equal.mdl","models/sprops/misc/alphanum/alphanum_equal.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_crt.mdl","models/sprops/misc/alphanum/alphanum_div.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_div.mdl")
    P2H_Color = array(vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255),vec4(255,255,255,255))
    P2H_Mat = array("models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite","models/debug/debugwhite")
    P2H_Pos = array(vec(23.046,16.5318,-3.7986),vec(10.546,16.5502,-3.7986),vec(-1.954,16.5686,-3.7986),vec(-14.454,16.587,-3.7986),vec(-26.954,16.6054,-3.7986),vec(-39.454,16.6238,-3.7986),vec(-51.9539,16.6422,-3.7986),vec(-26.954,16.6051,-6.7986),vec(1.546,16.5643,-7.5882),vec(-1.954,16.5685,-6.7986),vec(-7.954,16.578,-7.5882),vec(-17.454,16.5916,-7.5882),vec(-26.954,16.6053,-7.5882),vec(-36.454,16.619,-7.5882),vec(-45.954,16.6327,-7.5882),vec(-54.3541,16.6454,-22.7402),vec(-63.9539,16.6596,5.0389),vec(-64.0027,-16.4711,5.0393),vec(-52.0027,-16.4893,-3.7981),vec(-39.5027,-16.5077,-3.7981),vec(-27.0028,-16.5261,-3.7981),vec(-14.5028,-16.5445,-3.7981),vec(-2.0028,-16.5629,-3.7981),vec(10.4972,-16.5813,-3.7981),vec(22.9972,-16.5997,-3.7981),vec(1.4972,-16.569,-7.5878),vec(-2.0028,-16.5629,-6.7981),vec(-27.0028,-16.5259,-6.7981),vec(-17.5028,-16.5405,-7.5878),vec(-8.0028,-16.5548,-7.5878),vec(-27.0028,-16.5262,-7.5878),vec(-36.5027,-16.5119,-7.5878),vec(-46.0027,-16.4976,-7.5878),vec(-54.4029,-16.4859,-22.7398),vec(10.9972,-16.5833,-7.5878),vec(21.7972,-16.5998,-20.0941),vec(31.2985,-16.4073,-36.0247),vec(51.2502,-0.0748,-52.5),vec(61.7502,-0.0902,-52.5),vec(72.2502,-0.1056,-52.5),vec(-48.803,-16.4941,-37.0983),vec(-40.4034,-16.5065,-52.6801),vec(-40.3546,16.6239,-52.6806),vec(-48.7542,16.6367,-37.0987),vec(-18.2721,-16.2144,-75.8896),vec(-30.772,-16.1845,-75.8896),vec(-5.7721,-16.2444,-75.8896),vec(6.7279,-16.2743,-75.8896),vec(19.2278,-16.3042,-75.8896),vec(31.7278,-16.3342,-75.8896),vec(43.7272,-16.3633,-69.4106),vec(43.7752,16.2327,-69.411),vec(31.7758,16.2386,-75.89),vec(19.2758,16.2455,-75.89),vec(6.7758,16.2523,-75.89),vec(-18.2242,16.2661,-75.89),vec(-5.7242,16.2592,-75.89),vec(-30.7242,16.2729,-75.89),vec(-1.1999,0.002,-78.6998),vec(31.3467,16.3141,-36.0251),vec(11.046,16.5506,-7.5882),vec(21.846,16.535,-20.0945))
    P2H_Ang = array(ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.9157,179.9999),ang(0,179.916,-0.0018),ang(0,-0.0824,0.002),ang(0,179.916,-0.0018),ang(0,-0.0824,0.002),ang(0,-0.0824,0.002),ang(0,-0.0824,0.002),ang(0,-0.0824,0.002),ang(0,-0.0824,0.002),ang(0,-0.0803,179.9982),ang(0,-0.0842,179.9984),ang(0,-0.0845,-179.9999),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,179.9156,-179.9984),ang(0,-0.0863,-0.0035),ang(0,179.9153,0.0034),ang(0,179.9153,0.0034),ang(0,-0.0863,-0.0035),ang(0,-0.0863,-0.0035),ang(0,-0.0863,-0.0035),ang(0,-0.0863,-0.0035),ang(0,-0.0863,-0.0035),ang(0,-0.0884,-179.9997),ang(0,-0.0863,-0.0035),ang(0,-0.0879,0.0001),ang(0,-0.0844,0.0001),ang(0,-0.084,-179.9999),ang(0,-0.084,-179.9999),ang(0,-0.084,-179.9999),ang(0,-0.0847,0.0001),ang(0,-0.0847,0.0001),ang(0,-0.084,-0.0016),ang(0,-0.084,-0.0016),ang(0,-0.1371,179.9969),ang(0,-0.1371,179.9969),ang(0,-0.1371,179.9969),ang(0,-0.1371,179.9969),ang(0,-0.1371,179.9969),ang(0,-0.1371,179.9969),ang(-0.0004,-0.1376,179.9985),ang(-0.0004,-0.0311,180),ang(0,-0.0316,-179.9984),ang(0,-0.0316,-179.9984),ang(0,-0.0316,-179.9984),ang(0,-0.0316,-179.9984),ang(0,-0.0316,-179.9984),ang(0,-0.0316,-179.9984),ang(0,-0.0845,-179.9999),ang(0,-0.0843,-0.0016),ang(0,-0.0824,0.002),ang(0,-0.0808,-0.0016))
}

if(!P2H_Ready)
{
    while(holoCanCreate() & perf() & P2H_Int < P2H_Mod:count())
    {
        P2H_Int++
        local P2H_TempInt = P2H_Int+P2H_Offset
        holoCreate(P2H_TempInt,HE:toWorld(P2H_Pos[P2H_Int,vector]),vec(1),HE:toWorld(P2H_Ang[P2H_Int,angle]))
        holoColor(P2H_TempInt,P2H_Color[P2H_Int,vector4])
        holoModel(P2H_TempInt,P2H_Mod[P2H_Int,string])
        holoMaterial(P2H_TempInt,P2H_Mat[P2H_Int,string])
        holoParent(P2H_TempInt,HE)
        holoDisableShading(P2H_TempInt,1)
    }
    P2H_Ready = P2H_Int >= P2H_Mod:count()
}

Dri = P:driver()
Active = P:driver():isValid()
if(Active)
{
    W = Dri:keyForward()
    Ak = 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()
    
    if(changed(Alt)&Alt)
    {
        WM = !WM
        P:hintDriver("Weapon Mode: "+toString(WM):replace("1","ON"):replace("0","OFF"),3)
    }
    
    FM+=0.0025
    
    if(WM)
    {
        if(!M:isValid())
        {
            if(M1&!B)
            {
                M = propSpawn("models/props_phx/amraam.mdl",Dri:shootPos()+Dri:eye()*250,Dri:eyeAngles(),1)
                M:setColor(0,0,0,0)
                M:setTrails(100,0,3,"trails/laser",vec(255),255)
                
                soundPlay("nwtms",1.835,"weapons/cow_mangler_main_shot.wav")
                
                WTM = 0
                
                B = 1
                timer("ub",1500)
            }elseif(changed(M2)&M2)
            {
                M = propSpawn("models/props_phx/amraam.mdl",Dri:shootPos()+Dri:eye()*250,Dri:eyeAngles(),1)
                M:setTrails(15,300,2,"trails/smoke",vec(255),150)
                
                soundPlay("wtms",1.8,"weapons/sentry_rocket.wav")
                
                WTM = 1
            }
        }
    }
}else
{
    FM-=0.0025
}
FM = clamp(FM,0,1)

if(clk("ub"))
{
    stoptimer("ub")
    B = 0
}

if(M:isValid())
{
    rangerFilter(array(E,P,Dri,M))
    local RD = rangerOffset(200-(100*WTM),M:pos(),M:forward())
    if(RD:hit()|(changed(R)&R))
    {
        WTM = 0
        
        M:propBreak()
    }else
    {
        if(WTM)
        {
            M:setPos(M:toWorld(vec(50,0,0)))
            
            local A = ((Dri:shootPos()+Dri:eye()*(M:pos():distance(Dri:shootPos())+1000))-M:pos()):toAngle()
            local B = M:toLocal(A)
            
            M:setAng(M:toWorld(B/10))
        }else
        {
            M:setPos(M:toWorld(vec(150,0,0)))
        }
    }
}

if(changed(FM))
{
    soundPitch("ign",FM*100)
}
holoAng(2,holoEntity(2):toWorld(ang(0,FM*25,0)))
holoAng(16,holoEntity(16):toWorld(ang(FM*25,0,0)))

E:applyForce((E:up()*(FC+((Spc-Shift)*4))-(E:vel()*vec(0.0025,0.0025,0.005)))*E:mass()*FM)
E:applyAngForce((ang((W-S)*30,(M1-M2)*60*!WM,(D-Ak)*30)-(E:angles()*ang(1.5,0,1.5))-E:angVel()*0.75)*E:mass()*FM)

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