Trying to use baseevents:leftVehicle

I’m confused about the use of baseevents:leftVehicle
I want to compare the vehicle just exited to a known vehicle name. I found this for the GetHashKey function:
image

If currentVehicle is the handle to the instance of the vehicle as shown on the fivem doco page

Why do I get this when calling GetEntityModel(currentVehicle) ?

cfx> [    c-scripting-core] InvokeNative: execution failed: Tried to access invalid entity: 252674

This is my event handler

RegisterNetEvent('baseevents:leftVehicle', function(currentVehicle, currentSeat, vehicleDisplayName)
    if whitelistedVehicle(currentVehicle) then
      TriggerClientEvent('qb-taxi:client:leftVehicle', source)
    end
end)

and the function call to compare the vehicle

local function whitelistedVehicle(veh)
    local retval = false
    
    for i = 1, #Config.AllowedVehicles, 1 do
        if veh == GetHashKey(Config.AllowedVehicles[i].model) then
            retval = true
        end
    end

    if veh == GetHashKey("dynasty") then
        retval = true
    end

    return retval
end

Interestingly, this first and secon numbers here are the “handles” if I display when leaving and entering, but the third one is the result of a call to GetVehiclePedIsIn(…)
image

I just need to know how to translate the incoming veh value to something that can be compared to the GetHashKey(Config.AllowedVehicles[i].model) call.

Actually it turned out the base event passes the netId although it’s not documented in the baseevents web page. I went with this and it’s all working now:

RegisterNetEvent('baseevents:leftVehicle', function(currentVehicle, currentSeat, vehicleDisplayName, netId)
    local vehicle = NetworkGetEntityFromNetworkId(netId)

    if whitelistedVehicle(GetEntityModel(vehicle)) then
      TriggerClientEvent('qb-taxi:client:leftVehicle', source)
    end
end)
1 Like