[Release][ESX] onyxLocksystem | Keys, Hotwiring

Was developing this for my server and thought I’d release it as it’s a decent start for other servers to use for car keys I feel.

I will continue to update this script as I progress it with my server as there’s more features planned to be implemented and optimized.

Features:

  • Locking/Unlocking vehicles with keys
  • Hotwiring vehicles with multiple stages
  • Searching the glovebox with a chance to find spare keys
  • Synced with the server so players cant spam abuse searching the same car
  • Stores the vehicles plate to check if players have keys for the car with that plate
  • Steal keys from locals by holding them up

Scripts needed
ESX
Progress Bars
Mythic Notify

If you do not want to use Mythic Notify or Progress Bars just remove them from the code.

Download:
GitHub (v1.0)

Use
To give keys to players from different scripts use the exports function inside other scripts

exports["onyxLocksystem"]:givePlayerKeys(plate)

Screenshots

18 Likes

Nice :slight_smile:

Currently any vehicle that is spawned via command or similar system must be hotwired. Not sure if theres an event that can be attached on vehicle spawn to solve the issue though.

Inside your command you spawn the vehicle call the function from the lock system script

E.G

local plate = GetVehicleNumberPlateText(veh)
exports["onyxLocksystem"]:givePlayerKeys(plate)

perfect then

1 Like

Is there any bug fixes?

1 Like

If you find any bugs, let me know and I’ll fix them.

i have used this

local plate = GetVehicleNumberPlateText(veh)
exports[“onyxLocksystem”]:givePlayerKeys(plate)

in the spawn car part of my script’s but still getting the G search H hotwire

its not giving key’s

any more idea’s for a fix

Make sure your getting the actual plate for the vehicle you are spawning and not just putting “veh” as an empty variable.

Your “CreateVehicle” function make sure its a variable

E.G local veh = CreateVehicle() so you can pass it into the givePlayerKeys function

Check your f8 console for an error. I’m imaging you’re getting one in regards to the local plate.

If it was a part of your script you should’ve known where and how to use the function.
Anyway, mind giving us the partial code where you try to put it so we can fix it for you?

@HighHowdy The locking feature is inside or not yet?

IS there a way for spawned in vehicles wont need to be hotwired? and the car turns on as soon as you try hotwire it

i’ve tried adding the export to es_extended > client main.lua for the spawn function as such with no luck:

RegisterNetEvent('esx:spawnVehicle')
AddEventHandler('esx:spawnVehicle', function(vehicle)
	local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))

	if IsModelInCdimage(model) then
		local playerPed = PlayerPedId()
		local playerCoords, playerHeading = GetEntityCoords(playerPed), GetEntityHeading(playerPed)

		ESX.Game.SpawnVehicle(model, playerCoords, playerHeading, function(vehicle)
			TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
			local veh = GetVehiclePedIsIn(ped, vehicle)
			local plate = GetVehicleNumberPlateText(veh)
			exports["onyxLocksystem"]:givePlayerKeys(plate)
		end)
	else
		TriggerEvent('chat:addMessage', { args = { '^1SYSTEM', 'Invalid vehicle model.' } })
	end
end)

I get the following error:

You need to fix your local, it states “veh” and not “vehicle”

local plate = GetVehicleNumberPlateText(vehicle)
2 Likes

Thanks, ill try that

1 Like

Can confirm it works now. Thanks Cormac <3

RegisterNetEvent('esx:spawnVehicle')
AddEventHandler('esx:spawnVehicle', function(vehicle)
	local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))

	if IsModelInCdimage(model) then
		local playerPed = PlayerPedId()
		local playerCoords, playerHeading = GetEntityCoords(playerPed), GetEntityHeading(playerPed)

		ESX.Game.SpawnVehicle(model, playerCoords, playerHeading, function(vehicle)
			TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
			local veh = GetVehiclePedIsIn(ped, vehicle)
			local plate = GetVehicleNumberPlateText(vehicle)
			exports["onyxLocksystem"]:givePlayerKeys(plate)
		end)
	else
		TriggerEvent('chat:addMessage', { args = { '^1SYSTEM', 'Invalid vehicle model.' } })
	end
end)
2 Likes

np :smiley:

I’m having issues getting this to work with esx_vehicleshop where when I purchase a vehicle I no longer have to hotwire. Any help is appreciated

I do not have esx_vehicleshop as I use my own script but I assume you would change

ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
    if success then
        IsInShopMenu = false
        menu2.close()
        menu.close()
        DeleteDisplayVehicleInsideShop()

        ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
            TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
            SetVehicleNumberPlateText(vehicle, generatedPlate)

            FreezeEntityPosition(playerPed, false)
            SetEntityVisible(playerPed, true)
        end)
    else
        ESX.ShowNotification(_U('not_enough_money'))
    end
end, vehicleData.model, generatedPlate)

to this

ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
    if success then
        IsInShopMenu = false
        menu2.close()
        menu.close()
        DeleteDisplayVehicleInsideShop()

        ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
            TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
            SetVehicleNumberPlateText(vehicle, generatedPlate)
            exports["onyxLocksystem"]:givePlayerKeys(generatedPlate)

            FreezeEntityPosition(playerPed, false)
            SetEntityVisible(playerPed, true)
        end)
    else
        ESX.ShowNotification(_U('not_enough_money'))
    end
end, vehicleData.model, generatedPlate)

Sorry just seen this reply, yes locking/unlocking is functional from inside the car or if you’re close to a car you have keys for by pressing “U”. Feel free to change this keybind on line 91 of client.lua