Spawning Cars?

How do i create and spawn custom cars like those from the sicknes models pack in lua?
With out the use of the spawn menu.

derma panel.
or key binds.

ok ill make this simple for dark rp im trying to make a system that automaticly spawns cars from the sickens model pack.
So when u join the server thiers a cop car near the police station and fast car near the posh house that kinda stuff.

here is test code i have so far:

local ply = Entity(1) 
local tr = ply:GetEyeTrace() 
local ent = ents.Create("prop_vehicle_jeep")
ent:SetPos(tr.HitPos + Vector(0,0,50) )

but i’m getting this error:
Vehicle () unable to properly initialize due to script error in ()!

I cant seem to figure this out.

Are you sure Entity( 1 ) is actually a player?

Try replacing that with player.GetByID( 1 ) instead? And a better way would be (imo) record where you want the car to spawn with

lua_run_cl LocalPlayer():GetPos()

in console, then SetPos’ it to the location the console command above gave you


If you didn’t catch that, stand where you want the car to spawn then use the concommand

isn’t Entity(1) worldspawn?

thats not the problem but thanks for the idea.
The car does spawn but its just a model acting like a ghost. as if it wasnt thier but it is visable and solid color.

Try putting ent:Activate() before ent:Spawn()


Err after ent:Spawn()

Like has been posted in millions of threads like this before, you need to set the vehicle script before you can spawn it.

ent:SetKeyValue(“vehiclescript”, “scripts/vehicles/jeep.txt”)[/lua]

Nope even with ent:Activate() i get the same problem.


Thank you Dave.

Ok getting a new error now.

local ply = player.GetByID( 1 )
local pos = ply:GetEyeTrace().HitPos 
local model = "models/sickness/360spyder.mdl"
local ent = ents.Create("prop_vehicle_jeep")
ent:SetKeyValue("vehiclescript", "scripts/vehicles/jeep.txt")

Error: “Vehicle () unable to properly initialize due to script error in (scripts/vehicles/jeep.txt)!”