Spawning a vehicle with a chat command

How can I do this?

gm_spawnvehicle <vehicle name (Class)>

Close, but no cigar. That’s a concommand.

Assuming you’re using sandbox, you could do something like this:

[lua]function GM:OnPlayerChat( pl, strText, bTeamOnly, bPlayerIsDead )
local args = string.Explode(" ",strText)
if pl == LocalPlayer() and args[1] == “/vehicle” then
local vehicle = {
if !table.HasValue(vehicle,args[2]) then return end
RunConsoleCommand( “gm_spawnvehicle”, args[2] )

**NOTE: I don’t know what the actual arguments to gm_spawnvehicle are. You’d have to change the safety parameters in the vehicle table.

Oh I read it as console command.

That didn’t really work for me ay all.

I just want a chat command so when someone types /vehicle it will spawn them a jeep.

local function GimmeAJeep( ply, text )
if string.sub( text, 1, 8 ) == “/vehicle” then
ply:ConCommand(“gm_spawnvehicle Jeep”)
hook.Add(“PlayerSay”, “GimmeAJeep”, GimmeAJeep )

Perefect, thanks alot.

That’s because you probably put it on the server. It’s a clientside script. And it works for more vehicles than just the jeep.

That is kind of a backwards way to do it, it’s better to actually call the spawn function in the hook.

How would you do this without using “gm_spawnvehicle Jeep” becuase i would like to do this but without using sandbox as a base

I guess that you would get an eye trace and then spawn the vehicle using ents.Create()

Correct yet missing vital information such as how to spawn the vehicle with ents.Create. You’ll have to look up the classname first and then there may be KeyValues needed, such as whether it should have the gun. Information such as that needs you to look up on the Source SDK the class name and keyvalues and then the gmod wiki to find out how to set these keyvalues.