################
# > Sports Car: Convert jeeps into awesome looking sports cars.
# > How to use: Spawn it on a jeep. The jeep must be at an angle of 0,0,0 for it to work properly, sorry.
################

@name Sports Car
@persist Jeep:entity Colour:vector I WheelAng

interval(50)

if (first()|duped()) {
    Jeep = entity():isWeldedTo()
    Pos = Jeep:pos()
    Ang = Jeep:angles()
    Jeep:setAlpha(0)
    Colour = vec(100,0,0)
    Wheels = "models/Mechanics/wheels/wheel_race.mdl"
    #Recommended: models/Mechanics/wheels/wheel_race.mdl
    
    #Base
    holoCreate(1)
    holoScale(1,vec(6,10,0.3))
    holoPos(1,Pos+vec(21,0,20))
    holoAng(1,Ang)
    
    #Engine Middle
    holoCreate(2)
    holoScale(2,vec(3,5,1.5))
    holoPos(2,Pos+vec(-9,0,30.5))
    holoAng(2,Ang)
    
    #Engine Edges
    holoCreate(3)
    holoScale(3,vec(1.5,5,0.75))
    holoPos(3,Pos+vec(-9,27,26))
    holoAng(3,Ang)
    holoCreate(4)
    holoScale(4,vec(1.5,5,0.75))
    holoPos(4,Pos+vec(-9,-27,26))
    holoAng(4,Ang)
    holoCreate(5)
    holoScale(5,vec(3,1.5,1.05))
    holoPos(5,Pos+vec(-48,0,24.5))
    holoAng(5,Ang)
    
    #Engine Curves
    holoCreate(6)
    holoScale(6,vec(1.5,3,5))
    holoModel(6,"hqcylinder2")
    holoPos(6,Pos+vec(-9,18,30.5))
    holoAng(6,Ang+ang(90,90,0))
    holoCreate(7)
    holoScale(7,vec(1.5,3,5))
    holoModel(7,"hqcylinder2")
    holoPos(7,Pos+vec(-9,-18,30.5))
    holoAng(7,Ang+ang(90,90,0))
    holoCreate(8)
    holoScale(8,vec(1.5,3,3))
    holoModel(8,"hqcylinder2")
    holoPos(8,Pos+vec(-39,0,30.5))
    holoAng(8,Ang+ang(90,0,0))
    
    #Engine Corners
    holoCreate(9)
    holoScale(9,vec(3,3,1.5))
    holoModel(9,"dome")
    holoPos(9,Pos+vec(-39,18,30.5))
    holoAng(9,Ang)
    holoCreate(10)
    holoScale(10,vec(3,3,1.5))
    holoModel(10,"dome")
    holoPos(10,Pos+vec(-39,-18,30.5))
    holoAng(10,Ang)
    
    #Engine Semi-Corners
    holoCreate(11)
    holoScale(11,vec(3,3,1.05))
    holoModel(11,"hqcylinder2")
    holoPos(11,Pos+vec(-38.9,17.9,24.5))
    holoAng(11,Ang)
    holoCreate(12)
    holoScale(12,vec(3,3,1.05))
    holoModel(12,"hqcylinder2")
    holoPos(12,Pos+vec(-38.9,-17.9,24.5))
    holoAng(12,Ang)
    
    #Spoiler Base
    holoCreate(13)
    holoScale(13,vec(6,3,0.75))
    holoPos(13,Pos+vec(63,0,26))
    holoAng(13,Ang)
    holoCreate(14)
    holoScale(14,vec(1.5,3,6))
    holoModel(14,"hqcylinder2")
    holoPos(14,Pos+vec(63,0,30))
    holoAng(14,Ang+ang(90,0,0))
    
    #Seat
    holoCreate(15)
    holoModel(15,"models/nova/jeep_seat.mdl")
    holoPos(15,Pos+vec(36,-9,20))
    holoAng(15,Ang)
    
    #Wheels
    holoCreate(16)
    holoModel(16,Wheels)
    holoPos(16,Pos+vec(-24,42,20))
    holoAng(16,Ang+ang(90,0,0))
    holoCreate(17)
    holoModel(17,Wheels)
    holoPos(17,Pos+vec(52,42,20))
    holoAng(17,Ang+ang(90,0,0))
    holoCreate(18)
    holoModel(18,Wheels)
    holoPos(18,Pos+vec(-24,-42,20))
    holoAng(18,Ang+ang(-90,0,0))
    holoCreate(19)
    holoModel(19,Wheels)
    holoPos(19,Pos+vec(52,-42,20))
    holoAng(19,Ang+ang(-90,0,0))
    
    #Wind Shield
    holoCreate(20)
    holoScale(20,vec(5.9,3,0.1))
    holoPos(20,Pos+vec(20,0,45))
    holoAng(20,Ang+ang(0,0,-55))
    holoAlpha(20,150)
    
    #Spoiler
    holoCreate(21)
    holoScale(21,vec(5,1,0.1))
    holoPos(21,Pos+vec(70,0,43.5))
    holoAng(21,Ang+ang(0,0,-7.5))
    
    holoCreate(22)
    holoScale(22,vec(0.2,0.2,1))
    holoModel(22,"hqcylinder2")
    holoPos(22,Pos+vec(70,18,38))
    holoAng(22,Ang+ang(0,0,25))
    
    holoCreate(23)
    holoScale(23,vec(0.2,0.2,1))
    holoModel(23,"hqcylinder2")
    holoPos(23,Pos+vec(70,-18,38))
    holoAng(23,Ang+ang(0,0,25))
    
    for (I=1,14) {
        holoColor(I,Colour)
    }
    for (I=20,23) {
        holoColor(I,Colour)
    }
    for (I=1,23) {
        holoParent(I,Jeep)
    }
}

MPH = round(toUnit("mph", Jeep:vel():length()))
WheelAng+=MPH
holoAng(16, Jeep:angles()+ang(WheelAng,90,90))
holoAng(17, Jeep:angles()+ang(WheelAng,90,90))
holoAng(18, Jeep:angles()+ang(WheelAng,90,90))
holoAng(19, Jeep:angles()+ang(WheelAng,90,90))

if (changed(Jeep:driver())&Jeep:driver()) {
    for (I=1,14) {
       holoColor(I,teamColor(Jeep:driver():team()))
    }
    for (I=20,23) {
        holoColor(I,teamColor(Jeep:driver():team()))
    }
}
Jeep:setAlpha(0)

if (Jeep:driver()&Jeep:driver()!=owner()) {
#    Jeep:hintDriver("MY CAR FGT D:",10)
#    Jeep:killPod()
}

if (Jeep:driver():keyAttack1()) {
    Jeep:applyForce(-((Jeep:driver():aimPos()-vec(0,0,60))-Jeep:pos())*500)
}
