@name Robotboy655's Holo-Car
@inputs C:wirelink P:wirelink
@outputs
@persist RPressed Pos:vector Ang:angle Torque Steer Steeri Veiw VPressed Water WPressed
@trigger 

#OLD, Nice, BAD CODED, REWRITE

runOnTick(1)

Speed = 25
CameraDist = 25
Wheel_mat = "phoenix_storms/cube"#dome_side"
Car_mat = "phoenix_storms/iron_rails"
Max_Sound = 0.3

Car = holoEntity(1000)

soundVolume("car1",Max_Sound)
soundVolume("car2",0)
soundVolume("car3",0)
rangerHitWater(Water)

if(first() | duped())
{
    holoCreate(1000)
    holoCreate(1001)
    holoCreate(10001)
    holoCreate(10002)
    holoCreate(10003)
    holoCreate(10004)
    holoCreate(10005)
    holoCreate(10006)
    holoCreate(10007)
    holoMaterial(1000,Car_mat)
    holoMaterial(1001,Car_mat)
    holoMaterial(10001,Car_mat)
    holoMaterial(10002,Car_mat)
    holoMaterial(10003,Car_mat)
    holoMaterial(10004,Car_mat)
    holoMaterial(10005,Car_mat)
    holoColor(10006,vec(0,0,0),255)
    holoColor(10007,vec(0,0,0),255)
    holoColor(10005,vec(170,170,255),128)
    holoModel(10005,"prism")
    holoModel(10006,"hqcylinder")
    holoModel(10007,"hqcylinder")
    
    holoCreate(1002) #Back - left wheel
    holoCreate(1003) #Back - right wheel
    holoModel(1002,"hqcylinder")
    holoModel(1003,"hqcylinder")
    holoMaterial(1002,Wheel_mat)
    holoMaterial(1003,Wheel_mat)
    
    holoCreate(1004) #Back - left wheel
    holoCreate(1005) #Back - right wheel
    holoModel(1004,"hqcylinder")
    holoModel(1005,"hqcylinder")
    holoMaterial(1004,Wheel_mat)
    holoMaterial(1005,Wheel_mat)
    
    Pos = entity():pos()
    Pos = Pos:setZ(entity():pos():z() + 2)
    Ang = ang(0,0,0)

    holoEntity(1000):soundPlay("car1",0,"vehicles/v8/v8_start_loop1.wav")
    holoEntity(1000):soundPlay("car2",0,"vehicles/v8/v8_firstgear_rev_loop1.wav")
    holoEntity(1000):soundPlay("car3",0,"vehicles/v8/v8_turbo_on_loop1.wav")

    soundVolume("car1",0)
    soundVolume("car2",0)
    soundVolume("car3",0)

    Veiw = 1
}

holoPos(1000,Pos)
holoAng(1000,Ang + ang(0,Steeri,0))
holoScaleUnits(1000,vec(10,3,2))

holoPos(1001,Pos + vec(0,0,2) - Car:forward() * 2.75)
holoAng(1001,Ang + ang(0,Steeri,0))
holoScaleUnits(1001,vec(7,5,2.5))

holoPos(10001,Pos + Car:forward() * 5)
holoAng(10001,Ang + ang(0,Steeri,0))
holoScaleUnits(10001,vec(2,5,2))

holoPos(10002,Pos - Car:forward() * 5)
holoAng(10002,Ang + ang(0,Steeri,0))
holoScaleUnits(10002,vec(2,5,2))

holoPos(10003,Pos)
holoAng(10003,Ang + ang(0,Steeri,0))
holoScaleUnits(10003,vec(4,5,2))

holoPos(10004,Pos + Car:up() * 0.57)
holoAng(10004,Ang + ang(0,Steeri,0))
holoScaleUnits(10004,vec(12.5,5,1))

holoPos(10005,Pos + Car:up() * 2.025 + Car:forward() * 0.45)
holoAng(10005,Ang + ang(0,Steeri,0))
holoScaleUnits(10005,vec(5,4.5,2.5))

holoPos(10006,Pos - Car:up() * 1 + Car:forward() * 3)
holoAng(10006,Ang + ang(0,Steeri,0))
holoScaleUnits(10006,vec(1,5,1))

holoPos(10007,Pos - Car:up() * 1 - Car:forward() * 3)
holoAng(10007,Ang + ang(0,Steeri,0))
holoScaleUnits(10007,vec(1,5,1))

holoPos(1002,Pos - vec(0,0,1) + Car:right() * 2 - Car:forward() * 3)
holoAng(1002,Ang + ang(Torque,Steeri,90))
holoScaleUnits(1002,vec(2,2,1))

holoPos(1003,Pos - vec(0,0,1) - Car:right() * 2 - Car:forward() * 3)
holoAng(1003,Ang + ang(Torque,Steeri,90))
holoScaleUnits(1003,vec(2,2,1))

holoPos(1004,Pos - vec(0,0,1) - Car:right() * 2 + Car:forward() * 3)
holoAng(1004,Ang + ang(Torque,Steer + Steeri,90))
holoScaleUnits(1004,vec(2,2,1))

holoPos(1005,Pos - vec(0,0,1) + Car:right() * 2 + Car:forward() * 3)
holoAng(1005,Ang + ang(Torque,Steer + Steeri,90))
holoScaleUnits(1005,vec(2,2,1))

if(P["W",number])
{
    Torque = Torque + Speed + P["Shift",number] * Speed
    Pos = Pos + (Car:forward() * (Speed + P["Shift",number] * Speed)) / 35
    soundVolume("car1",0)
    soundVolume("car2",Max_Sound * !P["Shift",number])
    soundVolume("car3",Max_Sound * P["Shift",number])
}
if(P["S",number])
{
    Torque = Torque - Speed
    Pos = Pos - (Car:forward() * Speed) / 35
    soundVolume("car1",0)
    soundVolume("car2",Max_Sound)
}
if(P["A",number])
{
    Steer = 45
    if(P["W",number]){Steeri = Steeri + 2}
    if(P["S",number]){Steeri = Steeri - 2}
}
elseif(P["D",number])
{
    Steer = -45
    if(P["W",number]){Steeri = Steeri - 2}
    if(P["S",number]){Steeri = Steeri + 2}
}
else
{
    Steer = 0
}


C["Activated",number] = P["Active",number]
if(Veiw == 0)
{
    C["Direction",vector] = Car:eye()
    C["Position",vector] = Car:pos() + Car:up() * 8 - Car:forward() * 20
}
elseif(Veiw == 1)
{
    Eye = owner():eye()
    C["Direction",vector] = -Eye
    C["Position",vector] = Car:pos() + CameraDist * Eye
}
elseif(Veiw == 2)
{
    Eye = Car:eye()
    C["Direction",vector] = Eye
    C["Position",vector] = Car:pos() + vec(0,0,2) + CameraDist * Eye
}
C["Parent",entity] = Car

Ranger = rangerOffset(Car:pos() - vec(0,0,1),Car:pos() - vec(0,0,50))
Height = Ranger:distance()

Pos = Pos - vec(0,0,Height - 1)

if(P["Mouse1",number])
{
    Pos = Pos + vec(0,0,15)
}

if(P["Mouse2",number] & Veiw == 2 & VPressed == 0)
{
    Veiw = 0
    VPressed = 1
    timer("resetMouse2",1000)
    P["Entity",entity]:hintDriver("Camera: Fixed",5)
}
elseif(P["Mouse2",number] & Veiw == 0 & VPressed == 0)
{
    Veiw = 1
    VPressed = 1
    timer("resetMouse2",1000)
    P["Entity",entity]:hintDriver("Camera: Free",5)
}
elseif(P["Mouse2",number] & Veiw == 1 & VPressed == 0)
{
    Veiw = 2
    VPressed = 1
    timer("resetMouse2",1000)
    P["Entity",entity]:hintDriver("Camera: Front",5)
}
if(clk("resetMouse2"))
{
    VPressed = 0
}

if(P["Alt",number] & Water == 0 & WPressed == 0)
{
    Water = 1
    WPressed = 1
    timer("resetAlt",1000)
    P["Entity",entity]:hintDriver("Water mode: Enabled",5)
}
elseif(P["Alt",number] & Water == 1 & WPressed == 0)
{
    Water = 0
    WPressed = 1
    timer("resetAlt",1000)
    P["Entity",entity]:hintDriver("Water mode: Disabled",5)
}
if(clk("resetAlt"))
{
    WPressed = 0
}

if(P["R",number] & RPressed == 0)
{
    Pos = entity():pos()
    Pos = Pos:setZ(entity():pos():z() + 2)
    Ang = ang(0,0,0)
    RPressed = 1
    P["Entity",entity]:hintDriver("Car: Sucessfully respawned!",5)
    timer("resetR",1000)
}
if(clk("resetR"))
{
    RPressed = 0
}
