Fivem Car Key - Script

Fivem Car Key - Script

dependencies { 'es_extended' -- or 'qb-core' depending on your framework } Config = {} -- Framework (esx or qb) Config.Framework = 'esx' -- change to 'qb' if using QBCore

-- Lock/unlock keybind Config.Keybind = 'L' -- default key to lock/unlock fivem car key script

server_scripts { 'config.lua', 'server.lua' } dependencies { 'es_extended' -- or 'qb-core' depending on

-- Toggle engine on/off (only if you have key) Citizen.CreateThread(function() while true do Citizen.Wait(0) if IsControlJustPressed(0, 303) then -- U key (change in config) local ped = PlayerPedId() if IsPedInAnyVehicle(ped, false) then local vehicle = GetVehiclePedIsIn(ped, false) local plate = GetVehicleNumberPlateText(vehicle) lib.callback.await('carkeys:hasKey', false, plate) if hasKey then engineOn = not engineOn SetVehicleEngineOn(vehicle, engineOn, false, true) if engineOn then Config.Notify('Engine started', 'success') else Config.Notify('Engine turned off', 'info') end else Config.Notify('You don't have the key!', 'error') end end end end end) false) then local vehicle = GetVehiclePedIsIn(ped

-- Get vehicle from player's last entered Citizen.CreateThread(function() while true do Citizen.Wait(1000) local ped = PlayerPedId() if IsPedInAnyVehicle(ped, false) then local vehicle = GetVehiclePedIsIn(ped, false) if vehicle ~= currentVehicle then currentVehicle = vehicle local plate = GetVehicleNumberPlateText(vehicle) -- Check if player has key lib.callback.await('carkeys:hasKey', false, plate) hasKey = result if not hasKey then Config.Notify('You do not have the key for this vehicle!', 'error') -- Eject player from driver seat if GetPedInVehicleSeat(vehicle, -1) == ped then TaskLeaveVehicle(ped, vehicle, 0) end else vehicleLocked = false Config.Notify('You have the key for this vehicle', 'success') end end else currentVehicle = nil engineOn = false end end end)