Spawn tdm cars in lua

Hey

I found out to spawn cars, but how do i spawn a tdm emergency car. This doesnt work
I know how to spawn the regular jeep.



	local car = ents.Create("charger12poltdm")  
	car:SetModel("models/tdmcars/emergency/dod_charger12.mdl")  
	car:SetKeyValue("vehiclescript","scripts/vehicles/charger2012.txt")  
	car:SetPos(Vector(-4572.690918, -5530.907715, 180.799149))
	car:SetAngles(Angle(0,0,0))
	car:Spawn() 


I pulled this and edited it from:

ENTITY/SpawnFunction

Your issue is that you never made a function to spawn the car.

[lua]
function ENT:SpawnFunction( ply, tr, ClassName )

if ( !tr.Hit ) then return end

local SpawnPos = tr.HitPos + tr.HitNormal * 16

local car = ents.Create( "charger12poltdm" )
    car:SetModel("models/tdmcars/emergency/dod_charger12.mdl")
car:SetPos( -4572.690918, -5530.907715, 180.799149 )
car:Spawn()
car:Activate()

return car

end
[/lua]

I dont think you answered my question. I asked about how do i spawn the tdm emergency car dodge charger. It works fine in my code when i spawn the standard jeep.

Entity:SetSkin

Set the skin to the police skin.

You create a prop_vehicle_jeep, and I think the least you need to do after that is:
SetModel, set the vehicle script with SetKeyValue( “vehiclescript”, “scripthere” ); Spawn and Activate it.

Im trying to do what you say, but the model only spawns and you cant drive it

[editline]19th April 2015[/editline]

I found the problem. SetKeyValue doenst really work

The problem


car:SetKeyValue("vehiclescript","scripts/vehicles/jeep_test.txt") 

But what do i do now? When i remove it, the car drives like shit.

You can try:




local _class = "charger12poltdm";
local _e = ents.Create( "prop_vehicle_jeep" );

for i, v in pairs( list.Get( "Vehicles" )[ _class ].KeyValues ) do
    _e:SetKeyValue( i, v );
end

_e:SetPos( Player( 1 ):GetPos() );
_e:SetModel( list.Get( "Vehicles" )[ _class ].Model );
_e:Activate();
_e:Spawn();


Nothing you said, doesnt work. Only the defualt jeep works.

[lua]local function SpawnVehicle(ply, class)
local vehicle = list.Get(“Vehicles”)[class]
if not vehicle then return end
local car = ents.Create(vehicle.Class)
if not car then return end
car:SetModel(vehicle.Model)
if vehicle.KeyValues then
for k, v in pairs(vehicle.KeyValues) do
car:SetKeyValue(k, v)
end
end
car.VehicleName = class
car.VehicleTable = vehicle
car.Owner = ply

local pos = Vector(0,0,0)
local ang = Angle(0,0,0)
car:SetPos(pos)
car:SetAngles(ang)
car:Spawn()
car:Activate()
car:SetCollisionGroup(COLLISION_GROUP_WEAPON)
car.ClassOverride = vehicle.Class
if vehicle.Members then
table.Merge(car, vehicle.Members)
end
gamemode.Call(“PlayerSpawnedVehicle”, ply, car)
end[/lua]
ripped from https://github.com/ds-2198/DarkRP-Car-Dealer/blob/master/NPC%20Car%20Dealer%202.5.0/lua/npcshop/server.lua#L77

How much of this do we have to edit? Or will it make a list based on resources loaded from all the addons in addon folder?

all you need to do with the code is do paste it and under it write:
SpawnVehicle(PLAYER,class name)

Example


SpawnVehicle(Player.GetByID(1),"charger12poltdm")