Spawning Cars

Hi!

Can anybody tell me, how can i spawn a driveable car with lua? (Vehicle)
and how can i set the view distance on it?

EDIT: maybe spawn it as sent?



concommand.Add("Gimmecar", function()
	vehicle = ents.Create("prop_vehicle_jeep")
	vehicle:SetModel("Your/model.mdl")
	vehicle:SetKeyValue("vehiclescript", "scripts/vehicles/ScriptName.txt")
	vehicle:SetPos(LocalPlayer():GetEyeTrace().HitPos)
	vehicle:Spawn()
	LocalPlayer():ChatPrint("Yay, it worked!")
		else
	LocalPlayer():ChatPrint("Nay, it failed!")
	end )


That will not work at all.

Try this, lolz.

[lua]
function SpawnACar(Player)
local vehicle = ents.Create(“prop_vehicle_jeep”)
vehicle:SetModel(“models/buggy.mdl”)
vehicle:SetPos(Player:GetEyeTrace().HitPos)
vehicle:SetAngles(Player:GetAngles())
vehicle:SetKeyValue(“VehicleScript”,“scripts/vehicles/jeep.txt”)
vehicle:Spawn()
if ValidEntity(vehicle) and vehicle:IsVehicle() then
Player:ChatPrint(“Vehicle spawned!”)
else
Player:ChatPrint(“Vehicle spawn failed!”)
end
end
concommand.Add(“spawnvehicle”,SpawnACar)
[/lua]

Busymonkey, you can’t have an ‘else’ if there isn’t an ‘if’…

-snip- bad reading

He wasn’t talking about my code.

Yea that sucked, I know.

I was kinda tired, I went to bed at 9am and then out of bed at 12:30pm that day.