@name RC car
@inputs [Base W1 W2 W3 W4]:entity [Cam Pod]:wirelink
@persist Ang:angle Space Jump Cooldown Driver
@persist Force M1 Shift Active W S
if(first()|dupefinished()){
    runOnTick(1)
    holoCreate(1)
    holoModel(1,"models/vehicle/vehicle_engine_block.mdl")
    holoScale(1,vec(0.3,0.3,0.2))
    holoAng(1,Base:angles()+ang(0,-90,0))
    holoPos(1,Base:toWorld(vec(0,6,3)))
    holoParent(1,Base)
    
    holoCreate(2)
    holoModel(2,"models/nova/jeep_seat.mdl")
    holoScale(2,vec(0.2,0.2,0.2))
    holoAng(2,Base:angles())
    holoPos(2,Base:toWorld(vec(-3,-2,2)))
    holoParent(2,Base)
    
    holoCreate(4)
    holoModel(4,"models/nova/jeep_seat.mdl")
    holoScale(4,vec(0.2,0.2,0.2))
    holoAng(4,Base:angles())
    holoPos(4,Base:toWorld(vec(3,-2,2)))
    holoParent(4,Base)
    
    holoCreate(3)
    holoModel(3,"models/props_junk/gnome.mdl")
    holoScale(3,vec(0.2,0.2,0.2))
    holoAng(3,Base:angles()+ang(-10,90,0))
    holoPos(3,Base:toWorld(vec(-3,-2,3.5)))
    holoParent(3,Base)
    holoAlpha(3,0)
    
    holoCreate(5)
    holoModel(5,"models/xeon133/offroad/off-road-20.mdl")
    holoScale(5,vec(0.6,0.4,0.4))
    holoAng(5,W1:angles():setPitch(Base:angles():pitch()+180))
    holoPos(5,W1:massCenter())
    holoParent(5,W1)
    
    holoCreate(6)
    holoModel(6,"models/xeon133/offroad/off-road-20.mdl")
    holoScale(6,vec(0.6,0.4,0.4))
    holoAng(6,W2:angles():setPitch(Base:angles():pitch()))
    holoPos(6,W2:massCenter())
    holoParent(6,W2)
    
    holoCreate(7)
    holoModel(7,"models/xeon133/offroad/off-road-20.mdl")
    holoScale(7,vec(0.6,0.4,0.4))
    holoAng(7,W3:angles():setPitch(Base:angles():pitch()+180))
    holoPos(7,W3:massCenter())
    holoParent(7,W3)
    
    holoCreate(8)
    holoModel(8,"models/xeon133/offroad/off-road-20.mdl")
    holoScale(8,vec(0.6,0.4,0.4))
    holoAng(8,W4:angles():setPitch(Base:angles():pitch()))
    holoPos(8,W4:massCenter())
    holoParent(8,W4)
    
    holoCreate(9)
    holoModel(9,"hq_rcube")
    holoMaterial(9,"models/magnusson_device/magnusson_device_basecolor")
    holoScale(9,vec(0.5,0.9,0.3))
    holoAng(9,Base:angles()+ang(0,-90,0))
    holoPos(9,Base:toWorld(vec(0,-8,2.5)))
    holoParent(9,Base)
    
    Base:setMaterial("models/debug/debugwhite")
    Base:setColor(vec(25,25,25))
}
Seater=Pod["Entity",entity]:driver()
Pod2=Pod["Entity",entity]
W=Pod["W",number]
A=Pod["A",number]
S=Pod["S",number]
D=Pod["D",number]
R=Pod["R",number]
Shift=Pod["Shift",number]
Space=Pod["Space",number]
M1=Pod["Mouse1",number]
M2=Pod["Mouse2",number]
Active=Pod["Active",number]
Cam["Activated",number]=Pod["Active",number]
Cam["Parent",entity]=Base
Cam["Direction",vector]=-Base:right()
Cam["Position",vector]=Base:toWorld(vec(0,-20,20))
Base:applyForce(Base:right()*Base:mass()*(20+(20*Shift))*(S-W)+(Base:up()*Base:mass()*80*Jump)-(Base:up()*(Base:mass()*50)*(Force*1.5)))
Base:applyAngForce(ang(0,1,0)*Base:mass()*60*(A-D))

Ang = (-Base:angles()*10):setYaw(0)
AngForce = ($Ang*20) + (Ang*4)
Base:applyAngForce((AngForce*Base:mass()*R-Base:angVel()*2)/4)

if($Space&Space&!Jump&!Cooldown){
    timer("Jump",100)
    Jump=1
}

if(clk("Jump")){
    Jump=0
    Cooldown=1
    timer("Cooldown",1000)
}

if(clk("Cooldown")){
    Cooldown=0
}

rangerFilter(Base)
Ranger=rangerOffset(50,Base:massCenter(),-Base:right())

if($M1&M1){
    Force=!Force
    Base:soundPlay(1234,0,"buttons/button2.wav")
    Pod2:hintDriver("Wallclimbing set to: "+Force,1)
}
if(Ranger:hit()&Force){
    Base:applyAngForce(ang(0,0,1)*1000*Base:mass())
}

if($Shift&Shift){
    Base:soundPlay(1,0,"thrusters/rocket04.wav")
    Base:setTrails(10,0,1,"trails/plasma",vec(255,100,0),255)
}
if($Shift&!Shift){
    soundStop(1)
    Base:removeTrails()
}

if(($Active&Active)){
    Base:soundPlay(301,0,"vehicles/airboat/fan_motor_idle_loop1.wav")#"vehicles/v8/v8_start_loop1.wav")
    soundPitch(301,300)
    soundVolume(301,0.2)
    holoAlpha(3,255)
    holoCreate(10)
    holoScale(10,vec(0.1,0.1,0.1))
    holoModel(10,"models/buildables/sapper_sentry3.mdl")
    holoPos(10,Base:toWorld(vec(0,-8,2.5)))
    holoParent(10,9)
    holoCreate(11)
    holoScale(11,vec(0.2,0.2,0.2))
    holoModel(11,"models/buildables/sentry3_rockets.mdl")
    holoAng(11,Base:angles()+ang(0,90,0))
    holoPos(11,Base:toWorld(vec(0,-11,0)))
    holoParent(11,Base)
}
if(($Active&!Active)){
    soundStop(301)
    holoAlpha(3,0)
    holoDelete(10)
    holoDelete(11)
}
if(($W&W)|($S&S)){
    Base:soundPlay(300,0,"vehicles/v8/v8_turbo_on_loop1.wav")
    soundVolume(300,0.6)
}
if(($W&!W)|($S&!S)){
    soundStop(300)
}
soundPitch(300,clamp(Base:vel():length(),50,400)*Active)
Driver=(Seater!=noentity())
if(changed(Seater)){
    Pod2:printDriver("RC Car made by ShadowBrain")
    Pod2:printDriver("Controls:")
    Pod2:printDriver("WSAD   - Basic car controls")
    Pod2:printDriver("Space  - Jump")
    Pod2:printDriver("Mouse1 - Toggle wallclimbing")
    Pod2:printDriver("Shift  - Turbo")
    Pod2:printDriver("Reload - Flip car")
}
