Spawning in a car

So, im making a gamemode, and I want people to spawn in a jeep and cant get out,

Thanks for help.

Isn’t there supposed to be a question in there somewhere?

He’s asking how to do it what he described.

To make them enter a vehicle you would first spawn them then call EnterVehicle on them. Then you would hook to the event CanExitVehicle to disable exiting the vehicles.

As you can see the names are pretty straight forward and you could probably find them yourself if you took the time to search the wiki. :wink:

[Player.EnterVehicle

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=Player.EnterVehicle)
[Gamemode.CanExitVehicle

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?search=Gamemode.CanExitVehicle)

[lua]local Jeep = ents.Create(“prop_vehicle_jeep_old”)
Jeep:SetModel(“models/buggy.mdl”)
Jeep:SetKeyValue(“vehiclescript”, “scripts/vehicles/jeep_test.txt”)
Jeep:SetPos(Vector(0, 0, 0)) --Change this to the position where the jeep should be spawned
Jeep:Spawn()
Jeep:Activate()
[/lua]

To spawn a jeep. (Copied directly from another thread)

Ok, but it says that it enters the near vehicule, I want to make that if the player join the server, he automaticly spawns in a jeep. Is it possible?

Yes, and we’ve just told you how. :smile:

Basically you would have a PlayerSpawn hook or gamemode hook that lets the player spawn normally then creates a vehicle and force the player to enter it.

[lua]function GM:PlayerSpawn(ply)
if (!ply.Jeep) then
local Jeep = ents.Create(“prop_vehicle_jeep_old”)
Jeep:SetModel(“models/buggy.mdl”)
Jeep:SetKeyValue(“vehiclescript”, “scripts/vehicles/jeep_test.txt”)
Jeep:Spawn()
Jeep:Activate()
ply.Jeep = Jeep
end
ply.Jeep:SetPos(ply:GetPos()+ply:GetForward()*64+Vector(0, 0, 64))
ply:EnterVehicle(ply.Jeep)
end

function GM:CanExitVehicle( v, ply )
return false
end[/lua]

Untested, place it in your init.lua of your gamemode.