only owner can enter or use

hi! i have a question, ive made some changes from a darkrp car dealer to work with my gamemode but my problem is anyone can enter that car now, would i have to modify the car to only let the person who spawned it into the car or could i make an entity to do that?

When the entity is spawned you can just do something like Ent.Owner = ply

And on CanPlayerEnterVehicle you would check that the owner of the car is the same as the player.

I am assuming you can do that, at least if you’re making a gamemode i would i expect you could.

Pseudo:

GM:CanPlayerEnterVehicle( ply, vehi )
if( vehi.Owner == ply ) then return true else return false end
end
Good luck!


hook.Add("PlayerEnteredVehicle","Onwneronlyenters",function( ply, veh) if veh:GetOwner() == ply then return true else return false end end)

thanks il try that out soon!

[editline]11th May 2015[/editline]

also seems quite easy i thought it would be alot harder to do!

[editline]11th May 2015[/editline]

also even im really dumb at lua and playerenteredvehicle means when they are in it right? and CanPlayerEnterVehicle Is Checking If they can or not…
http://wiki.garrysmod.com/page/GM/PlayerEnteredVehicle

[editline]11th May 2015[/editline]

this didnt work and i tried to see what the error was but line 55 is the if (vehi.Owner …

error:



[ERROR] gamemodes/gt/gamemode/init.lua:55: '' expected near 'end'
  1. unknown - gamemodes/gt/gamemode/init.lua:0


nevermind changed the code around a bit and thanks AIX-Who for the gamemode function!

my new code:



function GM:CanPlayerEnterVehicle( ply, vehi ) 
if vehi.Owner == ply or vehi.Owner == nil then
	return true
else
	ply:ChatPrint("You Do Not Have Access To This Personal Vehicle")
	end
end