FivecodeDocs
DiscordTebex StoreYoutube
  • Welcome
  • Scripts
    • Fivecode Clothing
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Armor
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Carkeys
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Roleplay Chat
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Camping
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Burger Shot Job
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode UWU Cat Cafe Job
      • Installation Guide
      • Config file
      • Tutorials
    • Fivecode Vanilla Unicorn Job
      • Installation Guide
      • Config file
      • Tutorials
  • Tutorials
    • Fivem escrow System
      • Error parsing script ... <\1>
      • Failed to verify protected resource
Powered by GitBook
On this page

Was this helpful?

  1. Scripts
  2. Fivecode Carkeys

Tutorials

PreviousConfig fileNextFivecode Roleplay Chat

Last updated 11 months ago

Was this helpful?

1.

Toggle vehicle lock/unlock export:

---@param vehicle integer
---@param status Optional[integer] (1 || 2)
exports.fivecode_carkeys:ToggleLock(vehicle, status)

Toggle vehicle lock/unlock export - EXAMPLE:

-- For example in ox_target
exports.ox_target:addGlobalVehicle({
    {
        name = 'ox_target:driverF',
        icon = 'fa-solid fa-car-side',
        label = 'Toggle Lock Vehicle',
        bones = { 'bodyshell' },
        canInteract = function(entity, distance, coords, name)

            local boneId = GetEntityBoneIndexByName(entity, 'door_dside_f')

            if boneId ~= -1 then
                return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.5 or #(coords - GetWorldPositionOfEntityBone(entity, GetEntityBoneIndexByName(entity, 'seat_dside_f'))) < 0.72
            end
        end,
        onSelect = function(data)
            exports.fivecode_carkeys:ToggleLock(data.entity)
        end
    }
})

2.

Give car keys export:

Client side:

---@param vehicle integer
---@param isSociety boolean [default false]
---@param giveKey boolean [true - give key, false - remove key]
exports.fivecode_carkeys:GiveKey(vehicle, isSociety, giveKey)

Server side:

---@param source integer
---@param vehicle integer
---@param plate string
---@param model integer
---@param isSociety boolean [default false]
---@param giveKey boolean [true - give key, false - remove key]
exports.fivecode_carkeys:GiveKey(source, {vehicle = vehicle, plate = plate, model = model}, isSociety, giveKey)

Give car keys export - EXAMPLE:

[esx_vehicleshop/server/main.lua] line - 152
ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, model, plate)
	local xPlayer = ESX.GetPlayerFromId(source)
	local modelPrice = getVehicleFromModel(model).price

	if modelPrice and xPlayer.getMoney() >= modelPrice then
		xPlayer.removeMoney(modelPrice, "Vehicle Purchase")

		MySQL.insert('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (?, ?, ?)', {xPlayer.identifier, plate, json.encode({model = joaat(model), plate = plate})
		}, function(rowsChanged)
		    xPlayer.showNotification(TranslateCap('vehicle_belongs', plate))
		    ESX.OneSync.SpawnVehicle(joaat(model), Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading,{plate = plate}, function(vehicle)
		    Wait(100)
		    local vehicle = NetworkGetEntityFromNetworkId(vehicle)
		    Wait(300)
		    TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1)
		
		    exports.fivecode_carkeys:GiveKey(source, {vehicle = vehicle, plate = plate, model = model}, false, true)
		
		end)
		cb(true)
	    end)
	else
        cb(false)
    end
end)
[qb-vehicleshop/client.lua] line - 649
RegisterNetEvent('qb-vehicleshop:client:buyShowroomVehicle', function(vehicle, plate)
    tempShop = insideShop
    QBCore.Functions.TriggerCallback('QBCore:Server:SpawnVehicle', function(netId)
        local veh = NetToVeh(netId)
        exports['LegacyFuel']:SetFuel(veh, 100)
        SetVehicleNumberPlateText(veh, plate)
        SetEntityHeading(veh, Config.Shops[tempShop]["VehicleSpawn"].w)
        TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(veh))
        TriggerServerEvent("qb-vehicletuning:server:SaveVehicleProps", QBCore.Functions.GetVehicleProperties(veh))
        
        exports.fivecode_carkeys:GiveKey(veh, false, true)

    end, vehicle, Config.Shops[tempShop]["VehicleSpawn"], true)
end)

3.

Remove/give player keys when storing/taking out vehicle from garage:

---@param vehicle integer
---@param hasStored boolean [true - Store(Take keys), false - Take out(Give Keys)]
exports.fivecode_carkeys:StoreVehicleKey(vehicle, hasStored)
---@param source integer
---@param vehicle integer
---@param model integer
---@param hasStored boolean [true - Store(Take keys), false - Take out(Give Keys)]
exports.fivecode_carkeys:StoreVehicleKey(source, {vehicle = vehicle, model = model}, hasStored)

4.

Make vehicle drivable after lockpicking it:

---@param vehicle integer
---@param status boolean [true - Can drive without a key(lockpicked), false - Can't drive without a key(not lockpicked)]
exports.fivecode_carkeys:LockpickedVehicle(vehicle, status)
---@param vehicle integer
---@param status boolean [true - Can drive without a key(lockpicked), false - Can't drive without a key(not lockpicked)]
exports.fivecode_carkeys:LockpickedVehicle(vehicle, status)

5.

Create vehicle_keys table in your database:

CREATE TABLE IF NOT EXISTS `vehicle_keys` (
     `id` INT(11) NOT NULL AUTO_INCREMENT,
     `vehId` VARCHAR(50) NULL DEFAULT NULL COMMENT 'num or society (Universal key)' COLLATE 'utf8mb4_general_ci',
     `isActive` TINYINT(4) NOT NULL DEFAULT '1',
     `isStored` TINYINT(4) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`) USING BTREE
);

Script used for this demonstration:

Script used for this demonstration:

If you need help with anything, do not hesitate and open a support ticket in our .

https://github.com/esx-framework/esx_vehicleshop
https://github.com/qbcore-framework/qb-vehicleshop
discord
How to lock/unlock vehicle with third party script ?
How to implement fivecode_carkeys with your vehicleshop so your players receive vehicle keys upon purchase of a new vehicle ?
How to implement fivecode_carkeys with your garage system so that when you store your vehicle, the keys will be removed from you, and when you take it out, they will be given to you.
How to make your vehicle drivable after lockpicking it while Config.NeedKeysToStartVehicles is true
How to create vehicle_keys table in your database