Is there a resource like that? If framework tied, preferably ESX.
Hi Ticker. Welcome
You could accomplish this by locking the doors of police cars for non police players with lock state 2. If they tried to enter a police vehicle, even with the door open, nothing would happen.
There are a few ways to do this. Here’s an example from a script I wrote.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlPressed(0, 303) then -- U key
local playerPed = PlayerPedId()
local playerPos = GetEntityCoords(playerPed, false)
local vehicle = getClosestVehicle(playerPos, 5.0)
if vehicle and vehicle ~= 0 then
if ownedVehiclesSpawned[vehicle] then -- Is this vehicle's entity part of our owned vehicles table? Note: You would need to add vehicles to the table as they're created.
local isLocked = GetVehicleDoorLockStatus(vehicle) == 2
if isLocked then
SetVehicleDoorsLocked(vehicle, 1) -- Unlocked
else
SetVehicleDoorsLocked(vehicle, 2) -- Locked
end
TriggerServerEvent('updateVehicleLockState', NetworkGetNetworkIdFromEntity(vehicle), not isLocked) -- Send request to lock the veh
Citizen.Wait(250) -- Small delay to prevent repeated spam
else
-- Vehicle is not part of the ownedVehiclesSpawned table
end
end
end
end
end)
Then on the server side, you’d manage the lock states across clients.
local vehicleLockStates = {} -- A table of which vehicles are locked for the server side
RegisterServerEvent('updateVehicleLockState')
AddEventHandler('updateVehicleLockState', function(vehicleNetId, isLocked)
vehicleLockStates[vehicleNetId] = isLocked
TriggerClientEvent('syncVehicleLockState', -1, vehicleNetId, isLocked)
end)
Finally, apply the lock to the vehicle on the client.
RegisterNetEvent('syncVehicleLockState')
AddEventHandler('syncVehicleLockState', function(vehicleNetId, isLocked)
local vehicle = NetworkGetEntityFromNetworkId(vehicleNetId)
SetVehicleDoorsLocked(vehicle, isLocked and 2 or 1)
end)
You could go a bit more aggressive and simply lock vehicles by model name for civilians in a simple client loop.