• Vehicle driver seat question
    9 replies, posted
Well, i am keen on finding the script which allows to enter the driver seat of the specific vehicle only for one job.
You’ll need to return false in this hook: GM/CanPlayerEnterVehicle if you don’t want the player provided to enter a specific vehicle. Implementation is left as an excercise for the reader.
local allowedJobs = { "Citizen", "Civil Officer", "Mayor" } hook.Add("CanPlayerEnterVehicle", "JobOnlyVehicles", function(ply, veh) local job = ply:getJobTable().name for k, v in pairs(allowedJobs) do if(v == job) then return true end end return false end) This should do it
yeah, i guess it its, but where can i get the name like prop_vehicle_airboat ?
Look at the vehicle you want to get the name of and type this in console (Client console) lua_run_cl print(LocalPlayer():GetEyeTrace().Entity:GetClass())
gives nothing
You should check console for errors next time, the code above would obviously throw some for multiple reasons. Try this fixed code: local tVehicleWhitelist = { ["prop_vehicle_airboat"] = { ["Citizen"] = true, ["Gun Dealer"] = true, ["Hobo"] = true }, ["prop_vehicle_jeep"] = { ["Civil Officer"] = true, ["Mayor"] = true }, ["prop_vehicle_prisoner_pod"] = { ["Gangster"] = true, ["Mob Boss"] = true } } hook.Add("CanPlayerEnterVehicle", "JobSpecificVehicles", function(pPlayer, pVehicle) local sJob = pPlayer:getJobTable().name -- Player doesn't have a job name for some reason -- Allow them to enter by default -- This can be avoided by using TEAM_* enums instead of job names if (sJob == nil) then return end local tVehicleJobs = tVehicleWhitelist[pVehicle:GetClass()] -- If the vehicle isn't registered, allow anyone to enter -- If the job is in the vehicle table, allow the player to enter if (tVehicleJobs == nil or tVehicleJobs[sJob]) then return -- Let other hooks have a chance! end return false end)
Thank you! But stiil, i cant understand how to get the name like prop_vehicle_airboat
ubre's solution works, just make sure you have sv_allowcslua enabled.
thanks man, what would i do without your help!
Sorry, you need to Log In to post a reply to this thread.