Can anyone see the problem with this script?

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

Anyone have any ideas?

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

sorry you have lost me :flushed: so I have the code right but just in the wrong order??

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 :slight_smile:

Another thing mate, its elseif not else if (notice the space)

https://www.lua.org/pil/4.3.1.html

Useful, for learning lua: https://www.lua.org/pil/contents.html

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)

Is this how it should now look?

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?

yes i noticed that after posting this lol so i removed it but still not working, neither is your more organized and well indented one :thinking:

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…

1 Like

nope that’s not done it either :frowning: 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

do a simple test pls, remove the vrp part and test it

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

just removed the vrp part and it sets the vehicle undriveable and displays the message, will try doing the print now

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)

So if it works the error is in the vrp part mate

But as i said, i dont now to much about vrp, never worked with

Does anyone else have any ideas to try to get this working?

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.

I’m still trying to get this working if anyone with vRP experience could possibly have a look to try and figure out why this is not working?