I am using vrp and was trying to make a basic script to make it so you have to be set as the correct job to use a particular vehicle but I could not get my head around the tunnelling etc so I took a different approach to it and decided to add this to the bottom of vrp_garages\client.lua
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
local user_id = vRP.getUserId({source})
if vRP.hasGroup(user_id, "EMS") or vRP.hasGroup(user_id, "citizen") and IsPedInAnyVehicle(ped) then
if IsVehicleModel(car, GetHashKey("flatbed3",_r)) then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
else if vRP.hasGroup(user_id, "mechanic") and IsPedInAnyVehicle(ped) then
if IsVehicleModel(car, GetHashKey("flatbed3",_r)) then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
end
end
end
end
end
end)
It is half working in the sense that if a player gets in the flatbed3 then it makes it undriveable and it displays the message however, this occurs no matter what your job is set as.
Any help of any sort to get this working will be very much appreciated
Because when it enter the first if condition it instantly enter on the IsVehicleModel because you did not specifies a specific group in this if condition
So if the user is in the EMS group or the citizen one and the user is in flatbed3 it execute the condition, no matter the job
You need to redo a little bit of code here and there but you were almost good
if IsVehicleModel(car, GetHashKey("flatbed3",_r)) then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
else if vRP.hasGroup(user_id, "mechanic") and IsPedInAnyVehicle(ped) then
if IsVehicleModel(car, GetHashKey("flatbed3",_r)) then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
end
end
end
This part can be replace by this :
if IsVehicleModel(car, GetHashKey("flatbed3", _r)) and IsPedInAnyVehicle(ped) then
if vRP.hasGroup(user_id, "mechanic") then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
end
end
So to explain, first you check everything regarding the vehicle properties (is it the good vehicle and is the ped actually in the vehicle) then you check the job/group of the ped, which in this must be mechanic
If you have any question about the code just mention me and I’ll try to help
hmm still not working, I can now drive it with being set to any job and it does not show the message
just to check, this is the full code:
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
local user_id = vRP.getUserId({source})
if vRP.hasGroup(user_id, "EMS") or vRP.hasGroup(user_id, "citizen") and IsPedInAnyVehicle(ped) then
if IsVehicleModel(car, GetHashKey("flatbed3", _r)) and IsPedInAnyVehicle(ped) then
if vRP.hasGroup(user_id, "mechanic") then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
local user_id = vRP.getUserId({source})
if IsVehicleModel(car, GetHashKey("flatbed3", _r)) and IsPedInAnyVehicle(ped) then
if vRP.hasGroup(user_id, "mechanic") then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
end
end
end
end)
Look at the difference of my code and yours, this one is more organized and well indented
And i removed this:
if vRP.hasGroup(user_id, "EMS") or vRP.hasGroup(user_id, "citizen") and IsPedInAnyVehicle(ped) then
Why you check if it is EMS or Citizen, if you are going to check if it is a mechanic?
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local user_id = vRP.getUserId({source})
if IsPedInAnyVehicle(ped) then
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
if IsVehicleModel(car, GetHashKey("flatbed3", _r)) then
if vRP.hasGroup(user_id, "mechanic") then
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
vRP.notify({"You must be a Mechanic!"})
end
end
end
end
end)
Changed it, i dont know if this fix the issue…
i never worked with vrp so i dont know if the vrp part is right…
nope that’s not done it either this seems so simple but I have been working on this for a week on and off and seem to go round in circles with it lol. I appreciate you trying to help me though
You can debug this code by adding some print() in between each step of the process
For example :
print(user_id)
print(vRP.hasGroup(user_id, "mechanic"))
if vRP.hasGroup(user_id, "mechanic") then
print("User is a mechanic")
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
print("User is not a mechanic")
vRP.notify({"You must be a Mechanic!"})
end
And then open the console on the server (using F8) to check what print displays
I have added the two prints in the code but where do I put the print(user_id) and print(vRP.hasGroup(user_id, “mechanic”))?
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local user_id = vRP.getUserId({source})
if IsPedInAnyVehicle(ped) then
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
if IsVehicleModel(car, GetHashKey("flatbed3", _r)) then
if vRP.hasGroup(user_id, "mechanic") then
print("User is a mechanic")
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), false)
else
SetVehicleUndriveable(GetVehiclePedIsUsing(ped), true)
print("User is not a mechanic")
vRP.notify({"You must be a Mechanic!"})
end
end
end
end
end)
As i said, the error is the VRP part, when you get the player job, cause without that the script works, right?
If i now how to do the permissions in vrp i could help you, but I dont know the right way to do this in vrp.