Functions

Included in the script is a file called functions.lua which is not obfuscated and can be edited according to the needs of each server.

FUNCTIONS FILE

--    ____ __     ____ ___  ___  ____ __  __ ______  __ 
--   ||    ||    ||    ||\\//|| ||    ||\ || | || | (( \
--   ||==  ||    ||==  || \/ || ||==  ||\\||   ||    \\ 
--   ||___ ||__| ||___ ||    || ||___ || \||   ||   \_))
--                     CLIENT SIDE

--This function is activated when the garage UI is active. To hide the screen elements.

function hideElements()
    DisplayRadar(false)
end

--This function is activated when the garage UI is disabled. To display the screen elements.

function showElements()
    DisplayRadar(true)
end

--   __ __  ____ __  __ __   ___ __     ____     __  ____   ___  __    __ __  __
--   || || ||    ||  || ||  //   ||    ||       (( \ || \\ // \\ ||    || ||\ ||
--   \\ // ||==  ||==|| || ((    ||    ||==      \\  ||_// ||=|| \\ /\ // ||\\||
--    \V/  ||___ ||  || ||  \\__ ||__| ||___    \_)) ||    || ||  \V/\V/  || \||
--                               CLIENT SIDE
--Vehicle spawning function

    function spawnVehicle(model, actualGarage)
        if type(actualGarage) == "vector3" then -- for jobs garages
            local garageCoords = actualGarage
            local model = GetHashKey(model)
            if not IsModelInCdimage(model) then return end
            RequestModel(model)
            while not HasModelLoaded(model) do Citizen.Wait(10) end
            local vehicle = CreateVehicle(tonumber(model), actualGarage.x, actualGarage.y, actualGarage.z, 100.00, true, false)
            SetModelAsNoLongerNeeded(model)
            return vehicle
        else -- others garages
            local playerCoord = GetEntityCoords(PlayerPedId())
            SetEntityCoords(PlayerPedId(), playerCoord.x+2, playerCoord.y, playerCoord.z-1.0, false, false, false, true)
            local garageCoords = nil
            if Garages[actualGarage] == nil then
                garageCoords = actualGarage
            else
                garageCoords = Garages[actualGarage].spawn
            end
            if not IsModelInCdimage(model) then return end
            RequestModel(model)
            while not HasModelLoaded(model) do Citizen.Wait(10) end
            local vehicle = nil
            if garageCoords ~= nil then
                vehicle = CreateVehicle(tonumber(model), garageCoords.x, garageCoords.y, garageCoords.z, 100.00, true, false)
            else
                vehicle = CreateVehicle(tonumber(model), playerCoord.x, playerCoord.y, playerCoord.z, 100.00, true, false)
            end
            if Garages[actualGarage] == nil and garageCoords ~= nil then
                SetEntityHeading(vehicle, garageCoords.w)
            elseif Garages[actualGarage] ~= nil then
                SetEntityHeading(vehicle, Garages[actualGarage].heading)
            else
                local playerHeading = GetEntityHeading(PlayerPedId())
                SetEntityHeading(vehicle, playerHeading)
            end
            SetModelAsNoLongerNeeded(model)
            return vehicle
        end
    end

--    ______  ____ __     ____ ____    ___   ____  ______    __ __  __   ____ ____ 
--    | || | ||    ||    ||    || \\  // \\  || \\ | || |    || || (( \ ||    || \\
--      ||   ||==  ||    ||==  ||_// ((   )) ||_//   ||      || ||  \\  ||==  ||_//
--      ||   ||___ ||__| ||___ ||     \\_//  || \\   ||      \\_// \_)) ||___ || \\
--                                 CLIENT SIDE

--This function is activated by clicking on the "Drive" button, makes the character teleport to the side of the vehicle and access it.

function teportUser(playerPED, vehicle)
    TaskEnterVehicle(playerPED, vehicle, -1, -1, 1.0, 16, 0)
end

--    __ __  ____ _  _  __ 
--    || // ||    \\// (( \
---   ||<<  ||==   \/   \\ 
--    || \\ ||___ //   \_))
--         CLIENT SIDE

--Use only if you use your own key system.

function giveKeys(playerID, plate, vehicle)
    --example with qb
    --TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(vehicle))
end

--    ____   ___  _  _ ___  ___  ____ __  __ ______  __ 
--    || \\ // \\ \\// ||\\//|| ||    ||\ || | || | (( \
--    ||_// ||=||  )/  || \/ || ||==  ||\\||   ||    \\ 
--    ||    || || //   ||    || ||___ || \||   ||   \_))
--                     CLIENT SIDE

--Function for sending fee invoices to users.

function payTaxes(source, typetax, amount)
    TriggerServerEvent('esx_billing:sendBill', source, 'society_police', typetax, amount)
end

--    ____   ___  ____    ___  ____     ____    ___   __    __   ___  ____    __  __   ___   ______ __
--    || \\ // \\ || \\  // \\ || \\    || \\  // \\  ||    ||  //   ||       ||\ ||  // \\  | || | ||
--    ||_// ||=|| ||  )) ||=|| ||_//    ||_// ((   )) ||    || ((    ||==     ||\\|| ((   ))   ||   ||
--    || \\ || || ||_//  || || || \\    ||     \\_//  ||__| ||  \\__ ||___    || \||  \\_//    ||   ||
--                                           CLIENT SIDE

--Here you can configure the notification that the police will receive when a speed camera is triggered. You can add your dispatch for example

function customPoliceNotification(speed, coords)
    --TriggerServerEvent("bit-garage:NotifyPolice", speed, coords)
end

--Here you can edit the way the invoice or bill is sent to the user.

function sendBill(playerID, amount)
    --TriggerServerEvent('esx_billing:sendBill', playerID, 'society_police', typetax, amount)
end


--    ____   ___  ____    ___  ____     __ ___  ___  ___    ___   ____
--    || \\ // \\ || \\  // \\ || \\    || ||\\//|| // \\  // \\ ||   
--    ||_// ||=|| ||  )) ||=|| ||_//    || || \/ || ||=|| (( ___ ||== 
--    || \\ || || ||_//  || || || \\    || ||    || || ||  \\_|| ||___
--                           CLIENT SIDE

--The variable "image" is the path of the image captured by the radar. This function is simply if you want to use that variable for something specific, such as sending it to a MDT.

function radarImage(image)

end


--    __ ___  ___ ____    ___   __ __ __  __  ____ ____      __ __  ____ __  __ __   ___ __     ____     __  ____   ___  __    __ __  __
--    || ||\\//|| || \\  // \\  || || ||\ || ||    || \\     || || ||    ||  || ||  //   ||    ||       (( \ || \\ // \\ ||    || ||\ ||
--    || || \/ || ||_// ((   )) || || ||\\|| ||==  ||  ))    \\ // ||==  ||==|| || ((    ||    ||==      \\  ||_// ||=|| \\ /\ // ||\\||
--    || ||    || ||     \\_//  \\_// || \|| ||___ ||_//      \V/  ||___ ||  || ||  \\__ ||__| ||___    \_)) ||    || ||  \V/\V/  || \||
--                                                          CLIENT SIDE
--Function for spawning vehicles in the impouneds area

function impounedVehicleSpawn(model, coord, heading)
    model = tonumber(model)
    if not IsModelInCdimage(model) then return end
    RequestModel(model)
    while not HasModelLoaded(model) do Citizen.Wait(10) end
    local vehicle = CreateVehicle(tonumber(model), coord.x, coord.y, coord.z, 100.00, true, false)
    if Garages[actualGarage] == nil then
        SetEntityHeading(vehicle, heading)
    else
        SetEntityHeading(vehicle, heading)
    end
    SetModelAsNoLongerNeeded(model)
    return vehicle
end

--    __ ___  ___ ____    ___   __ __ __  __ ____      ___  ___   ___    _  __  ____ _  _
--    || ||\\//|| || \\  // \\  || || ||\ || || \\     ||\\//||  // \\  ||\ || ||    \\//
--    || || \/ || ||_// ((   )) || || ||\\|| ||  ))    || \/ || ((   )) ||\\|| ||==   )/ 
--    || ||    || ||     \\_//  \\_// || \|| ||_//     ||    ||  \\_//  || \|| ||___ //

function removeMoneyImpound(xPlayer, price)
    if Config.Framework == "esx" then
        xPlayer.removeMoney(price)
    elseif Config.Framework == "qb" then
        xPlayer.Functions.RemoveMoney('cash', price, "Impound")
    end
end

--    __ __  __   ___  ____  __     ____    __ ______  ____ ___  ___  __ 
--    || || (( \ // \\ || )) ||    ||       || | || | ||    ||\\//|| (( \
--    || ||  \\  ||=|| ||=)  ||    ||==     ||   ||   ||==  || \/ ||  \\ 
--    \\_// \_)) || || ||_)) ||__| ||___    ||   ||   ||___ ||    || \_))
--                              SERVER SIDE
--        BE CAREFUL! NOTE THAT THERE ARE PARTS FOR ESX AND FOR QB

--Function to make the lockpicking item usable.

function lockPickItem()
    --##### ESX #####
    if Config.Framework == "esx" then
        ESX.RegisterUsableItem(Config.lockpickItem, function(source)
            TriggerClientEvent('bit-garage:startlockpicking', source)
        end)

    --##### QB #####
    elseif Config.Framework == "qb" then
        QBCore.Functions.CreateUseableItem(Config.lockpickItem, function(source)
            TriggerClientEvent('bit-garage:startlockpicking', source)
        end)
    end
end

--Function to make usable the fake and original plates

function fakePlateItems()
    --##### ESX #####
    if Config.Framework == "esx" then
        ESX.RegisterUsableItem(Config.fakePlateItem, function(source)
            local xPlayer = ESX.GetPlayerFromId(source)
            if Config.useOXInventory then
                item = exports.ox_inventory:GetItem(source, Config.toolItem, false, true)
            elseif Config.QSInventory then
                item = exports['qs-core']:GetItem(source, Config.toolItem)
            else
                item = xPlayer.getInventoryItem(Config.toolItem).count
            end
            if Config.needTool then
                if item > 0 then
                    TriggerClientEvent('bit-garage:newPlate', source)
                else
                    TriggerClientEvent("bit-garage:errors", source, Lang.forgotTool)
                end
            else
                TriggerClientEvent('bit-garage:newPlate', source)
            end
        end)
        ESX.RegisterUsableItem(Config.originalPlateItem, function(source)
            local xPlayer = ESX.GetPlayerFromId(source)
            local item = nil
            if Config.useOXInventory then
                item = exports.ox_inventory:GetItem(source, Config.toolItem, false, true)
            elseif Config.QSInventory then
                item = exports['qs-core']:GetItem(source, Config.toolItem)
            else
                item = xPlayer.getInventoryItem(Config.toolItem).count
            end
            if Config.needTool then
                if item > 0 then
                    TriggerClientEvent('bit-garage:oldPlate', source)
                else
                    TriggerClientEvent("bit-garage:errors", source, Lang.forgotTool)
                end
            else
                TriggerClientEvent('bit-garage:oldPlate', source)
            end
        end)

    --##### QB #####
    elseif Config.Framework == "qb" then
        QBCore.Functions.CreateUseableItem(Config.fakePlateItem, function(source)
            local xPlayer = QBCore.Functions.GetPlayer(source)
            if Config.useOXInventory then
                item = exports.ox_inventory:GetItem(source, Config.toolItem, false, true)
            elseif Config.QSInventory then
                item = exports['qs-core']:GetItem(source, Config.toolItem)
            else
                item = xPlayer.getInventoryItem(Config.toolItem).count
            end
            if Config.needTool then
                if item > 0 then
                    TriggerClientEvent('bit-garage:newPlate', source)
                else
                    TriggerClientEvent("bit-garage:errors", source, Lang.forgotTool)
                end
            else
                TriggerClientEvent('bit-garage:newPlate', source)
            end
        end)
        QBCore.Functions.CreateUseableItem(Config.originalPlateItem, function(source)
            local xPlayer = QBCore.Functions.GetPlayer(source)
            if Config.useOXInventory then
                item = exports.ox_inventory:GetItem(source, Config.toolItem, false, true)
            elseif Config.QSInventory then
                item = exports['qs-core']:GetItem(source, Config.toolItem)
            else
                item = xPlayer.getInventoryItem(Config.toolItem).count
            end
            if Config.needTool then
                if item > 0 then
                    TriggerClientEvent('bit-garage:oldPlate', source)
                else
                    TriggerClientEvent("bit-garage:errors", source, Lang.forgotTool)
                end
            else
                TriggerClientEvent('bit-garage:oldPlate', source)
            end
        end)

    end
end

--   ___   ___  __  __   ___   __ 
--  // \\ // \\ ||\ ||  // \\ (( \
-- (( ___ ||=|| ||\\|| (( ___  \\ 
--  \\_|| || || || \||  \\_|| \_))

function GetPlayerGang(playerID)
    if Config.Framework == "esx" then
        --
    elseif Config.Framework == "qb" then
        if QBCore.Functions.GetPlayerData().gang ~= nil then
            local userGang = QBCore.Functions.GetPlayerData().gang.name
            return userGang
        end
    end
end

--    ___  __     ____ ____  ______  __ 
--   // \\ ||    ||    || \\ | || | (( \
--   ||=|| ||    ||==  ||_//   ||    \\ 
--   || || ||__| ||___ || \\   ||   \_))

--This function is for the typical "Press E to..." alerts. Here you can add an export or trigger as you need.

useCustomAlerts = false

function customAlert(alertType, status)
    if alertType == "alert" then
        if status then
            --add export to SHOW the "Press E to enter the garage" prompt
        else
            --add export to HIDE the "Press E to enter the garage" prompt
        end
    elseif alertType == "alertsave" then
        if status then
            --add export to SHOW the "Press E to save vehicle" prompt
        else
            --add export to HIDE the "Press E to save vehicle" prompt
        end
    elseif alertType == "alertimpound" then
        if status then
            --add export to SHOW the "Press E to access" prompt
        else
            --add export to HIDE the "Press E to access" prompt
        end
    end
end


--    ___   ____   ____ __  __     ____ __ __ __  __   ___ ______ __   ___   __  __  __ 
--   // \\  || \\ ||    ||\ ||    ||    || || ||\ ||  //   | || | ||  // \\  ||\ || (( \
--  ((   )) ||_// ||==  ||\\||    ||==  || || ||\\|| ((      ||   || ((   )) ||\\||  \\ 
--   \\_//  ||    ||___ || \||    ||    \\_// || \||  \\__   ||   ||  \\_//  || \|| \_))

-- CLIENT SIDE
--Function that is executed just after declaring the ESX or QBCore variable, you can use it for whatever you need
function openClient()

end

-- SERVER SIDE
--Function that is executed just after declaring the ESX or QBCore variable, you can use it for whatever you need
function openServer()

end

Last updated