@name UnoBike
@inputs  
@outputs  
@persist [E P Dri]:entity Active_i PWrk VSV Ign VelLL Mul Ntrpl HoverHeight FlyAng SpeedMultiplier YawSpeed
@trigger 
@model models/hunter/plates/plate1x1.mdl
runOnTick(1)

if (first()) {
    entity():setColor(vec(),0)
    
    holoCreate(1)
    holoModel(1,"models/sprops/misc/tubes/size_72/tube_72x6.mdl")
    holoPos(1,entity():toWorld(vec(0,0,0)))
    holoAng(1,ang(0,90,0))
    holoParent(1,entity())
    
    holoCreate(2)
    holoModel(2,"models/sprops/misc/tubes/size_72/tube_72x6.mdl")
    holoPos(2,entity():toWorld(vec(0,0,0)))
    holoAng(2,ang(0,90,45))
    holoParent(2,entity())
    
    holoCreate(3)
    holoModel(3,"models/sprops/misc/tubes/size_72/tube_72x6.mdl")
    holoPos(3,entity():toWorld(vec(0,0,0)))
    holoAng(3,ang(0,90,-45))
    holoParent(3,entity())
    
    holoCreate(4)
    holoModel(4,"models/sprops/geometry/fring_108.mdl")
    holoPos(4,entity():toWorld(vec(0,0,0)))
    holoAng(4,ang(0,90,0))
    holoParent(4,entity())
    
    holoCreate(5)
    holoModel(5,"models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl")
    holoPos(5,entity():toWorld(vec(0,-52.5,0)))
    holoAng(5,ang(0,90,0))
    holoParent(5,entity())
    
    holoCreate(6)
    holoModel(6,"models/sprops/cuboids/height06/size_1/cube_6x6x6.mdl")
    holoPos(6,entity():toWorld(vec(0,52.5,0)))
    holoAng(6,ang(0,90,0))
    holoParent(6,entity())
    
    holoCreate(7)
    holoModel(7,"models/sprops/rectangles/size_1/rect_3x24x3.mdl")
    holoPos(7,entity():toWorld(vec(0,-42.5,0)))
    holoAng(7,ang(0,90,0))
    holoParent(7,entity())
    
    holoCreate(8)
    holoModel(8,"models/sprops/rectangles/size_1/rect_3x24x3.mdl")
    holoPos(8,entity():toWorld(vec(0,42.5,0)))
    holoAng(8,ang(0,90,0))
    holoParent(8,entity())
    
    holoCreate(9)
    holoModel(9,"hq_torus_thin")
    holoScale(9,vec(9.5,9.5,6))
    holoAng(9,ang(0,90,90))
    holoParent(9,entity())
    
    holoCreate(10)
    holoModel(10,"hq_sphere")
    holoScale(10,vec(5.9,5.9,5.9))
    holoParent(10,entity())
    
    for (I = 1,3) {holoMaterial(I,"models/shiny") holoColor(I,vec(80,80,80))}
    for (E = 5,8) {holoMaterial(E,"models/shiny") holoColor(E,vec(80,80,80))}
    holoMaterial(4,"models/shiny")
    holoColor(4,vec(80,80,80))
    holoColor(9,vec(0,0,0))
    holoColor(10,vec(0,0,0))
    
    Ntrpl = 90/(500/33) #If your hovercraft is spazzing out, try lowing that 90 in the interval (Line 4) and this line here. Warning: Decreasing the interval will increase the ops usage.
    
    E = entity()
    P = entity():isConstrainedTo()
    
    E:setMass(5000)
    E:propFreeze(0)
    
    #rangerHitWater(1)
    rangerHitEntities(0)
    rangerPersist(1)
	
    #Settings:
    HoverHeight = 59 #Self-explanitory
    FlyAng = -0 #Angle at which you want to fly towards when you hold Space
    SpeedMultiplier = 0.3 #Mess with this number if you wanna fly fast
    YawSpeed = 6 #Speed at which the hovercraft turns left and right
}

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

if(PWrk)
{
    Dri = P:driver()
    Act = P:driver():isValid()
    
    if(Act)
    {
        W = Dri:keyForward()
        A = Dri:keyLeft()
        S = Dri:keyBack()
        D = Dri:keyRight()
        Shi = Dri:keySprint()
        Alt = Dri:keyWalk()
        Spc = Dri:keyJump()
        R = Dri:keyReload()
        M1 = Dri:keyAttack1()
        M2 = Dri:keyAttack2()
        
        if(changed(R) & R)
        {
            Ign = !Ign            
            soundStop("fail")
            soundPlay("ignv",Ign ? 0.874 : 1.13, Ign ? "hl1/fvox/activated.wav" : "hl1/fvox/deactivated.wav")
        } else {
    }
}
    
    Mul += Ign ? 0.0125 : -0.0125
    Mul = clamp(Mul,0,1)
    
    if(changed(P))
    {
        PWrk = P:isValid()
    }
    
    VelLL = E:vel():length()
    DV = $VelLL
}else
{
    findByClass("prop_vehicle_prisoner_pod")
    findSortByDistance(E:pos())
    if(find():model() == "models/nova/airboat_seat.mdl" & find():owner() == owner())
    {
        P = find()
        P:setPos(E:toWorld(vec(0,0,-6))) #Mess with that vector to change the offset position of the chair
        P:setAng(E:toWorld(ang(0,180,0))) #If you DO want your chair to face backwards or something, go ahead and mess with this
        
        timer("parent",20)
    }
    if(clk("parent"))
    {
        stoptimer("parent")
        
        P:parentTo(E)
        
        rangerFilter(array(E,P))
        
        PWrk = 1
    }
}

if(Ign)
{
    VelL = E:velL()
    VSV = clamp(-E:velL():y()/7.5,-1500,1500)
    
    GR = rangerOffset(HoverHeight, E:pos() + (E:right() * clamp(VSV,0,1500)), vec(0,0,-1))
    FR = rangerOffset(25 + clamp(VSV,0,1500), mix(E:pos(), GR:pos(), 0.5), E:right())
    
    applyForce(((vec(0,0,(HoverHeight - GR:distance()) * GR:hit()))*0.75 + (E:right() * (W-S) * SpeedMultiplier * (10 * 1 + Spc*3 +  Shi*4 + FR:hit() * 3)) - E:toWorldAxis(VelL * vec(0.025,0.006125,0.045))) * E:mass() * Ntrpl)
    applyAngForce(((ang(E:angVel():yaw() / 6 - (2 * !GR:hit()), (A-D) * YawSpeed, ((Spc * FlyAng * (W-S)) + clamp((E:angles():roll() - 35) * FR:hit() * W,-90,0))  * (W|S))  - E:angles()*ang(1,0,1))*5 - E:angVel()/ang(2.5,2.5,1.5)) * E:mass() * Ntrpl)
    applyAngForce(((ang(E:angVel():yaw() / 6 - (2 * !GR:hit()), (A-D) * YawSpeed, ((Shi * -FlyAng * (W-S)) + clamp((E:angles():roll() - 35) * FR:hit() * W,-90,0))  * (W|S))  - E:angles()*ang(1,0,1))*5 - E:angVel()/ang(2.5,2.5,1.5)) * E:mass() * Ntrpl)
}
    if(DV < -10000) #Mess with the number if you wanna change the resistence to crashing
    {
        Ign = 0
        soundStop("ignv")
        soundPlay("crash",0.8,"ambient/explosions/explode_3.wav")
    }
if (HoverHeight > 59) {
    holoAng(4,holoEntity(4):angles()+ang(0,0,0))
    holoAng(9,holoEntity(9):angles()+ang(0,0,0))
}
