@name FailCake ToniCar Ballon Supreme
@inputs Pod:wirelink Cam:wirelink Driver:entity
@persist E:entity [Ps Front Back LEF RIG]:ranger W A S D SHIFT SPACE GEARS:array
@persist Vel On LasVel:vector Active For Gear Fo Spd MaxSpeed LasP Ang CanMove
@persist Onc KK Onces GG Charge MaxCrg M2 BUM Bepp Pitch Angles:angle Bearing
@persist Alp
@trigger all

if(first()){
runOnTick(1)

E = entity()    

holoCreate(1)
holoModel(1,"models/props_vehicles/car002a_physics.mdl")    
holoScale(1,vec(1,1,1)/10)
holoPos(1,E:toWorld(vec(0,0,2)))

holoCreate(2)
holoModel(2,"models/dav0r/thruster.mdl")    
holoScale(2,vec(1,1,1)/10)
holoAng(2,ang(-90,0,0))
holoParent(2,holoEntity(1))
holoPos(2,E:toWorld(vec(-6.9,0,2)))

holoCreate(3)
holoModel(3,"models/Effects/muzzleflash/minigunmuzzle.mdl")    
holoScale(3,vec(1,1,1)/10)
holoAng(3,ang(-180,0,0))
holoParent(3,holoEntity(1))
holoAlpha(3,0)
holoPos(3,E:toWorld(vec(-7.7,0,2)))

holoCreate(4)
holoModel(4,"hqcylinder")    
holoScale(4,vec(-3,-3,-7))
holoAng(4,ang(90,0,0))
holoParent(4,holoEntity(1))
holoMaterial(4,"models/props_lab/warp_sheet")
holoAlpha(4,0)
holoPos(4,E:toWorld(vec(0,0,2)))

holoCreate(5)
holoModel(5,"models/props_combine/stasisvortex.mdl")    
holoScale(5,vec(1,1,1)/5)
holoParent(5,holoEntity(1))
holoAng(5,ang(-90,0,0))
holoAlpha(5,0)
holoPos(5,E:toWorld(vec(0,0,5)))


Gear = 1
On = 0
KK = 0
Onc = 0
MaxCrg = 5
## The Gears
GEARS:pushNumber(1) # Gear1
GEARS:pushNumber(2.5) # Gear 2
GEARS:pushNumber(3.8) # Gear 3

MaxSpeed = 4
}

W = Pod:number("W")
S = Pod:number("S")
D = Pod:number("D")
A = Pod:number("A")
SPACE = Pod:number("Space")
SHIFT = Pod:number("Shift")
Active = Pod:number("Active")
M2 = Pod:number("Mouse2")


Angles = Driver:driver():eyeAngles()

Cam:setVector("Position",holoEntity(1):toWorld(vec(-20,0,7)))
Cam:setAngle("Angle",holoEntity(1):angles())



if(tickClk()){
Vel = holoEntity(1):pos():distance( LasVel )
LasVel = holoEntity(1):pos()
}




if(Active){
    
if(On == 0){
On = 1  
soundPurge()
holoEntity(1):soundPlay(1,0,"vehicles/v8/v8_start_loop1.wav") 
GG = 0
}    
      
if(Vel > 0.1 & Fo != 0){
Onces = 0
   

if(GG == 0){
soundPurge()
if(Gear == 1){
GG = 1
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/first.wav")    
}elseif(Gear == 2){
GG = 1
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/second.wav")
}elseif(Gear == 3){
GG = 1
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/third.wav")
}     
}

 
}else{

if(Onces == 0){
Onces = 1
GG = 0
soundPurge()
if(Vel > 3){
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/v8_throttle_off_fast_loop1.wav")
}elseif(Vel <= 3 & Vel > 0.2){
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/v8_throttle_off_slow_loop2.wav")
}

}

}
 
## TIME TRAVEL!
#thrusters\rocket04.wav
#npc/scanner/cbot_discharge1.wav
#
    
if(SPACE & Vel <= 0.1){ 

if(changed(SPACE) & SPACE){
holoEntity(1):soundPlay(2,0,"weapons/physcannon/superphys_hold_loop.wav")    
}    
    
if(Charge >= MaxCrg){  
    
if(Bepp == 0){
Bepp = 1
holoEntity(2):soundPlay(55,0,"buttons/blip1.wav")       
}    

if(changed(M2) & M2){
BUM = 1    
} 
   
}  
   
if(Charge < MaxCrg){
Charge += 0.03   
}
}elseif(SPACE == 0 | Vel > 0.1){
if(Charge > 0){
Charge -= 0.02  
}
}
soundPitch(2,Charge*20) 


if(changed(BUM) & BUM == 1){
soundStop(2)
soundStop(1)
holoAlpha(3,255)
holoEntity(1):soundPlay(5,0,"thrusters/rocket04.wav") 
}

if(BUM == 1){
holoAng(3,holoEntity(1):toWorld(ang(-180,0,curtime()*1000)))
holoPos(1,Ps:position() + holoEntity(1):forward()*10 + vec(0,0,2.1)) 
holoPos(5,holoEntity(1):toWorld(vec(-Alp/10,0,5)))

if(Alp < 255){
Alp+=1
holoAlpha(4,Alp/3)
holoAlpha(5,Alp) 
}else{
BUM = 2
soundPurge()
timer("sound",10)
}

} 

if(clk("sound")){
soundStop(5)
holoEntity(5):soundPlay(6,0,"ambient/energy/whiteflash.wav") 
holoEntity(5):soundPlay(7,0,"ambient/levels/labs/teleport_active_loop1.wav")
soundPitch(7,70)   
}

if(BUM == 2){
holoAng(3,holoEntity(1):toWorld(ang(-180,0,curtime()*1000)))

holoModel(5,"models/props_combine/stasisshield.mdl")
holoScale(5,vec(1,1,1)/10)
holoAlpha(4,Alp/2)

holoUnparent(5)
holoPos(5,holoEntity(1):toWorld(vec(40,0,5)))
holoAlpha(5,255)
holoPos(1,E:toWorld(vec(cos(curtime()*100)*15,cos(curtime()*100)*15,300 + cos(curtime()*100)*15)))


} 



## TIME TRAVEL!
   
Ps = rangerOffset(3,holoEntity(1):pos(),-holoEntity(1):up())

## GEARS
if(BUM == 0){
if(Vel >= GEARS[Gear,number] & Gear < GEARS:count()){
Gear+=1
GG = 0
}elseif(Vel < GEARS[Gear,number] & Gear > 1 & Fo == 0){
Gear-=1
} 

## GEARS
     

if(Fo == 1 | Fo == -1){
if(Spd < MaxSpeed){
Spd+=0.01  
}
}elseif(Fo == 0){

if(Spd >= 0){
Spd-=0.02 
CanMove = 0
}elseif(Spd <= 0){
Spd = 0
CanMove = 1
}

}


if(Spd > 0.3){
if(A){
Ang+=0.8 
}elseif(D){
Ang-=0.8
}
}

holoAng(1,ang(0,Ang,0))


if(W & CanMove == 1){
Fo = 1  
LasP = 1
holoPos(1,Ps:position() + holoEntity(1):forward()*Spd + vec(0,0,2.1)) 
}elseif(S & CanMove == 1){
Fo = -1 
LasP = -1
holoPos(1,Ps:position() + -holoEntity(1):forward()*Spd + vec(0,0,2.1)) 
}else{
Fo = 0 

if(LasP == 1){
holoPos(1,Ps:position() + holoEntity(1):forward()*Spd + vec(0,0,2.1)) 
}elseif(LasP == -1){
holoPos(1,Ps:position() + -holoEntity(1):forward()*Spd + vec(0,0,2.1)) 
}

}
}


}else{
if(On == 1){
On = 0 
Gear = 1
Spd = 0
Bepp = 0
Vel = 0
KK = 0
#BUM = 0
holoAlpha(3,0)
soundStop(5)
soundStop(1)
holoEntity(1):soundPlay(1,0,"vehicles/v8/v8_stop1.wav")   
} 

soundPitch(2,Charge*20) 

if(Charge > 0){
Charge -= 0.02 
}else{
soundStop(2)
Charge = 0
}

}
