@name Wash Doges Hype Train
@persist [E P M]:entity Rdy O:vector Jmp Clr:array
@model models/props_trainstation/train001.mdl
if(first())
{
    runOnTick(1)
    
    E = entity()
    E:propFreeze(0)
    E:setMass(50000)
    
    function entity:goto(Vector:vector)
    {
        This:applyForce(((Vector-This:pos())*10-This:vel())*This:mass())   
    }
    
    holoCreate(100,E:toWorld(vec(0,E:boxSize():y()/1.95,-75)))
    holoModel(100,"models/nova/airboat_seat.mdl")
    holoAlpha(100,100)
    holoParent(100,E)
    
    holoCreate(101,E:toWorld(vec(0,-E:boxSize():y()/2,0)))
    holoAlpha(101,0)
    holoParent(101,E)
    #holoEntity(101):setTrails(0,3000,3,"trails/smoke",vec(255),255)
    
    local Ar = array("models/sprops/misc/alphanum/alphanum_w.mdl","models/sprops/misc/alphanum/alphanum_l_a.mdl","models/sprops/misc/alphanum/alphanum_l_t.mdl","models/sprops/misc/alphanum/alphanum_l_c.mdl","models/sprops/misc/alphanum/alphanum_l_h.mdl","models/sprops/misc/alphanum/alphanum_underscore.mdl","models/sprops/misc/alphanum/alphanum_d.mdl","models/sprops/misc/alphanum/alphanum_l_o.mdl","models/sprops/misc/alphanum/alphanum_l_g.mdl","models/sprops/misc/alphanum/alphanum_l_s.mdl","","models/sprops/misc/alphanum/alphanum_h.mdl","models/sprops/misc/alphanum/alphanum_l_y.mdl","models/sprops/misc/alphanum/alphanum_l_p.mdl","models/sprops/misc/alphanum/alphanum_l_e.mdl","","models/sprops/misc/alphanum/alphanum_t.mdl","models/sprops/misc/alphanum/alphanum_l_r.mdl","models/sprops/misc/alphanum/alphanum_l_a.mdl","models/sprops/misc/alphanum/alphanum_l_i.mdl","models/sprops/misc/alphanum/alphanum_l_n.mdl")
    for(I = 1, 22)
    {
        holoCreate(I,E:toWorld(vec(0,(50 * I)-505,200)))
        holoAng(I,E:toWorld(ang(0,-90,0)))
        holoModel(I,Ar[I,string])
        if(Ar[I,string]=="")
        {
            holoAlpha(I,0)
        }
        holoMaterial(I,"models/debug/debugwhite")
        holoScale(I,vec(5))
        holoDisableShading(I,1)
        holoParent(I,E)
    }
    
    timer("clr",300)
    timer("snd",15)
    
    Clr = array(vec(255,0,0),vec(0,255,0),vec(0,255,255),vec(255,255,0),vec(255,128,0),vec(255,0,255))
    
    rangerHitWater(1)
    rangerFilter(E)
    rangerPersist(1)
}

if(clk("clr"))
{
    stoptimer("clr")
    timer("clr",50)
    for(I = 1, 22)
    {
        holoColor(I,Clr[randint(1,Clr:count()),vector])
    }
}

if(clk("snd"))
{
    stoptimer("snd")
    timer("snd",7800)
    soundPlay("train",7.7,"ambient/alarms/train_horn2.wav")
}

if(Rdy)
{
    Dri = P:driver()
    Active = Dri:isValid()
    W = Dri:keyPressed("W")
    A = Dri:keyPressed("A")
    S = Dri:keyPressed("S")
    D = Dri:keyPressed("D")
    Shift = Dri:keyPressed("LSHIFT")
    Space = Dri:keyPressed("SPACE")
    M1 = Dri:keyAttack1()
    
    RD = rangerOffset(150,E:pos(),vec(0,0,-1))
    if(RD:hit()&!Jmp)
    {
        E:goto(RD:pos() + vec(0,0,150) + O)
    }
    
    if(changed(Active))
    {
        if(Active)
        {
            cameraCreate(1)
            cameraToggle(1,1,P)
            holoCreate(102)
            holoModel(102,"hq_sphere")
            holoColor(102,vec4(255,100,0,150))
            holoScale(102,vec(3))
            holoVisible(102,players(),0)
            holoVisible(102,Dri,1)
        }else
        {
            cameraRemove(1)
            holoDelete(102)
        }
    }
    
    local Ang = -E:angles()*500
    applyAngForce((ang(-E:angles():pitch() * RD:hit(),(A-D)*6,-E:angles():roll() * RD:hit())*500 + (-E:angVel() * RD:hit() * 25) )* E:mass())
    
    if(Active)
    {
        cameraPos(1,E:toWorld(vec(0,0,300))-Dri:eye()*750)
        cameraAng(1,Dri:eyeAngles())
        
        local ER = rangerOffset(100000,E:pos()+vec(0,0,300),Dri:eye())
        holoPos(102,ER:pos()-Dri:eye()*10)
        if(M1&!M:isValid())
        {
            M = propSpawn("models/props_phx/amraam.mdl",E:pos()+vec(0,0,300)-Dri:eye()*300,Dri:eyeAngles(),1)
            M:setTrails(300,0,1,"trails/laser",vec(150,0,150),255)
            M:setColor(0,0,0,0)
        }
        
        Jmp = changed(Space) & Space
        if(Jmp)
        {
            applyForce(vec(0,0,1000 * RD:hit()) * E:mass())
        }
        
        O = E:right():setZ(0) * (S-W) * (200 * (1+(Shift*3)))
    }
    
    if(E:isFrozen())
    {
        E:propFreeze(0)
    }
    
    if(M:isValid())
    {
        local MR = rangerOffset(330,M:pos(),M:forward())
        if(MR:hit())
        {
            M:propBreak()
        }else
        {
            M:setPos(M:toWorld(vec(300,0,0)))
        }
    }
}else
{
    if(findCanQuery())
    {
        findByClass("prop_vehicle_prisoner_pod")
        findSortByDistance(holoEntity(100):pos())
        if(find():owner() == owner() & find():pos():distance(holoEntity(100):pos()) < 300 & find():model() == "models/nova/airboat_seat.mdl")
        {
            P = find()
            P:setPos(holoEntity(100):pos())
            P:setAng(holoEntity(100):angles())
            timer("p",100)
        }
    }
    
    if(clk("p"))
    {
        stoptimer("p")
        P:parentTo(E)
        holoDelete(100)
        Rdy = 1
    }
}
