################
# > Jeep Upgrade: Customize jeeps with holograms to make it look awesome.
# > How to use: Spawn a jeep and spawn the E2 on it.
################

@name Jeep Upgrade
@outputs Jeep:entity Flame I MPH WheelAng
@outputs AllowedPlayers:array CheckDriver Allowed

interval(10)

if (first()|duped()) {
    Jeep = entity():isWeldedTo()
    holoCreate(0)
    holoAng(0, Jeep:angles())
    holoPos(0, Jeep:pos())
    Jeep:parentTo(holoEntity(0))
    holoAng(0, ang(0,-90,0))
    #Flame
    holoCreate(1)
    holoScale(1, vec(5,5,5))
    holoAng(1, Jeep:angles()+ang(0,180,0))
    holoModel(1, "models/effects/sentry1_muzzle/sentry1_muzzle.mdl")
    holoPos(1, Jeep:pos()+vec(-105,0,30))
    holoParent(1, Jeep)
    #Wheels
    holoCreate(2)
    holoModel(2, "models/mechanics/wheels/wheel_spike_48.mdl")
    holoAng(2, Jeep:angles()+ang(0,90,90))
    holoPos(2, Jeep:pos()+vec(40,45,20))
    holoParent(2, Jeep)
    holoCreate(3)
    holoModel(3, "models/mechanics/wheels/wheel_spike_48.mdl")
    holoAng(3, Jeep:angles()+ang(0,90,90))
    holoPos(3, Jeep:pos()+vec(40,-45,20))
    holoParent(3, Jeep)
    holoCreate(4)
    holoModel(4, "models/mechanics/wheels/wheel_spike_48.mdl")
    holoAng(4, Jeep:angles()+ang(0,90,90))
    holoPos(4, Jeep:pos()+vec(-90,45,20))
    holoParent(4, Jeep)
    holoCreate(5)
    holoModel(5, "models/mechanics/wheels/wheel_spike_48.mdl")
    holoAng(5, Jeep:angles()+ang(0,90,90))
    holoPos(5, Jeep:pos()+vec(-90,-45,20))
    holoParent(5, Jeep)
    #Spoiler
    holoCreate(6)
    holoScale(6, vec(0.3,4,0.3))
    holoPos(6, Jeep:pos()+vec(-100,30,50))
    holoAng(6, Jeep:angles()+ang(0,0,-60))
    holoMaterial(6, "phoenix_storms/dome")
    holoModel(6, "hqcylinder2")
    holoParent(6, Jeep)
    holoCreate(7)
    holoScale(7, vec(0.3,4,0.3))
    holoPos(7, Jeep:pos()+vec(-100,-30,50))
    holoAng(7, Jeep:angles()+ang(0,0,-60))
    holoMaterial(7, "phoenix_storms/dome")
    holoModel(7, "hqcylinder2")
    holoParent(7, Jeep)
    holoCreate(8)
    holoScale(8, vec(7,0.3,1.5))
    holoPos(8, Jeep:pos()+vec(-110,0,70))
    holoAng(8, Jeep:angles()+ang(0,0,85))
    holoMaterial(8, "phoenix_storms/metalset_1-2")
    holoModel(8, "hqcylinder2")
    holoParent(8, Jeep)
    
    Jeep:deparent()
    holoDelete(0)
    Jeep:setColor(vec(150,150,255))
    AllowedPlayers=array()
    AllowedPlayers[1,entity]=owner()
}

Driver=Jeep:driver()
Mouse1=Driver:keyAttack1()
Mouse2=Driver:keyAttack2()

Flame+=30
holoAng(1, Jeep:angles()+ang(0,-90,Flame))

if (changed(Driver)&Driver) {
    for (CheckDriver=0,AllowedPlayers:count()) {
        if (AllowedPlayers[CheckDriver,entity]==Driver) {
            Allowed=1
        }
        if (CheckDriver==AllowedPlayers:count()) {
            if (Allowed) {
                holoAlpha(1, 255)
                Jeep:hintDriver("Jeep Upgrade Mod by Runeneo",10)
                Jeep:hintDriver("Activate Turbo: Mouse1",10)
                Allowed=0
            }
            else {
                Jeep:hintDriver("You do not have permission to drive this.",10)
                Jeep:hintDriver("For permission, ask "+owner():name(),10)
                Jeep:ejectPod()
            }
        }
    }
}
if (changed(Driver)&!Driver) {
    holoAlpha(1, 0)
}
if (changed(Mouse1)&Mouse1) {
    Jeep:soundPlay("1",0,"weapons/rpg/rocket1.wav")
}
if (changed(Mouse1)&!Mouse1) {
    soundStop("1")
}
if (Mouse1) {
    Jeep:applyForce(-((Driver:aimPos()-vec(0,0,60))-Jeep:pos())*300)
}

MPH = round(toUnit("mph", Jeep:vel():length()))
WheelAng+=MPH
holoAng(2, Jeep:angles()+ang(WheelAng,90,90))
holoAng(3, Jeep:angles()+ang(WheelAng,90,90))
holoAng(4, Jeep:angles()+ang(WheelAng,90,90))
holoAng(5, Jeep:angles()+ang(WheelAng,90,90))
