At Wits End - Spawn an addon vehicle

I’ve been trying to create a derma panel button that spawns an addon (photon and SGM vehicle to be precise). I’ve literally spent the last 6 hours on this. I’ve been searching, googling and found a few things. Keep in mind, it’s not just one addon, it’s ALL of them I can’t figure out. I was able to do this after MANY hours to spawn custom npc and I figured it would be a similar process.

from the developer of the mod: I found this :

local ent = ents.Create("prop_vehicle_jeep")
-- all your entity setting up goes here
if youWantThisAsAPhotonCar then
 ent.VehicleTable = list.Get("Vehicles")["photonnameyouwant"]

local ent = ents.Create ("prop_vehicle_jeep")
	ent:SetModel ("models/sentry/caison_fire.mdl")
	if "Caison Fire Truck" then
		ent.VehicleTable = list.Get("Vehicles")["Emergency Vehicles"]  //have to pull up the correct vehicle for the photon script to work

Right now this is as far as I can get on my own. has this code :

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
if vehicle.KeyValues then
for k, v in pairs(vehicle.KeyValues) do
car:SetKeyValue(k, v)
car.VehicleName = class
car.VehicleTable = vehicle
car.Owner = ply

local pos = Vector(0,0,0)
local ang = Angle(0,0,0)
car.ClassOverride = vehicle.Class
if vehicle.Members then
table.Merge(car, vehicle.Members)
gamemode.Call("PlayerSpawnedVehicle", ply, car)

With help, I’ve been able to get a long output of the vehicle table that contains some information as a txt file but I do not know what the table names are actually called and where everything goes.

EDIT : Right now I should mention none of these resources are in my gamemode mode directory because they are still in the root folder for garrysmod. That shouldn’t matter correct?

why hello sir

try this:

ent.VehicleTable = list.Get("Vehicles")["Caison Fire Truck"]

The “Caison Fire Truck” text needs to be the name of the vehicle.

To explain, the Vehicles table is a table of all the vehicles Sandbox uses in the Spawn Menu. The text afterwards (Caison Fire Truck in this case) is the table’s index/key. In order for a vehicle to be registered in sandbox, it adds its own index into the Vehicles table with all the appropriate parameters. Photon rides on this technique to throw in the additional Photon information as a single model can be outfitted with different Photon parameters.

Not an ideal circumstance, but it works for right now.

Wow, thanks for replying man, this made my day.

after dealing with some stack overflows, this is as minimal of an error that I can get from console:

Does it give you any ideas? I tried swapping “Ford C-Series Firetruck” to the IF statement but no change.

[editline]28th July 2015[/editline]

Progress. Apparently there was SUPPOSED to be a SPACE at the end of the "Caisons Fire Truck ". (see?)

Now I can drive it but it still spawns without photon and isn’t colored right…


[editline]28th July 2015[/editline]

I’m not giving up on this.

This error message:


Hmm, so this is the fallback message as I’m sure you guessed.

The latest error you posted would happen when Photon can’t find a vehicle table and tries to pull the model name but GetModel is failing for some reason. Maybe add ent:Activate() below the ent:Spawn()?

Also unrelated but just so you know

if "Caison Fire Truck" then

will always evaluate to true because Lua interprets any string as being true, and there isn’t any real conditional you’re setting up, as opposed to

if vehicleName == "Caison Fire Truck" then

. But that aside, you don’t need to wrap that in an if statement at all.

If none of that makes sense you can post your code block you have atm and I’ll take a look.

Again, THANK YOU for checking back on this. However, it is still a model and not drivable or photoned.

Error messsage from console.

Below is as far as I can get. This actually spawns a RED model (versus always being white).

local ent = ents.Create ("prop_vehicle_jeep")
		local car = ents.Create ("prop_vehicle_jeep")
	ent:SetModel ("models/sentry/caison_fire.mdl")
	ent.VehicleTable = list.Get("Vehicles")["Caison Fire Truck "]   

IMPORTANT (possibly) : Where should the photon and car models packs be located. Is it okay if I have them just as GMA’s and NOT in my gamemode or referenced in any of my gamemode lua files? Or do I need to take elements and ADDCSLUA / include them for this to work? (That might be why it continually fails)

Secondary, I ran

 lua_run for k,v in pairs(list.Get("Vehicles")) do print(k,v.Name) end

an found the actual table name table: 0x347fa2c8. I have no clue whether that is something I can (or even SHOULD) reference as a way to get around this tostring error I get. Maybe it’s just a path issue where I have the files stored.

In any event, again, THANK YOU I have only been activalying learning lua over the past 2 weeks, mainly by googling, searching the forums and reading previous posters problems and solutions, and posting questions when I was absolutely stuck. Having someone experience chime in makes a world of difference.