[HELP] How to check if Player is in a specific Vehicle (vRP/vRPmt tunnel)

Hi guys!
I want to check if the players are inside a specific vehicle (like a truck “Phantom”), otherwise: vRPclient.notify (player, {"~ r ~ You can’t complete this mission with this car."})

The code is this:

        local step = {
          text = "",
          onenter = function(player, area)  
            for idname,amount in pairs(trash_items) do
              if amount > 0 then -- check if not done
                  if vRP.tryGetInventoryItem({user_id,idname,amount,true}) then
                    local reward = v.items[idname][3]*amount
                    vRP.giveMoney({user_id,reward})
                    vRPclient.notify(player,{glang.money.received({reward})})
                    todo = todo-1
                    trash_items[idname] = 0
                    if todo == 0 then -- all received, finish mission
                    vRP.nextMissionStep({player})
                    end
                  end
                end
              end
            end
          end,
          position = v.positions[math.random(1,#v.positions)]
        }

//edit 20 characters

if IsVehicleModel(GetVehiclePedIsIn(GetPlayerPed(-1), true), GetHashKey(“Phantom”)) then

Nope.

Error running call reference function for resource vrp_basic_mission: citizen:/scripting/lua/scheduler.lua:351: server.lua:663: attempt to call a nil value (global 'GetVehiclePedIsIn')

Just tested.

I have to use it (take it from client script):

function vRPmt.isPlayerInVehicleModel(model)
  if (IsVehicleModel(GetVehiclePedIsUsing(GetPlayerPed(-1)), GetHashKey(model))) then -- just a function you can use to see if your player is in a taxi or any other car model (use the tunnel)
    return true
  else
    return false
  end
end

“just a function you can use to see if your player is in a taxi or any other car model (use the tunnel)”

I have some news: (UPDATE)

        local step = {
          text = "",
          onenter = function(player, area)
            if vRPclient.isPlayerInVehicleModel("Phantom") then
              for idname,amount in pairs(trash_items) do
                if amount > 0 then -- check if not done
                  if vRP.tryGetInventoryItem({user_id,idname,amount,true}) then
                    local reward = v.items[idname][3]*amount
                    vRP.giveMoney({user_id,reward})
                    vRPclient.notify(player,{glang.money.received({reward})})
                    todo = todo-1
                    trash_items[idname] = 0
                    if todo == 0 then -- all received, finish mission
                      vRP.nextMissionStep({player})
                    end
                  end
                end
              end
            else
              vRPclient.notify(player,{"~r~Wrong Vehicle!"})
            end
          end,
          position = v.positions[math.random(1,#v.positions)]
        }

When i pass on checkpoint without a vehicle, server send me a notify “Wrong Vehicle!” and nothing happens! So it’s good! But the same happens if i stay in a vehicle (“Phantom” in this case) :frowning:

Passing values from and to the client in vRP (outside the vRP resource) should look something like this (At least in 0.5):

local step = {
    text = "",
    onenter = function(player, area)
        vRPclient.isPlayerInVehicleModel(player, {"phantom"}, function(in_vehicle)
            if in_vehicle then
                for idname, amount in pairs(trash_items) do
                    if amount > 0 then -- check if not done
                        if vRP.tryGetInventoryItem({user_id, idname, amount, true}) then
                            local reward = v.items[idname][3] * amount
                            vRP.giveMoney({user_id, reward})
                            vRPclient.notify(player, {glang.money.received({reward})})
                            todo = todo - 1
                            trash_items[idname] = 0
                            if todo == 0 then -- all received, finish mission
                                vRP.nextMissionStep({player})
                            end
                        end
                    end
                end
            else
                vRPclient.notify(player, {"~r~Wrong Vehicle!"})
            end
        end)
    end,
    position = v.positions[math.random(1, #v.positions)]
}

At first, thank you so much!
But i have a problem with your fix. When i pass on checkpoint without a vehicle, a server send me a nitify “Wrong Vehicle!” so it’s good! But the same happens with a car model “Phantom”. The same message “Wrong Vehicle!” The good thing is that the mission remain not completed.

PS: No console error, NOTHING.

I fixed, can you lock this thred

How did you manage to fix this? I’m also trying to call for a specific vehicle

1 Like