You are using an unsupported browser. Please update your browser to the latest version on or before July 31, 2020.
close
You are viewing the article in preview mode. It is not live at the moment.
Home > fivem car key script > fivem car key script

Fivem Car Key Script Online

-- 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)

if targetPlayer then local keyItem = string.format('%s_%s', Config.KeyItem, plate) targetPlayer.addInventoryItem(keyItem, 1) TriggerClientEvent('carkeys:keyReceived', targetId, plate) Config.Notify('Key given for vehicle: ' .. plate, 'success') end end) 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 -- Toggle engine on/off (only if you have key) Citizen

-- Lock/unlock keybind Config.Keybind = 'L' -- default key to lock/unlock false) then local vehicle = GetVehiclePedIsIn(ped

-- Check if player has key for specific plate lib.callback.register('carkeys:hasKey', function(source, plate) local xPlayer = Framework.GetPlayerFromId(source) local keyItem = string.format('%s_%s', Config.KeyItem, plate) local count = xPlayer.getInventoryItem(keyItem).count return count > 0 end) local Framework = nil local currentVehicle = nil local engineOn = false local vehicleLocked = true local ownedVehicles = {} -- store plate -> hasKey -- Load framework Citizen.CreateThread(function() if Config.Framework == 'esx' then TriggerEvent('esx:getSharedObject', function(obj) Framework = obj end) elseif Config.Framework == 'qb' then Framework = exports['qb-core']:GetCoreObject() end end)

Feedback
22 out of 27 found this helpful

scroll to top icon