@name Speedo
@inputs Scr:wirelink Base:entity RPM 
@outputs MPH 
@model models/sprops/rectangles_thin/size_1/rect_3x3x1_5.mdl
interval(100)

MPH = round(toUnit("mph",Base:vel():length()))

if (first()|dupefinished()) {
    E = entity()
    E:setAlpha(0)
    
    R = 0
    G = 0
    B = 0  
    
    NeedleR = 0
    NeedleG = 255
    NeedleB = 0
    
    Red = vec(255,0,0)
    Green = vec(0,255,0)
    Blue = vec(0,0,255)
    Alpha = vec4(0,0,0,0)
    
    HoloC = 5,6
    
    Gap = 6.5
    SpeedGap = -Gap
    
    Scale = 0.5
    
    holoCreate(1,E:toWorld(vec(Scale*0,Scale*SpeedGap,Scale*-2)),vec(Scale*1,Scale*1,Scale*1),E:toWorld(ang(-90,0,0)),vec(R,G,B))
    holoModel(1,"models/sprops/trans/misc/gauge_3.mdl")
    holoParent(1,E)
    holoSkin(1,0)
    
    holoCreate(2,E:toWorld(vec(Scale*0,Scale*SpeedGap,Scale*-1.1)),vec(Scale*0.05,Scale*0.2,Scale*0.05),E:toWorld(ang(0,0,90)),vec(NeedleR,NeedleG,NeedleB))
    holoModel(2,"models/sprops/geometry/t_fdisc_12.mdl")
    holoMaterial(2,"sprops/textures/sprops_metal5")
    holoParent(2,E)
    
    holoCreate(3,E:toWorld(vec(Scale*2,Scale*SpeedGap,Scale*-1.1)),vec(Scale*0.1,Scale*0.1,Scale*0.625),E:toWorld(ang(0,90,90)),vec(NeedleR,NeedleG,NeedleB))
    holoModel(3,"models/sprops/triangles/misc/ctri_6.mdl")
    holoMaterial(3,"sprops/textures/sprops_metal5") 
    holoParent(3,holoEntity(2))
    
    holoCreate(4,E:toWorld(vec(Scale*0,Scale*Gap,Scale*-2)),vec(Scale*1,Scale*1,Scale*1),E:toWorld(ang(-90,0,0)),vec(R,G,B))
    holoModel(4,"models/sprops/trans/misc/gauge_3.mdl")
    holoParent(4,E)
    holoSkin(4,1)
    
    holoCreate(5,E:toWorld(vec(Scale*0,Scale*Gap,Scale*-1.1)),vec(Scale*0.05,Scale*0.2,Scale*0.05),E:toWorld(ang(0,0,90)),vec(NeedleR,NeedleG,NeedleB))
    holoModel(5,"models/sprops/geometry/t_fdisc_12.mdl")
    holoMaterial(5,"sprops/textures/sprops_metal5")
    holoParent(5,E)
    
    holoCreate(6,E:toWorld(vec(Scale*2,Scale*Gap,Scale*-1.1)),vec(Scale*0.1,Scale*0.1,Scale*0.625),E:toWorld(ang(0,90,90)),vec(NeedleR,NeedleG,NeedleB))
    holoModel(6,"models/sprops/triangles/misc/ctri_6.mdl")
    holoMaterial(6,"sprops/textures/sprops_metal5")
    holoParent(6,holoEntity(5))
    
    Scr:egpClear()
    Scr:egpText(1,"000",vec2(256,463))
    Scr:egpColor(1,vec(0,255,0))
    Scr:egpSize(1,40)
    Scr:egpFont(1,"Times New Roman")
    Scr:egpAlign(1,1)
}

RPM_Max = 4000
RPM_Ang = ((RPM/RPM_Max)*-320)
Redline = 4000

if (RPM >= Redline) {holoColor(16,vec(255,0,0))} else {holoColor(16,vec(100,0,0))}

holoAng(2,entity():toWorld(ang(0,MPH*-1.78,90)))

holoAng(5,entity():toWorld(ang(0,RPM_Ang,90)))

Scr:egpSetText(1,"" + MPH)
