cfg_functions.lua
local Config = require("config.cfg_main")
local Locales = require("config.cfg_locales")
--[[ Notify ]]
--- Sends a notification to the client.
--- @param data {title: string, description: string, type: string, duration: number, position?: string}
local function ClientNotify(data)
lib.notify({
title = data.title,
description = data.description,
type = data.type,
duration = data.duration,
position = data.position or "top-left",
style = { backgroundColor = "#1E1E1E" },
})
end
--- Sends a notification from the server to a specific client.
--- @param source number Player source ID
--- @param data {title: string, description: string, type: string, duration: number, position?: string}
local function ServerNotify(source, data)
TriggerClientEvent("ox_lib:notify", source, {
title = data.title,
description = data.description,
type = data.type,
duration = data.duration,
position = data.position or "top-left",
style = { backgroundColor = "#1E1E1E" },
})
end
--[[ Interaction ]]
--- Displays a help text.
--- @param msg string The message to display
local function HelpText(msg)
AddTextEntry("textUI", msg)
DisplayHelpTextThisFrame("textUI", false)
end
--- Displays floating help text near an entity or specific coordinates.
--- @param entity? number The entity ID (optional)
--- @param coords? vector3 The coordinates (required if entity is nil)
--- @param msg string The message to display
local function FloatingHelpText(entity, coords, msg)
AddTextEntry("FloatingHelpText", msg)
SetFloatingHelpTextStyle(1, 1, 2, -1, 3, 0)
BeginTextCommandDisplayHelp("FloatingHelpText")
EndTextCommandDisplayHelp(2, false, false, -1)
if entity then
local entityCoords = GetEntityCoords(entity)
SetFloatingHelpTextWorldPosition(1, entityCoords.x, entityCoords.y, entityCoords.z + 0.85)
elseif coords then
SetFloatingHelpTextWorldPosition(1, coords.x, coords.y, coords.z)
end
end
--- Adds a target box zone to bank locations.
--- @param data table The bank location data.
local function AddBankTarget(data)
exports.ox_target:addBoxZone({
coords = data.Coords,
size = data.Interaction.Target.BoxZoneSize,
drawSprite = data.Interaction.Target.DrawSprite,
options = {
icon = Locales.Interaction.Target.OpenBanking.Icon,
label = Locales.Interaction.Target.OpenBanking.Label,
onSelect = function()
Interaction.OpenBanking()
end,
distance = data.Interaction.Target.Distance,
canInteract = function()
return not IsPedInAnyVehicle(cache.ped, false)
end,
},
})
end
--- Adds a target to ATM models.
--- @param model string The ATM model to add the target to.
local function AddATMTarget(model)
exports.ox_target:addModel(model, {
icon = Locales.Interaction.Target.OpenATM.Icon,
label = Locales.Interaction.Target.OpenATM.Label,
onSelect = function()
if Config.ATM.Animation.Enabled then ATM.Anim() end
Interaction.OpenBanking()
end,
distance = Config.ATM.Interaction.Target.Distance,
canInteract = function()
return not IsPedInAnyVehicle(cache.ped, false)
end,
})
end
return {
Notify = {
Client = ClientNotify,
Server = ServerNotify,
},
Interact = {
HelpText = HelpText,
FloatingHelpText = FloatingHelpText,
Target = {
Bank = AddBankTarget,
ATM = AddATMTarget,
},
},
}
Last updated