@name Cute machine
@persist [Snd Names]:array [Expl Hi Mdl Blln Trtl]:string [H E P]:entity [V]:vector
@persist Dri:entity Act W A S D R KZm Spc Alt Shift M1 M2 N Clk
if(first())
{
    E = entity()
    P = E:isConstrainedTo()
    if(!P:isVehicle())
    {
        print("Please spawn this e2 on a vehicle.")
        selfDestruct()
    }
    
    Blln = "models/player/items/pyro/taunticorn.mdl"
    Trtl = "models/props/de_tides/vending_turtle.mdl"
    Mdl = Trtl
    
    runOnTick(1)
    
    Snd = array("npc/headcrab/idle1.wav","npc/headcrab/idle2.wav","npc/headcrab/idle3.wav","npc/turret/different_turret07.wav","npc/zombie_poison/pz_breathe_loop2.wav")
    Expl = "npc/crow/pain1.wav"
    Hi = "npc/curiositysphere/hi.wav"
    
    Names = array("Cinematic Camera","Spectator E2","SwagDaddy","le 1337 haxor",">xddd","btw im a grill","")
    
    timer("idl",10)
    
    cameraRemoveAll()
}

Dri = P:driver()
Act = P:driver():isValid()
W = Dri:keyForward()
A = Dri:keyLeft()
S = Dri:keyBack()
D = Dri:keyRight()
R = Dri:keyReload()
KZm = Dri:keyZoom()
Spc = Dri:keyJump()
Alt = Dri:keyWalk()
Shift = Dri:keySprint()
M1 = Dri:keyAttack1()
M2 = Dri:keyAttack2()

if(changed(Act))
{
    if(Act)
    {
        if(Dri!=owner())
        {
            P:killPod()
        }
        H = holoCreate(1,P:toWorld(vec(0,50,10)))
        if(Mdl==Blln)
        {
            holoScale(1,vec(1.5))
        }else
        {
            holoScale(1,vec(2))
        }
        holoModel(1,Mdl)
        cameraCreate(1)
        cameraToggle(1,1,P)
    }else
    {
        holoDelete(1)
        cameraRemoveAll()
    }
}

if(Act)
{
    if(W|S)
    {
        N+=(W-S)*15
    }
    
    if(Mdl==Blln)
    {
        V = H:toWorld(vec((W-S)*4+((W|S)*Shift*3),(A-D)*2,0))
    }else
    {
        V = H:toWorld(vec((D-A)*2,(W-S)*4+((W|S)*Shift*3),0))
    }
    local R = rangerOffset(10^10,V+vec(0,0,1000*Alt),vec(0,0,-1))
    holoPos(1,R:pos()+vec(0,0,25-(22.5*(Mdl==Trtl))))
    holoAng(1,ang(0,cos(N)*15*(W|S),0)+(Dri:eyeAngles()*ang(0.25*(Mdl==Blln),1,0)-(ang(0,90,0)*(Mdl==Trtl))))
    
    local CR = rangerOffset(100,H:pos()+vec(0,0,25),-Dri:eye())
    cameraPos(1,CR:pos())
    cameraAng(1,Dri:eyeAngles())
    
    if(clk("idl"))
    {
        stoptimer("idl")
        timer("idl",random(7000,15000))
        
        H:soundPlay("idl",5,Snd[randint(1,Snd:count()),string])
        setName(Names[randint(1,Names:count()),string])
    }
    
    if(changed(M2)&M2)
    {
        stoptimer("idl")
        timer("idl",random(7000,15000))
        
        soundStop("idl")
        H:soundPlay("hi",0.6,Hi)
    }
    
    if(changed(M1)&M1)
    {
        stoptimer("idl")
        timer("idl",random(7000,15000))
        
        soundStop("idl")
        H:soundPlay("expl",0.35,Expl)
        timer("ded",500)
    }
    
    if(clk("ded"))
    {
        propSpawn("models/props_phx/amraam.mdl",H:pos(),1):propBreak()
        P:ejectPod()
    }
    
    if(changed(Spc)&Spc)
    {
        Clk = !Clk
        holoAlpha(1,!Clk*255)
    }
}
