Garage - Car key

Edit garage and car key commands

Add Car Key

This function, located in gksphone/client/settings.lua, is used to give the player the vehicle key. It works based on the vehicle key script installed on the server.

--- Function to give a key to a car
--- Located in: gksphone/client/settings.lua
--- Modify this function according to your key system
--- @param callback_vehicle number The vehicle entity
function GiveKeyCar(callback_vehicle)
  if GetResourceState('qs-vehiclekeys') == 'started' then
    local model = GetDisplayNameFromVehicleModel(GetEntityModel(callback_vehicle))
    local plate = GetVehicleNumberPlateText(callback_vehicle)
    exports['qs-vehiclekeys']:GiveKeys(plate, model, true)
  elseif GetResourceState('qb-vehiclekeys') == 'started' then
    local plate = GetVehicleNumberPlateText(callback_vehicle)
    TriggerEvent("vehiclekeys:client:SetOwner", plate)
  end
  -- New systems can be added here ↓↓↓
  -- local plate = GetVehicleNumberPlateText(callback_vehicle)
  -- Add the export or trigger of the key command you are using here
end

Garage

You will edit the framework file you are using in the gksphone/server/framework/ directory.

Garage SQL

Set the default options for the following sections according to your garage script.

Config.GarageDBColumn = "garage" -- Set column name of garage name in owned_vehicles or player_vehicles database (esx: parking / qb: garage)
Config.GarageDefaultName = "pillboxgarage" -- Set the default garage name (default: pillboxgarage)
Config.GarageStored = "state = 1"  -- Vehicle garage status

Car status info

This section determines whether the vehicle is outside or impounded according to the garage script.

function GetCharacterAllVehicles(identifier, appname)
    -- There are examples for the following other scripts
    -- You need to configure this section according to the garage script you are using.
    -- These values are found in the player_vehicles / owned_vehicles table.
    if GetResourceState("qb-garages") == "started"  then
        if vehicle.state == 2 then
            vehData.garage = "Impounded"
        elseif vehicle.state == 0 then
            vehData.garage = "Out"
        end
    elseif GetResourceState("cd_garage") == "started" or GetResourceState("jg-advancedgarages") == "started" then
        vehData.garage = vehicle.garage_id
        if not vehicle.in_garage then
            vehData.garage = "On The Street"
        end
        if vehicle.impound ~= 0 then
            vehData.garage = "Impounded"
        end
    elseif GetResourceState("loaf_garage") == "started" then
        if vehicle.state == 0 then
            vehData.garage = "On The Street"
        elseif vehicle.state == 2 then
            vehData.garage = "Impounded"
        end
    end
end

Bring control

This function checks whether the car called is impounded or outside.

function GetVehicle(identifier, plate)
    -- The following sections are examples for other scripts.
    -- You should organize it according to your own script.
    -- You can view the values here in SQL.
    if GetResourceState("cd_garage") == "started" or GetResourceState("jg-advancedgarages") == "started" then
        if ret.impound ~= 0 then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is impounded | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carimpounded"
        elseif not ret.in_garage then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is not in garage | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carnotingarage"
        end
    elseif GetResourceState("loaf_garage") == "started" then
        if ret.stored == 2 then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is impounded | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carimpounded"
        elseif ret.stored == 0 then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is not in garage | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carnotingarage"
        end
    elseif GetResourceState("qb-garages") == "started" then
        if ret.state == 2 then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is impounded | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carimpounded"
        elseif ret.state == 0 then
            Debugprint("gksphone:server:vale:vehiclebring | Vehicle is not in garage | CitizenID: " .. identifier .. " | Plate: " .. plate)
            return "carnotingarage"
        end
    end    
end

After Bring

Changing some parts in SQL when bringing a car

function VehicleUpdate(plate, app, data)
    -- Below are some examples of scripts.
    -- Setting to indicate that the car is outside via SQL after calling the car
    if GetResourceState("loaf_garage") == "started" then
        MySQL.Async.execute('UPDATE player_vehicles SET `state` = @state WHERE `plate` = @plate', {
            ['@plate'] = plate,
            ['@state'] = 0,
        })
    elseif GetResourceState("cd_garage") == "started" or GetResourceState("jg-advancedgarages") == "started" then
        MySQL.Async.execute('UPDATE player_vehicles SET  `in_garage` = @in_garage WHERE `plate` = @plate', {
            ['@plate'] = plate,
            ['@in_garage'] = 0,
        })
    elseif GetResourceState("qb-garages") == "started" then
        MySQL.Async.execute('UPDATE player_vehicles SET  `state` = @state WHERE `plate` = @plate', {
            ['@plate'] = plate,
            ['@state'] = 0,
        })
    end
end

Last updated