Custom Framework - Server

Framework check

At the top of the file, add a check for Config.Framework. If it's not set to your framework, return to prevent it from loading.

if Config.Framework ~= "your-framework" then
    return
end

Framework functions

You need to implement the following functions for the racing script to work with your framework.

IsAdmin

Check if a player is an admin.

---@return boolean
function IsAdmin(source)
    return IsPlayerAceAllowed(source, "command.lbracing_admin") == 1
end

GetIdentifier

Get a player's identifier. If you use multicharacter, make sure to return the identifier of the current character.

---@param source number
---@return string?
function GetIdentifier(source)
    ---@diagnostic disable-next-line: param-type-mismatch
    return GetPlayerIdentifierByType(source, "license")
end

GetSourceFromIdentifier

Get a source from an identifier.

---@param identifier string
---@return number?
function GetSourceFromIdentifier(identifier)
    local players = GetPlayers()
 
    for i = 1, #players do
        if GetPlayerIdentifierByType(players[i], "license") == identifier then
            ---@diagnostic disable-next-line: return-type-mismatch
            return players[i]
        end
    end
end

GetCharacterName

Get the first and last name of a character.

---@param source number
---@return string firstName
---@return string lastName
function GetCharacterName(source)
    return GetPlayerName(source), tostring(source)
end

DoesPlayerOwnVehicle

Check if a player owns a vehicle.

---@param source number
---@param plate string
---@param vehicle number
---@return boolean
function DoesPlayerOwnVehicle(source, plate, vehicle)
    return true
end

CreateUsableItem (optional)

Create a usable item, with a handler.

---@param item string
---@param cb function
function CreateUsableItem(item, cb)
    -- ESX.RegisterUsableItem(item, cb)
end

Money functions

GetMoney

Get the player's current bank balance.

---@param source number
---@return number
function GetMoney(source)
    return 0
end

RemoveMoney

Remove money from a player's bank balance.

---@param source number
---@param amount number
---@return boolean
function RemoveMoney(source, amount)
    return true
end

RemoveMoneyOffline

Remove money from an offline character's bank balance.

---@param identifier string
---@param amount number
---@return boolean
function RemoveMoneyOffline(identifier, amount)
    return true
end

AddMoney

Add money to a player's bank balance.

---@param source number
---@param amount number
---@return boolean
function AddMoney(source, amount)
    return true
end

AddMoneyOffline

Add money to an offline character's bank balance.

---@param identifier string
---@param amount number
---@return boolean
function AddMoneyOffline(identifier, amount)
    return true
end

Events

Player loaded

Trigger the lb-racing:playerLoaded event when a character has loaded.

---@param source number
---@param playerData { identifier: string }
AddEventHandler("yourFramework:playerLoaded", function(source, playerData)
    TriggerEvent("lb-racing:playerLoaded", source, playerData.identifier)
end)

Player unloaded

Trigger the lb-racing:playerUnloaded event when a character unloads.

AddEventHandler("yourFramework:playerUnloaded", function(source)
    local identifier = GetIdentifier(source)
 
    if identifier then
        TriggerEvent("lb-racing:playerUnloaded", source, identifier)
    end
end)