@name Chaqua Hover John
@inputs P:entity
@persist [E Dri M]:entity PWrk VSV Ign VelLL Div
@model models/hunter/blocks/cube05x2x05.mdl
interval(20)

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

if(first())
{
    Div = 20/(500/33)
    
    E = entity()
    P = entity():isConstrainedTo()
    
    #noCollideAll(E, 0)
    
    E:setMass(5000)
    E:propFreeze(0)
    E:setColor(0, 0, 0, 0)
    
    rangerHitWater(1)
    rangerPersist(1)
    
    local Skin = vec(100, 75, 36)
    
    holoCreate(1, E:toWorld(vec(0, 12.5, 0)), vec(2.5, 2.5, 3), E:toWorld(ang(90, 90, 0)))
    holoModel(1, "hq_cylinder")
    holoDisableShading(1, 1)
    holoColor(1, Skin)
    holoParent(1, E)
    
    holoCreate(2, holoEntity(1):toWorld(vec(-1, 0, -35)), vec(2.5, 2.5, 3), holoEntity(1):toWorld(ang(3, 0, 0)))
    holoModel(2, "hq_cylinder")
    holoDisableShading(2, 1)
    holoColor(2, Skin)
    holoParent(2, 1)
    
    holoCreate(3, holoEntity(2):toWorld(vec(-1, 0, -35)), vec(2.5, 2.5, 3), holoEntity(2):toWorld(ang(3, 0, 0)))
    holoModel(3, "hq_cylinder")
    holoDisableShading(3, 1)
    holoColor(3, Skin)
    holoParent(3, 2)
    
    holoCreate(4, holoEntity(3):toWorld(vec(0, 0, -20)), vec(2.75), holoEntity(3):toWorld(ang()))
    holoModel(4, "hq_sphere")
    holoDisableShading(4, 1)
    holoColor(4, vec(166, 90, 137))
    holoParent(4, 3)
    
    holoCreate(5, E:toWorld(vec(15, 32, -5)), vec(3.5))
    holoModel(5, "hq_sphere")
    holoDisableShading(5, 1)
    holoColor(5, Skin)
    holoParent(5, E)
    
    holoCreate(6, E:toWorld(vec(-15, 32, -5)), vec(3.5))
    holoModel(6, "hq_sphere")
    holoDisableShading(6, 1)
    holoColor(6, Skin)
    holoParent(6, E)
}

if(changed(numPlayers()))
{
    rangerFilter(array(E, P):merge(players()))
}

if(PWrk)
{
    Dri = P:driver()
    Act = P:driver():isValid()
    
    W = Dri:keyForward()
    A = Dri:keyLeft()
    S = Dri:keyBack()
    D = Dri:keyRight()
    Shi = Dri:keySprint()
    Spc = Dri:keyJump()
    R = Dri:keyReload()
    Alt = Dri:keyWalk()
    M1 = Dri:keyAttack1()
    M2 = Dri:keyAttack2()
    
    if(Act)
    {
        if(changed(R) & R)
        {
            Ign = !Ign
        }
    }
}else
{
    if(P)
    {
        P:setColor(0, 0, 0, 0)
        P:setPos(E:toWorld(vec(0, 12.5, 10)))
        P:setAng(E:toWorld(ang(0, 180, 0)))
        
        timer("parent", 20)
    }
    if(clk("parent"))
    {
        stoptimer("parent")
        
        P:parentTo(E)
        
        rangerFilter(array(E, P))
        
        PWrk = 1
    }
}

VelLL = E:vel():length()
DV = $VelLL

if(Ign)
{
    if(DV < -125)
    {
        Ign = 0
        soundPlay("stop", 0.5, "physics/body/body_medium_impact_hard"+randint(1, 6)+".wav")
    }
    
    VelL = E:velL()
    VSV = clamp(-E:velL():y()/7.5, 0, 1500)
    
    GR = rangerOffset(60, E:pos() - vec(0, 0, 20) + (E:right() * VSV), vec(0, 0, -1))
    FR = rangerOffsetHull(25 + VSV, E:toWorld(vec(0, -100, 0)) + (E:right() * VSV), E:right(), vec(30))
    
    applyForce(((vec(0, 0, (60 - GR:distance()) * GR:hit()))*0.75 + (E:right() * (W-S) * (10 * 1 + Spc*3 +  Shi*4 + FR:hit() * 3)) - E:toWorldAxis(VelL * vec(0.025, 0.006125, 0.045))) * E:mass() * Div)
    applyAngForce(((ang(E:angVel():yaw() / 7.5, (A-D) * 12.5, (((Spc - Alt) * -25 * (W-S)) + clamp((E:angles():roll() - 15) * FR:hit() * W, -90, 0))  * (W|S))  - E:angles()*ang(1.5, 0, 0.8))*3 - E:angVel()/ang(1.5, 2.5, 2.5)) * E:mass() * Div)
    
    if(changed(M1) & M1)
    {
        if(M2 & !M:isValid())
        {
            M = propSpawn("models/props_phx/ww2bomb.mdl", holoEntity(4):toWorld(vec(0, 0, -16.5)), holoEntity(4):toWorld(ang(90, 0, 0)), 1)
            M:setTrails(12, 0, 0.5, "effects/beam_generic01", vec(255), 255)
            M:setColor(0, 0, 0, 0)
            
            holoCreate(7, M:pos())
            holoModel(7, "hq_sphere")
            holoDisableShading(7, 1)
            holoParent(7, M)
            
            soundPlay("slosh", 1, "player/footsteps/mud1.wav")
        }elseif(!M2)
        {
            soundPlay("honk", 3, "vo/npc/male01/question07.wav")
        }
    }
}

if(M:isValid() & !changed(M:isValid()))
{
    local Rd = rangerOffset(50 * Div, M:pos(), M:forward())
    if(Rd:hit() | !M2)
    {
        M:propBreak()
    }else
    {
        M:setPos(M:toWorld(vec(50 * Div, 0, 0)))
        if(Act)
        {
            M:setAng(M:toWorld(M:toLocal(((Dri:shootPos() + Dri:eye() * (Dri:shootPos():distance(M:pos()) + 500)) - M:pos()):toAngle())/10 * Div))
        }
        
    }
}
