- init changes

This commit is contained in:
Mustachedom committed 2026-08-17 03:49:37 -07:00
1 parent 8accf38f97
commit d6cffd01bc
38 files changed
+325 -3377

No files matched your search

+1 -1
View File
@@ -43,7 +43,7 @@ function Clothing.GetAppearance(entity)
return skinData
end
Callback.Register('community_bridge:cb:GetAppearance', function()
lib.callback.register('community_bridge:cb:GetAppearance', function()
local ped = PlayerPedId()
if not ped or not DoesEntityExist(ped) then return end
local skinData = Clothing.GetAppearance(ped)
+1 -1
View File
@@ -22,7 +22,7 @@ end
---@param src number
---@return table
function Clothing.GetAppearance(src)
return Callback.Trigger('community_bridge:cb:GetAppearance', src)
return lib.callback.await('community_bridge:cb:GetAppearance', src)
end
---Apply skin data to a player
+1 -1
View File
@@ -147,7 +147,7 @@ function Clothing.OpenMenu(src)
end
---Callback handler for retrieving a player's appearance data
Callback.Register('community_bridge:cb:GetAppearance', function(source)
lib.callback.register('community_bridge:cb:GetAppearance', function(source)
local src = source
return Clothing.GetAppearance(src)
end)
+1 -1
View File
@@ -167,7 +167,7 @@ AddEventHandler('onResourceStart', function(resource)
end)
--- Callback handler for retrieving a player's appearance data
Callback.Register('community_bridge:cb:GetAppearance', function(source)
lib.callback.register('community_bridge:cb:GetAppearance', function(source)
local src = source
return Clothing.GetAppearance(src)
end)
@@ -160,7 +160,7 @@ AddEventHandler('onResourceStart', function(resource)
end)
--- Callback handler for retrieving a player's appearance data
Callback.Register('community_bridge:cb:GetAppearance', function(source)
lib.callback.register('community_bridge:cb:GetAppearance', function(source)
local src = source
return Clothing.GetAppearance(src)
end)
+1 -1
View File
@@ -168,7 +168,7 @@ AddEventHandler('onResourceStart', function(resource)
end)
--- Callback handler for retrieving a player's appearance data
Callback.Register('community_bridge:cb:GetAppearance', function(source)
lib.callback.register('community_bridge:cb:GetAppearance', function(source)
local src = source
return Clothing.GetAppearance(src)
end)
+2 -2
View File
@@ -11,7 +11,7 @@ local cachedItemList = nil
---@description This is an internal function, its here to attempt to emulate qbs shared items mainly. This should not be used outside of bridge.
Framework.ItemList = function()
if cachedItemList then return cachedItemList end
local items = Callback.Trigger('community_bridge:Callback:GetFrameworkItems', false)
local items = lib.callback.await('community_bridge:Callback:GetFrameworkItems', false)
cachedItemList = { Items = items.Items or {} }
return cachedItemList
end
@@ -45,7 +45,7 @@ end
---@description This will return a table of all the jobs in the framework.
---@return table
Framework.GetFrameworkJobs = function()
local jobs = Callback.Trigger('community_bridge:Callback:GetFrameworkJobs', false)
local jobs = lib.callback.await('community_bridge:Callback:GetFrameworkJobs', false)
return jobs
end
+93 -3
View File
@@ -69,6 +69,15 @@ Framework.GetPlayerDob = function(src)
return dob
end
Framework.GetPlayerDobByIdentifier = function(citizenid)
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
if xPlayer then
return xPlayer.get("dateofbirth")
end
local result = MySQL.single.await("SELECT dateofbirth FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
return result and result.dateofbirth or nil
end
--- @description Returns the player data of the specified source in the framework defualt format
--- @param src any
--- @return table | nil
@@ -120,6 +129,15 @@ Framework.GetPlayerName = function(src)
return xPlayer.variables.firstName, xPlayer.variables.lastName
end
Framework.GetPlayerNameByIdentifier = function(citizenid)
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
if xPlayer then
return xPlayer.variables.firstName, xPlayer.variables.lastName
end
local result = MySQL.single.await("SELECT firstname, lastname FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
return result and result.firstname or nil, result and result.lastname or nil
end
---@description This will return a table of all logged in players
--- @return table
Framework.GetPlayers = function()
@@ -340,6 +358,15 @@ Framework.GetPlayerPhone = function(src)
return xPlayer.get("phone_number")
end
Framework.GetPlayerPhoneByIdentifier = function(citizenid)
local xPlayer = Framework.GetPlayerByIdentifier(citizenid)
if xPlayer then
return xPlayer.get("phone_number")
end
local result = MySQL.single.await("SELECT phone_number FROM users WHERE identifier = @identifier", {["@identifier"] = citizenid})
return result and result.phone_number or nil
end
---@description This will return the job name, label, grade name, and grade level of the player.
---@deprecated
---@param src number
@@ -404,7 +431,10 @@ Framework.GetPlayerGang = function(src)
print("ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order.")
return
end
Framework.GetPlayerGangByIdentifier = function(citizenid)
print("ESX does not support gangs, please ensure you are using a supported gang system or that you have the correct start order.")
return
end
---@description This will get a table of player sources that have the specified job name.
--- @param job string
--- @return table
@@ -441,6 +471,28 @@ Framework.AddAccountBalance = function(src, _type, amount)
return true
end
---@description This will add money based on the type of account (money/bank)
--- @param src number
--- @param _type string
--- @param amount number
--- @return boolean
Framework.AddAccountBalanceByIdentifier = function(src, _type, amount)
local xPlayer = Framework.GetPlayer(src)
if _type == 'cash' then _type = 'money' end
if amount <= 0 then return false end
if xPlayer then
xPlayer.addAccountMoney(_type, amount)
return true
end
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
if not money then return false end
local accounts = json.decode(money.accounts)
accounts[_type] = (accounts[_type] or 0) + amount
MySQL.update.await("UPDATE users SET accounts = @accounts WHERE identifier = @identifier", {["@accounts"] = json.encode(accounts), ["@identifier"] = src})
return true
end
---@description This will remove money based on the type of account (money/bank)
--- @param src number
--- @param _type string
@@ -457,6 +509,30 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
return true
end
---@description This will remove money based on the type of account (money/bank)
--- @param src number
--- @param _type string
--- @param amount number
--- @return boolean
Framework.RemoveAccountBalanceByIdentifier = function(src, _type, amount)
local xPlayer = Framework.GetPlayer(src)
if _type == 'cash' then _type = 'money' end
if amount <= 0 then return false end
if xPlayer then
local accountVal = Framework.GetAccountBalance(src, _type)
if accountVal < amount then return false end
xPlayer.removeAccountMoney(_type, amount)
return true
end
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
if not money then return false end
local accounts = json.decode(money.accounts)
if (accounts[_type] or 0) < amount then return false end
accounts[_type] = (accounts[_type] or 0) - amount
MySQL.update.await("UPDATE users SET accounts = @accounts WHERE identifier = @identifier", {["@accounts"] = json.encode(accounts), ["@identifier"] = src})
return true
end
---@description This will get money based on the type of account (money/bank)
--- @param src number
--- @param _type string
@@ -470,6 +546,20 @@ Framework.GetAccountBalance = function(src, _type)
return balance
end
Framework.GetAccountBalanceByIdentifier = function(src, _type)
local xPlayer = Framework.GetPlayerByIdentifier(src)
if _type == 'cash' then _type = 'money' end
if xPlayer then
local balance = xPlayer.getAccount(_type).money or 0
if balance <= 0 then return 0 end
return balance
end
local money = MySQL.single.await("SELECT accounts FROM users WHERE identifier = @identifier", {["@identifier"] = src})
if not money then return 0 end
local accounts = json.decode(money.accounts)
return accounts[_type] or 0
end
---@description This will add an item, and return true or false based on success
--- This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
@@ -600,13 +690,13 @@ end)
---@description Callback to get framework jobs list
---@param source number
Callback.Register('community_bridge:Callback:GetFrameworkJobs', function(source)
lib.callback.register('community_bridge:Callback:GetFrameworkJobs', function(source)
return Framework.GetFrameworkJobs() or {}
end)
---@description This is linked to an internal function, its an attempt to standardize the item list across frameworks.
---@param source number
Callback.Register('community_bridge:Callback:GetFrameworkItems', function(source)
lib.callback.register('community_bridge:Callback:GetFrameworkItems', function(source)
return Framework.ItemList() or {}
end)
+87 -1
View File
@@ -4,7 +4,7 @@ if GetResourceState('qbx_core') == 'started' then return end
Framework = Framework or {}
QBCore = exports['qb-core']:GetCoreObject()
local QBCore = exports['qb-core']:GetCoreObject()
Framework.Shared = QBCore.Shared
@@ -93,6 +93,15 @@ Framework.GetPlayerName = function(src)
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
---@description Returns the first and last name of the player.
---@return string|nil, string|nil
Framework.GetPlayerNameByIdentifier = function(id)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
---@description Returns the player date of birth.
---@param src number
---@return string|nil
@@ -103,6 +112,17 @@ Framework.GetPlayerDob = function(src)
return playerData.charinfo.birthdate
end
---@description Returns the player date of birth.
---@param id number
---@return string|nil
Framework.GetPlayerDobByIdentifier = function(id)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.birthdate
end
---@description Returns a table of items matching the specified name and if passed metadata from the player's inventory.
---@param src number
---@param item string
@@ -240,6 +260,7 @@ Framework.SetPlayerMetadata = function(src, metadata, value)
return true
end
---@description Gets the specified metadata key to the player's data.
---@param src number
---@param metadata string
@@ -370,6 +391,17 @@ Framework.GetPlayerPhone = function(src)
return playerData.charinfo.phone
end
---@description Returns the phone number of the player.
---@param src number
---@return string | nil
Framework.GetPlayerPhoneByIdentifier = function(src)
local player = Framework.GetPlayerByIdentifier(src) or QBCore.Functions.GetOfflinePlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.phone
end
---@description Returns the gang name of the player.
---@param src number
---@return string | nil
@@ -380,6 +412,16 @@ Framework.GetPlayerGang = function(src)
return playerData.gang.name
end
---@description Returns the gang name of the player.
---@param id number
---@return string | nil
Framework.GetPlayerGangByIdentifier = function(id)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return end
local playerData = player.PlayerData
return playerData.gang.name
end
---@description This will get a table of player sources that have the specified job name.
---@param job string
---@return table
@@ -400,6 +442,8 @@ Framework.GetPlayerJob = function(src)
return jobData.jobName, jobData.jobLabel, jobData.gradeName, jobData.gradeLevel
end
---@description This will return the players job name, job label, job grade label job grade level, boss status,
---and duty status in a table
---@param src number
@@ -467,6 +511,24 @@ Framework.AddAccountBalance = function(src, _type, amount)
return player.Functions.AddMoney(_type, amount)
end
---@description This will add money based on the type of account (money/bank)
---@param src number
---@param _type string
---@param amount number
---@return boolean | nil
Framework.AddAccountBalanceByIdentifier = function(id, _type, amount)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return false end
if _type == 'money' then _type = 'cash' end
if amount <= 0 then return false end
local paid = player.Functions.AddMoney(_type, amount)
if paid and not player.PlayerData.source then
player.Functions.Save()
end
return paid
end
---@description This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
@@ -479,6 +541,22 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
return player.Functions.RemoveMoney(_type, amount)
end
---@description This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
---@param amount number
---@return boolean | nil
Framework.RemoveAccountBalanceByIdentifier = function(id, _type, amount)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return false end
if _type == 'money' then _type = 'cash' end
local paid = player.Functions.RemoveMoney(_type, amount)
if paid and not player.PlayerData.source then
player.Functions.Save()
end
return paid
end
---@description This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
@@ -491,6 +569,14 @@ Framework.GetAccountBalance = function(src, _type)
return playerData.money[_type]
end
Framework.GetAccountBalanceByIdentifier = function(id, _type)
local player = Framework.GetPlayerByIdentifier(id) or QBCore.Functions.GetOfflinePlayer(id)
if not player then return 0 end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end
return playerData.money[_type]
end
---@description This will add an item, and return true or false based on success
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
+90
View File
@@ -35,6 +35,17 @@ Framework.GetPlayerDob = function(src)
return playerData.charinfo.birthdate
end
---@description Returns the player date of birth.
---@param id string
---@return string|nil
Framework.GetPlayerDobByIdentifier = function(id)
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.birthdate
end
---@description Returns the player data of the specified source.
---@param src any
---@return table | nil
@@ -102,6 +113,17 @@ Framework.GetPlayerName = function(src)
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
---@description Returns the first and last name of the player.
---@param src number
---@return string | nil
---@return string | nil
Framework.GetPlayerNameByIdentifier = function(src)
local player = Framework.GetPlayerByIdentifier(src) or QBox:GetOfflinePlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname
end
---@description Adds the specified item to the player's inventory.
---This is an internal function and should not be used outside of bridge, use the Inventory module instead when dealing with items.
---@param src number
@@ -350,6 +372,17 @@ Framework.GetPlayerPhone = function(src)
return playerData.charinfo.phone
end
---@description Returns the phone number of the player.
---@param src number
---@return string | nil
Framework.GetPlayerPhoneByIdentifier = function(src)
local player = Framework.GetPlayerByIdentifier(src) or QBox:GetOfflinePlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.phone
end
---@description Returns the gang name of the player.
---@param src number
---@return string | nil
@@ -358,6 +391,17 @@ Framework.GetPlayerGang = function(src)
return player.gang.name
end
---@description Returns the gang name of the player.
---@param id number
---@return string | nil
Framework.GetPlayerGangByIdentifier = function(id)
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
if not player then return end
local playerData = player.PlayerData
return playerData.gang.name
end
---@description This will get a table of player sources that have the specified job name.
---@param job string
---@return table
@@ -445,6 +489,24 @@ Framework.AddAccountBalance = function(src, _type, amount)
return player.Functions.AddMoney(_type, amount)
end
---@description Adds the specified amount to the player's account balance of the specified type.
---@param id string
---@param _type string
---@param amount number
---@return boolean | nil
Framework.AddAccountBalanceByIdentifier = function(id, _type, amount)
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
if not player then return end
if _type == 'money' then _type = 'cash' end
if amount <= 0 then return false end
local paid = player.Functions.AddMoney(_type, amount)
if paid and not player.PlayerData.source then
QBox:SaveOffline(player.PlayerData)
end
return paid
end
---@description Removes the specified amount from the player's account balance of the specified type.
---@param src number
---@param _type string
@@ -458,6 +520,22 @@ Framework.RemoveAccountBalance = function(src, _type, amount)
return player.Functions.RemoveMoney(_type, amount)
end
---@description This will remove money based on the type of account (money/bank)
---@param src number
---@param _type string
---@param amount number
---@return boolean | nil
Framework.RemoveAccountBalanceByIdentifier = function(id, _type, amount)
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
if not player then return false end
if _type == 'money' then _type = 'cash' end
local paid = player.Functions.RemoveMoney(_type, amount)
if paid and not player.PlayerData.source then
QBox:SaveOffline(player.PlayerData)
end
return paid
end
---@description Returns the player's account balance of the specified type.
---@param src number
---@param _type string
@@ -472,6 +550,18 @@ Framework.GetAccountBalance = function(src, _type)
return balance
end
---@description Returns the player's account balance of the specified type.
---@param id string
---@param _type string
---@return number | nil
Framework.GetAccountBalanceByIdentifier = function(id, _type)
local player = Framework.GetPlayerByIdentifier(id) or QBox:GetOfflinePlayer(id)
if not player then return 0 end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end
return playerData.money[_type]
end
---@description Returns a table of owned vehicles for the player. format is {vehicle = vehicle, plate = plate}
---@param src number
---@return table
+1 -1
View File
@@ -6,7 +6,7 @@ Menu = {}
---@param useQb boolean Whether to use QB menu syntax.
---@return id string The menu ID.
function Menu.Open(data, useQb)
local id = data.id or Ids.CreateUniqueId(Menus, nil, nil)
local id = data.id or lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
Menus[id] = OpenMenu(id, data, useQb)
data.id = id
return id
+1 -1
View File
@@ -20,7 +20,7 @@ end
---@param message string
---@return boolean
Phone.SendEmail = function(email, title, message)
local success = Callback.Trigger('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message)
local success = lib.callback.await('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message)
return success
end
+1 -1
View File
@@ -58,7 +58,7 @@ Phone.SendEmail = function(src, email, title, message)
return success
end
Callback.Register('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message)
lib.callback.register('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message)
return Phone.SendEmail(src, email, title, message)
end)
+2 -2
View File
@@ -21,7 +21,7 @@ end)
Shops.FinalizeCheckOut = function(shopName, item, itemLabel, price, amount)
if not shopName and not item and not itemLabel and not price then return end
local mathStuff = (tonumber(price) * tonumber(amount))
local generatedID = Ids.CreateUniqueId()
local generatedID = lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
local buildMenu = {
{
title = locale('Shops.PayByCash', tostring(mathStuff)),
@@ -72,7 +72,7 @@ end
---@return nil
Shops.OpenShop = function(shopName, shopData)
if not shopName and not shopData then return print("^6 No Shop Name or Shop Data Passed ^0") end
local generatedID = Ids.CreateUniqueId()
local generatedID = lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
local buildMenu = {}
for _, v in pairs(shopData) do
local getItemName = Inventory.GetItemInfo(v.name).label
+5 -3
View File
@@ -1,4 +1,6 @@
---@diagnostic disable: duplicate-set-field
---
---TODO: fix points
Target = Target or {}
Ids = Ids or Require("lib/utility/shared/ids.lua")
@@ -18,7 +20,7 @@ end
function Target.CreateCanInteract(cb)
if not cb then return end
local id = Ids.CreateUniqueId(InteractIds)
local id = lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
InteractIds[id] = {
id = id,
ableToInteract = -1,
@@ -80,7 +82,7 @@ function Target.AddLocalEntity(entities, _options)
entities = { entities }
end
for _, entity in pairs(entities) do
local id = Ids.RandomString()
local id = lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
local title = Language.Locale("target.title")
local menuData = { id = id, title = title, options = {} }
for k, v in pairs(fixedOptions) do
@@ -128,7 +130,7 @@ end
function Target.AddBoxZone(name, coords, size, heading, options)
local fixedOptions = Target.FixOptions(options)
local id = Ids.RandomString()
local id = lib.string.random('Aa1A', 8) -- Generate a random ID if not provided
local title = Bridge.Language.Locale("target.title")
local menuData = { id = id, title = title, options = {} }
for k, v in pairs(fixedOptions) do
-161
View File
@@ -1,161 +0,0 @@
--- ox_lib compatibility wrapper for zone creation and management.
--- Provides a small API around lib.zones (box, sphere, poly) to create/destroy
--- and lookup zones with automatic id generation and resource ownership.
---
--- Example:
--- local id = cZones.Create("box", { coords = vec3(0,0,0), size = vec3(2,2,2), onEnter = function(z) ... end })
--- cZones.Destroy(id)
---
---@module cZones
---@class ZoneData
---@field id string Unique id for the zone (generated)
---@field invoking string Resource that created the zone
---@field coords vector3? Center coordinates (box/sphere)
---@field points vector2[]? Array of points for poly zones
---@field radius number? Radius for sphere zones
---@field size table? Size table or vec3 for box zones
---@field zone any Internal zone handle returned by lib.zones
---@field debug boolean? Debug flag passed to lib.zones
---@field onEnter fun(data:ZoneData)? Callback invoked on enter (receives ZoneData)
---@field onExit fun(data:ZoneData)? Callback invoked on exit (receives ZoneData)
---@alias ZoneType "box"|"sphere"|"poly"
---@diagnostic disable: duplicate-set-field
local resourceName = "ox_lib"
if GetResourceState(resourceName) == 'missing' then return end
if not lib then Require('init.lua', 'ox_lib') end
Ids = Ids or Require('lib/utility/shared/ids.lua')
cZones = {} --conflict with ox
cZones.All = {}
--- Create a zone of the specified type.
--- Supported types: "box", "sphere", "poly"
---@param type ZoneType
---@param data ZoneData
---@return string|nil id Returns the generated zone id on success, or nil on failure
function cZones.Create(type, data)
assert(type, "Requires zone type ('box', 'sphere', or 'poly')")
assert(data, "Requires data table")
data.id = Ids.CreateUniqueId(cZones.All)
data.invoking = GetInvokingResource() or "unknown"
local onEnter = data.onEnter or data.OnEnter
local onExit = data.onExit or data.OnExit
local zone = nil
if type == "box" then
assert(data.coords, "Requires .coords as vector3 in data")
local width = data.size?.x or data.length or 1.0
local height = data.size?.y or data.width or 1.0
local z = data.size?.z or data.height or 1.0
zone = lib.zones.box({
coords = data.coords,
size = vec3(width, height, z),
rotation = data.heading or data.rotation or 0.0,
debug = data.debug or false,
onEnter = function(point)
if onEnter then
onEnter(data)
end
end,
onExit = function(point)
if onExit then
onExit(data)
end
end,
})
data.zone = zone
print("Created Zone: " .. data.id, json.encode(cZones.All))
cZones.All[data.id] = data
return data.id
elseif type == "sphere" then
assert(data.coords, "Requires .coords as vector3 in data")
data.radius = data.radius or data.size?.x or 1
lib.zones.sphere(data)
local zone = lib.zones.sphere({
coords = data.coords,
radius = data.radius,
debug = data.debug or false,
onEnter = function(point)
data.zone = data.zone or point
if onEnter then
onEnter(data)
end
end,
onExit = function(point)
data.zone = data.zone or point
if onExit then
onExit(data)
end
end,
})
data.zone = zone
cZones.All[data.id] = data
return data.id
elseif type == "poly" then
assert(data.points, "Requires an array of vector2 in .points")
assert(#data.points > 2, "Requires at least three points in .points")
local zSize = data.minZ or data.size?.z or data.height or data.thickness or 2
local polyZone = lib.zones.poly({
points = data.points,
thickness = zSize,
debug = data.debug or false,
onEnter = function(point)
data.zone = data.zone or point
if onEnter then
onEnter(data)
end
end,
onExit = function(point)
data.zone = data.zone or point
if onExit then
onExit(data)
end
end,
})
data.zone = polyZone
cZones.All[data.id] = data
return data.id
end
return nil
end
--- Destroy a zone by id.
---@param id string
---@return boolean success True if destroyed, false otherwise
function cZones.Destroy(id)
if not id then return false end
local zone = cZones.All[id].zone
if not zone then return false end
zone:remove()
cZones.All[id] = nil
return true
end
--- Destroy all zones created by a specific resource.
---@param resource string Name of the invoking resource
---@return boolean success True if operation completed (no guarantee zones existed)
function cZones.DestroyByResource(resource)
if not resource then return false end
for id, zone in pairs(cZones.All or {}) do
if zone.invoking == resource then
zone.zone:remove()
end
end
return true
end
--- Retrieve zone data by id.
---@param id string
---@return ZoneData|nil
function cZones.Get(id)
if not id then return nil end
return cZones.All[id]
end
--- Event handler: clean up zones when a resource stops.
--- This is registered to the "onResourceStop" event and delegates to DestroyByResource.
RegisterNetEvent("onResourceStop", function(resource)
cZones.DestroyByResource(resource)
end)
-116
View File
@@ -1,116 +0,0 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "PolyZone"
if GetResourceState(resourceName) == 'missing' or GetResourceState('ox_lib') ~= 'missing' then return end
Require("client.lua", resourceName)
Require("BoxZone.lua", resourceName)
Require("EntityZone.lua", resourceName)
Require("CircleZone.lua", resourceName)
Require("ComboZone.lua", resourceName)
Ids = Ids or Require('lib/utility/shared/ids.lua')
cZones = {
All = {}
}
--- Create a zone of the specified type.
--- Supported types: "box", "sphere", "poly"
---@param type ZoneType
---@param data ZoneData
---@return string|nil id Returns the generated zone id on success, or nil on failure
function cZones.Create(type, data)
assert(type, "Requires zone type ('box', 'sphere', or 'poly')")
assert(data, "Requires data table")
data.id = Ids.CreateUniqueId(cZones.All)
data.invoking = GetInvokingResource() or "unknown"
local zone = nil
if type == "box" then
assert(data.coords, "Requires .coords as vector3 in data")
local width = data.size.x or data.length or 1.0
local height = data.size.y or data.width or 1.0
local z = data.size?.z or data.height or 1.0
data.size = vec3(width, height, z)
data.heading = data.heading or data.rotation
data.rotation = data.heading
zone = BoxZone:Create(data.coords, width, height, {
name = data.id,
debugPoly = data.debug,
minZ = data.coords.z - 0.5,
maxZ = data.coords.z + z - 0.5,
heading = data.heading or data.rotation
})
elseif type == "sphere" then
assert(data.coords, "Requires .coords as vector3 in data")
data.radius = data.radius or data.size?.x or 1
zone = CircleZone:Create(data.coords, data.radius, {
name = data.id,
debugPoly = data.debug,
})
elseif type == "poly" then
assert(data.points, "Requires an array of vector2 in .points")
assert(#data.points > 2, "Requires at least three points in .points")
local zSize = data.minZ or data.size?.z or data.height or data.thickness or 2
local firstPoint = data.points[1]
local firstZ = firstPoint.z
zone = PolyZone:Create(data.points, {
name = data.id,
debugPoly = data.debug,
minZ = firstZ - 0.5,
maxZ = firstZ and (firstZ + zSize - 0.5) or nil,
})
end
if not zone then return end
data.zone = zone
zone:onPlayerInOut(function(isInside, _)
if isInside then
if data.onEnter or data.OnEnter then
(data.onEnter or data.OnEnter)(data)
end
else
if data.onExit or data.OnExit then
(data.onExit or data.OnExit)(data)
end
end
end)
cZones.All[data.id] = data
return data.id
end
--- Destroy a zone by id.
---@param id string
---@return boolean success True if destroyed, false otherwise
function cZones.Destroy(id)
if not id then return false end
local zone = cZones.All[id].zone
if not zone then return false end
zone:destroy()
cZones.All[id] = nil
return true
end
--- Destroy all zones created by a specific resource.
---@param resource string Name of the invoking resource
---@return boolean success True if operation completed (no guarantee zones existed)
function cZones.DestroyByResource(resource)
if not resource then return false end
for id, zone in pairs(cZones.All) do
if zone.invoking == resource then
zone.zone:destroy()
end
end
return true
end
--- Retrieve zone data by id.
---@param id string
---@return ZoneData|nil
function cZones.Get(id)
if not id then return nil end
return cZones.All[id]
end
--- Event handler: clean up zones when a resource stops.
---@param resource string
RegisterNetEvent("onResourceStop", function(resource)
cZones.DestroyByResource(resource)
end)