Merge pull request #140 from TheOrderFivem/dev

feat: major system refactor, feature patches, and compatibility improvements
This commit is contained in:
MrNewb authored and GitHub committed 2025-08-19 07:30:39 -04:00
commit 957e2e2ff6
81 files changed
+1451 -908

No files matched your search

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2 -2
View File
@@ -5,7 +5,7 @@ use_experimental_fxv2_oal 'yes'
author 'The Order of the Sacred Framework'
name 'community_bridge'
description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.'
version '0.11.1'
version '0.11.2'
shared_scripts {
'@ox_lib/init.lua',
@@ -25,7 +25,7 @@ server_scripts {
'modules/inventory/**/server.lua',
'modules/doorlock/**/server.lua',
'modules/phone/**/server.lua',
'modules/managment/**/server.lua',
'modules/banking/**/server.lua',
'modules/dispatch/**/server.lua',
'modules/clothing/**/server.lua',
'modules/shops/**/server.lua',
+1
View File
@@ -90,6 +90,7 @@ end)
-- ▄█▀ █▄▄ █▀▄ ▀▄▀ █▄▄ █▀▄
if not IsDuplicityVersion() then goto client end
Bridge.RegisterModule('Version', Version)
Bridge.RegisterModule('Banking', Banking)
-- ▄▀▀ █ █ ██▀ █▄ █ ▀█▀
-- ▀▄▄ █▄▄ █ █▄▄ █ ▀█ █
+6 -26
View File
@@ -3,33 +3,22 @@ local PlayerPedId = PlayerPedId
local GetVehiclePedIsIn = GetVehiclePedIsIn
local GetVehicleMaxNumberOfPassengers = GetVehicleMaxNumberOfPassengers
local GetPedInVehicleSeat = GetPedInVehicleSeat
local GetPlayerServerId = GetPlayerServerId
local GetSelectedPedWeapon = GetSelectedPedWeapon
local PlayerId = PlayerId
-- Comparison functions for client-side state
--- Get the player's ped ID
---@return integer
function GetPed()
return PlayerPedId()
end
--- Get the vehicle the player is in, if any
---@return integer | nil
function GetVehicle()
local ped = Cache.Get("Ped") -- Use cached ped for efficiency
if not ped then return end -- Or handle error/default case
local ped = PlayerPedId()
if not ped then return end
return GetVehiclePedIsIn(ped, false)
end
--- Get the seat of the player in the vehicle if the vehicle is occupied
---@return integer | nil
function GetVehicleSeat()
local vehicle = Cache.Get("Vehicle")
local vehicle = GetVehicle()
if not vehicle then return end
local ped = Cache.Get("Ped")
local ped = PlayerPedId()
if not ped then return end
for i = -1, GetVehicleMaxNumberOfPassengers(vehicle) - 1 do
if ped == GetPedInVehicleSeat(vehicle, i) then
@@ -38,26 +27,17 @@ function GetVehicleSeat()
end
end
---Get The Server ID of the player
---@return integer | nil
function GetServerId()
local ped <const> = PlayerId()
if not ped then return end -- Return unarmed hash if no ped
return GetPlayerServerId(ped)
end
--- Get the current weapon of the player
--- @return integer | nil
function GetWeapon()
local ped = Cache.Get("Ped")
local ped = PlayerPedId()
if not ped then return end -- Return unarmed hash if no ped
return GetSelectedPedWeapon(ped)
end
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
Cache.Create("Ped", PlayerPedId, 1000) -- Check ped every second (adjust as needed)
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in vehicle every 500ms
Cache.Create("Weapon", GetWeapon , 250) -- Check weapon every 250ms
Cache.Create("ServerId", GetServerId, 1000) -- Check server ID every second
return Cache
+2 -5
View File
@@ -128,11 +128,8 @@ local function trackResource(resourceName, type, data)
for _, cb in ipairs(resourceTracker.callbacks[resourceName] or {}) do
local targetCache = Cache.Caches[cb.cacheName]
if targetCache then
table.remove(targetCache.OnChange, cb.index)
debugPrint(("Removed OnChange callback from cache '%s' - resource '%s' stopped"):format(
cb.cacheName,
resourceName
))
targetCache.OnChange[cb.index] = nil
debugPrint(("Removed callback '%s' from cache '%s' - resource '%s' stopped"):format(cb.index, cb.cacheName, resourceName))
end
end
+43 -12
View File
@@ -9,18 +9,15 @@ ClientEntity = {} -- Renamed from BaseEntity
local function SpawnEntity(entityData)
entityData = entityData and entityData.args
if entityData.spawned and DoesEntityExist(entityData.spawned) then return end -- Already spawned
-- for k, v in pairs(entityData.args) do
-- print(string.format("SpawnEntity %s: %s", k, v))
-- end
local model = entityData.model and type(entityData.model) == 'string' and GetHashKey(entityData.model) or entityData.model
if model and not Utility.LoadModel(model) then
local loaded, model = Utility.LoadModel(entityData.model)
if not loaded then
print(string.format("[ClientEntity] Failed to load model %s for entity %s", entityData.model, entityData.id))
return
end
local entity = nil
local coords = entityData.coords
local rotation = entityData.rotation or vector3(0.0, 0.0, 0.0) -- Default rotation if not provided
local rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0) -- Default rotation if not provided
if entityData.entityType == 'object' then
entity = CreateObject(model, coords.x, coords.y, coords.z, false, false, false)
@@ -41,23 +38,26 @@ local function SpawnEntity(entityData)
SetModelAsNoLongerNeeded(model)
end
if entityData.OnSpawn then
entityData.OnSpawn(entityData)
pcall(function (...)
return entityData.OnSpawn(entityData)
end)
end
end
local function RemoveEntity(entityData)
entityData = entityData and entityData.args or entityData
if not entityData then return end
ClientEntityActions.StopAction(entityData.id)
if entityData.OnRemove then
pcall(function (...)
return entityData.OnRemove(entityData)
end)
end
if entityData.spawned and DoesEntityExist(entityData.spawned) then
local entityHandle = entityData.spawned
entityData.spawned = nil
SetEntityAsMissionEntity(entityHandle, false, false)
SetEntityAsMissionEntity(entityHandle, true, true)
DeleteEntity(entityHandle)
end
if entityData.OnRemove then
entityData.OnRemove(entityData)
end
end
--- Registers an entity received from the server and sets up proximity spawning.
@@ -177,6 +177,37 @@ function ClientEntity.OnCreate(_type, func)
table.insert(ClientEntity.OnCreates[_type], func)
end
function ClientEntity.SetOnSpawn(id, func)
local entityData = Entities[id]
if not entityData then
print(string.format("[ClientEntity] SetOnSpawn: Entity %s does not exist", id))
return
end
entityData.OnSpawn = func
end
function ClientEntity.SetOnRemove(id, func)
local entityData = Entities[id]
if not entityData then
print(string.format("[ClientEntity] SetOnRemove: Entity %s does not exist", id))
return
end
entityData.OnRemove = func
end
function ClientEntity.UpdateCoords(id, coords)
local entityData = Entities[id]
if not entityData then
print(string.format("[ClientEntity] UpdateCoords: Entity %s does not exist", id))
return
end
entityData.coords = coords
Point.UpdateCoords(id, coords)
if entityData.spawned and DoesEntityExist(entityData.spawned) then
SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, true)
end
end
-- Network Event Handlers
RegisterNetEvent("community_bridge:client:CreateEntity", function(entityData)
ClientEntity.Create(entityData)
+3 -3
View File
@@ -29,7 +29,7 @@ end
function ServerEntity.Create(id, entityType, model, coords, rotation, meta)
local self = ServerEntity.New(id, entityType, model, coords, rotation, meta)
if not self then
print("Failed to create entity with ID: " .. tostring(id))
-- print("Failed to create entity with ID: " .. tostring(id))
return nil
end
TriggerClientEvent("community_bridge:client:CreateEntity", -1, self)
@@ -68,7 +68,7 @@ end
-- @param data table The data fields to update.
function ServerEntity.Update(id, data)
local entity = Entities[id]
print("Updating entity: ", id, entity)
-- print("Updating entity: ", id, entity)
if not entity then return false end
for key, value in pairs(data) do
@@ -84,7 +84,7 @@ end
-- @param actionName string The name of the action to trigger (must match a function in ClientEntityActions).
-- @param ... any Additional arguments for the action function.
function ServerEntity.TriggerAction(entityId, actionName, endPosition, ...)
print("Triggering action: ", entityId, actionName, ...)
-- print("Triggering action: ", entityId, actionName, ...)
local entity = Entities[entityId]
if not entity then
print(string.format("[ServerEntity] Attempted to trigger action '%s' on non-existent entity %s", actionName, entityId))
+2 -1
View File
@@ -47,6 +47,7 @@ cLib = {
Math = Math or Require("lib/utility/shared/math.lua"),
LA = LA or Require("lib/utility/shared/la.lua"),
Perlin = Perlin or Require("lib/utility/shared/perlin.lua"),
-- Zones = Poly or Require("lib/zones/shared/zones.lua"),
-- Action = Action or Require("lib/entities/shared/actions.lua"),
}
@@ -71,7 +72,7 @@ cLib.Placeable = Placeable or Require("lib/placers/client/object_placer.lua")
cLib.Utility = Utility or Require("lib/utility/client/utility.lua")
cLib.PlaceableObject = ObjectPlacer or Require("lib/placers/client/placeable_object.lua")
cLib.Raycast = Raycast or Require("lib/raycast/client/raycast.lua")
cLib.Point = Point or Require("lib/points/client/points.lua")
cLib.Point = Point or Require("lib/points/client/pointsv2.lua")
cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
cLib.Cache = Cache or Require("lib/cache/client/cache.lua")
cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua")
+56
View File
@@ -55,5 +55,61 @@ Logs.Send = function(src, message)
end
end
local embeds = {}
Logs.Notify = function(src, url, image, message)
if not src or not message then return end
local logType = LogSystem or "built-in"
if logType == "built-in" then
embeds[url] = embeds[url] or {}
local embed = embeds[url].embed or {}
local firstName, lastName = Framework.GetPlayerName(src)
table.insert(embed, {
color = "15769093",
title = GetInvokingResource(),
-- url = 'https://discord.gg/Gm6rYEXUsn',
thumbnail = { url = LogoForEmbed },
fields = {
{
name = '**Player ID**',
value = src,
inline = true,
},
{
name = '**Player Identifier**',
value = Framework.GetPlayerIdentifier(src),
inline = true,
},
{
name = 'Log Message',
value = "```"..message.."```",
inline = false,
},
},
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
footer = {
text = "Community_Bridge | ",
icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
},
})
embeds[url].embed = embed
if embeds[url].inProgress then return end
embeds[url].inProgress = true
SetTimeout(5000, function()
PerformHttpRequest(url, function(err, text, headers) end, 'POST', json.encode({
username = string.format("%s %s", firstName, lastName),
avatar_url = image or 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
embeds = embeds[url].embed
}), { ['Content-Type']= 'application/json' })
embeds[url].inProgress = false
end)
elseif logType == "qb" then
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
elseif logType == "ox_lib" then
return lib.logger(src, GetCurrentResourceName(), message)
end
end
exports('Logs', Logs)
return Logs
+1 -1
View File
@@ -8,7 +8,7 @@ function Particle.New(data)
assert(data.dict, "Invalid particle data. Must contain string dict.")
assert(data.ptfx, "Invalid particle data. Must contain string ptfx.")
local _id = data.id or id.CreateUniqueId(Particles)
local _id = data.id or Bridge.Ids.CreateUniqueId(Particles)
data = {
id = _id,
dict = data.dict,
+2 -1
View File
@@ -36,6 +36,7 @@ Placeable.PlaceObject = function(object, distance, snapToGround, allowedMats, of
local propObject = type(object) == 'string' and joaat(object) or object
local heading = 0.0
local checkDist = distance or 10.0
local ped = PlayerPedId()
Utility.LoadModel(propObject)
@@ -60,7 +61,7 @@ Placeable.PlaceObject = function(object, distance, snapToGround, allowedMats, of
end
SetEntityCoords(activePlacementProp, coords.x, coords.y, coords.z, false, false, false, false)
local distCheck = #(GetEntityCoords(cache.ped) - coords)
local distCheck = #(GetEntityCoords(ped) - coords)
SetEntityHeading(activePlacementProp, heading)
if snapToGround then
+44 -39
View File
@@ -12,7 +12,7 @@ RegisterKeyMapping('+rotate_left', locale('placeable_object.rotate_left'), 'keyb
RegisterKeyMapping('+rotate_right', locale('placeable_object.rotate_right'), 'keyboard', 'RIGHT')
RegisterKeyMapping('+scroll_up', locale('placeable_object.object_scroll_up'), 'mouse_wheel', 'IOM_WHEEL_UP')
RegisterKeyMapping('+scroll_down', locale('placeable_object.object_scroll_down'), 'mouse_wheel', 'IOM_WHEEL_DOWN')
RegisterKeyMapping('+depth_modifier', locale('placeable_object.depth_modifier'), 'keyboard', 'LCONTROL')
RegisterKeyMapping('+depth_modifier', locale('placeable_object.depth_modifier'), 'keyboard', 'LCONTROL')
local state = {
isPlacing = false,
@@ -44,6 +44,15 @@ local state = {
}
}
local placementText = {
string.format(locale('placeable_object.object_place'), Utility.GetCommandKey('+place_object')),
string.format(locale('placeable_object.object_cancel'), Utility.GetCommandKey('+cancel_placement')),
string.format(locale('placeable_object.rotate_clockwise'), Utility.GetCommandKey('+scroll_up')),
string.format(locale('placeable_object.rotate_counter_clockwise'), Utility.GetCommandKey('+scroll_down')),
string.format(locale('placeable_object.depth_modifier'), Utility.GetCommandKey('+depth_modifier'))
}
-- Command handlers for key mappings
RegisterCommand('+place_object', function()
if state.isPlacing then
@@ -554,15 +563,14 @@ local function placementLoop()
state.keys.placeObject = false -- Reset the key state
local canPlace = checkMaterialAndBoundary()
if canPlace then
Wait(100)
local coords = GetEntityCoords(state.currentEntity)
if not state.settings.allowVertical or state.snapToGround then
local groundZ, _z = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z + 50, false)
if groundZ then
coords = vector3(coords.x, coords.y, _z)
end
end
-- if not state.settings.allowVertical or state.snapToGround then
-- local groundZ, _z = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z + 50, false)
-- if groundZ then
-- end
-- end
coords = vector3(coords.x, coords.y, coords.z - 0.2) -- Adjust Z to ground level
local rotation = GetEntityRotation(state.currentEntity)
if state.promise then
state.promise:resolve({
@@ -616,15 +624,15 @@ local function placementLoop()
end
-- Show help text for placement controls
local placementText = {
string.format(locale('placeable_object.place_object_place'), Bridge.Utility.GetCommandKey('+place_object')),
string.format(locale('placeable_object.place_object_cancel'), Bridge.Utility.GetCommandKey('+cancel_placement')),
-- string.format(locale('placeable_object.rotate_left'), Bridge.Utility.GetCommandKey('+rotate_left')),
-- string.format(locale('placeable_object.rotate_right'), Bridge.Utility.GetCommandKey('+rotate_right')),
string.format(locale('placeable_object.place_object_scroll_up'), Bridge.Utility.GetCommandKey('+scroll_up')),
string.format(locale('placeable_object.place_object_scroll_down'), Bridge.Utility.GetCommandKey('+scroll_down')),
string.format(locale('placeable_object.depth_modifier'), Bridge.Utility.GetCommandKey('+depth_modifier'))
}
-- local placementText = {
-- string.format(locale('placeable_object.place_object_place'), Bridge.Utility.GetCommandKey('+place_object')),
-- string.format(locale('placeable_object.place_object_cancel'), Bridge.Utility.GetCommandKey('+cancel_placement')),
-- -- string.format(locale('placeable_object.rotate_left'), Bridge.Utility.GetCommandKey('+rotate_left')),
-- -- string.format(locale('placeable_object.rotate_right'), Bridge.Utility.GetCommandKey('+rotate_right')),
-- string.format(locale('placeable_object.place_object_scroll_up'), Bridge.Utility.GetCommandKey('+scroll_up')),
-- string.format(locale('placeable_object.place_object_scroll_down'), Bridge.Utility.GetCommandKey('+scroll_down')),
-- string.format(locale('placeable_object.depth_modifier'), Bridge.Utility.GetCommandKey('+depth_modifier'))
-- }
Bridge.Notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText))
-- -- Draw entity bounding box
@@ -644,18 +652,24 @@ end
---@param model - Model name or hash
---@param settings - Configuration table:
--[[
depth (3.0): Starting distance from player,
allowVertical (false): Enable height controls,
allowMovement (false): Enable WASD mode,
disableSphere (false): Hide position indicator,
boundary: Area restriction {min = vector3(), max = vector3()},
allowedMats: Surface materials {"concrete", "grass"},
depthStep (0.1): Step size for depth adjustment,
rotationStep (0.5): Step size for rotation,
heightStep (0.5): Step size for height adjustment,
movementStep (0.1): Step size for normal movement,
movementStepFast (0.5): Step size for fast movement (with shift),
maxDepth (50.0): Maximum distance from player,
{
depth = 3.0, -- Starting distance from player
allowVertical = false, -- Enable height controls (Q/E, Alt to toggle ground snap)
allowMovement = false, -- Enable WASD movement mode
allowNormal = false, -- Allow switching back to normal mode from movement
disableSphere = false, -- Hide position indicator sphere
drawBoundary = false, -- Draw boundary box/polygon
drawInBoundary = false, -- Draw entity outline (green/red) based on boundary/material
boundary = nil, -- Area restriction (box: {min=vector3(), max=vector3()}, polygon: {points={...}, minZ, maxZ})
allowedMats = nil, -- Allowed surface materials (e.g. {"concrete", "grass"})
customCheck = nil, -- Custom function(pos, entity, settings) -> bool
depthStep = 0.1, -- Step size for depth adjustment (scroll + modifier)
rotationStep = 0.5, -- Step size for rotation (scroll)
heightStep = 0.5, -- Step size for height adjustment (Q/E)
movementStep = 0.1, -- Step size for WASD movement
movementStepFast = 0.5, -- Step size for fast movement (WASD + Shift)
maxDepth = 5.0, -- Maximum distance from player
}
--]]
---@returns Promise with: {entity, coords, heading, placed, cancelled}
--[[
@@ -724,15 +738,6 @@ function PlaceableObject.Create(model, settings)
state.isPlacing = true
-- Show help text for placement controls
local placementText = {
string.format(locale('placeable_object.place_object_place'), Bridge.Utility.GetCommandKey('+place_object')),
string.format(locale('placeable_object.place_object_cancel'), Bridge.Utility.GetCommandKey('+cancel_placement')),
-- string.format(locale('placeable_object.rotate_left'), Bridge.Utility.GetCommandKey('+rotate_left')),
-- string.format(locale('placeable_object.rotate_right'), Bridge.Utility.GetCommandKey('+rotate_right')),
string.format(locale('placeable_object.place_object_scroll_up'), Bridge.Utility.GetCommandKey('+scroll_up')),
string.format(locale('placeable_object.place_object_scroll_down'), Bridge.Utility.GetCommandKey('+scroll_down')),
string.format(locale('placeable_object.depth_modifier'), Bridge.Utility.GetCommandKey('+depth_modifier'))
}
Bridge.Notify.ShowHelpText(type(placementText) == 'table' and table.concat(placementText))
placementLoop()
+223 -223
View File
@@ -1,255 +1,255 @@
-- Grid-based point system
Point = {}
local ActivePoints = {}
local GridCells = {}
local LoopStarted = false
local insidePoints = {}
local data = {} -- 👈 Move this outside the function
-- -- Grid-based point system
-- Point = {}
-- local ActivePoints = {}
-- local GridCells = {}
-- local LoopStarted = false
-- local insidePoints = {}
-- local data = {} -- 👈 Move this outside the function
-- Grid configuration
local GRID_SIZE = 500.0 -- Size of each grid cell
local CELL_BUFFER = 1 -- Number of adjacent cells to check
-- -- Grid configuration
-- local GRID_SIZE = 500.0 -- Size of each grid cell
-- local CELL_BUFFER = 1 -- Number of adjacent cells to check
-- Consider adding these optimizations
local ADAPTIVE_WAIT = true -- Adjust wait time based on player speed
-- -- Consider adding these optimizations
-- local ADAPTIVE_WAIT = false -- Adjust wait time based on player speed
---This is an internal function, do not call this externally
function Point.GetCellKey(coords)
local cellX = math.floor(coords.x / GRID_SIZE)
local cellY = math.floor(coords.y / GRID_SIZE)
return cellX .. ":" .. cellY
end
-- ---This is an internal function, do not call this externally
-- function Point.GetCellKey(coords)
-- local cellX = math.floor(coords.x / GRID_SIZE)
-- local cellY = math.floor(coords.y / GRID_SIZE)
-- return cellX .. ":" .. cellY
-- end
---This is an internal function, do not call this externally
function Point.RegisterInGrid(point)
local cellKey = Point.GetCellKey(point.coords)
-- ---This is an internal function, do not call this externally
-- function Point.RegisterInGrid(point)
-- local cellKey = Point.GetCellKey(point.coords)
-- Initialize cell if it doesn't exist
GridCells[cellKey] = GridCells[cellKey] or {
points = {},
count = 0
}
-- -- Initialize cell if it doesn't exist
-- GridCells[cellKey] = GridCells[cellKey] or {
-- points = {},
-- count = 0
-- }
-- Add point to cell
GridCells[cellKey].points[point.id] = point
GridCells[cellKey].count = GridCells[cellKey].count + 1
-- -- Add point to cell
-- GridCells[cellKey].points[point.id] = point
-- GridCells[cellKey].count = GridCells[cellKey].count + 1
-- Store cell reference in point
point.cellKey = cellKey
end
-- -- Store cell reference in point
-- point.cellKey = cellKey
-- end
---This is an internal function, do not call this externally
function Point.UpdateInGrid(point, oldCellKey)
-- Remove from old cell if cell key changed
if oldCellKey and oldCellKey ~= point.cellKey then
if GridCells[oldCellKey] and GridCells[oldCellKey].points[point.id] then
GridCells[oldCellKey].points[point.id] = nil
GridCells[oldCellKey].count = GridCells[oldCellKey].count - 1
-- ---This is an internal function, do not call this externally
-- function Point.UpdateInGrid(point, oldCellKey)
-- -- Remove from old cell if cell key changed
-- if oldCellKey and oldCellKey ~= point.cellKey then
-- if GridCells[oldCellKey] and GridCells[oldCellKey].points[point.id] then
-- GridCells[oldCellKey].points[point.id] = nil
-- GridCells[oldCellKey].count = GridCells[oldCellKey].count - 1
-- Clean up empty cells
if GridCells[oldCellKey].count <= 0 then
GridCells[oldCellKey] = nil
end
end
-- -- Clean up empty cells
-- if GridCells[oldCellKey].count <= 0 then
-- GridCells[oldCellKey] = nil
-- end
-- end
-- Add to new cell
Point.RegisterInGrid(point)
end
end
-- -- Add to new cell
-- Point.RegisterInGrid(point)
-- end
-- end
---Gets nearby cells based on the coords
---@param coords table
---@return table
function Point.GetNearbyCells(coords)
local cellX = math.floor(coords.x / GRID_SIZE)
local cellY = math.floor(coords.y / GRID_SIZE)
local nearbyCells = {}
-- ---Gets nearby cells based on the coords
-- ---@param coords table
-- ---@return table
-- function Point.GetNearbyCells(coords)
-- local cellX = math.floor(coords.x / GRID_SIZE)
-- local cellY = math.floor(coords.y / GRID_SIZE)
-- local nearbyCells = {}
-- Get current and adjacent cells
for x = cellX - CELL_BUFFER, cellX + CELL_BUFFER do
for y = cellY - CELL_BUFFER, cellY + CELL_BUFFER do
local key = x .. ":" .. y
if GridCells[key] then
table.insert(nearbyCells, key)
end
end
end
-- -- Get current and adjacent cells
-- for x = cellX - CELL_BUFFER, cellX + CELL_BUFFER do
-- for y = cellY - CELL_BUFFER, cellY + CELL_BUFFER do
-- local key = x .. ":" .. y
-- if GridCells[key] then
-- table.insert(nearbyCells, key)
-- end
-- end
-- end
return nearbyCells
end
-- return nearbyCells
-- end
---Returns all points in the same cell as the given point
---This will require you to pass the point object
---@param point table
---@return table
function Point.CheckPointsInSameCell(point)
local cellKey = point.cellKey
if not GridCells[cellKey] then return {} end
-- ---Returns all points in the same cell as the given point
-- ---This will require you to pass the point object
-- ---@param point table
-- ---@return table
-- function Point.CheckPointsInSameCell(point)
-- local cellKey = point.cellKey
-- if not GridCells[cellKey] then return {} end
local nearbyPoints = {}
for id, otherPoint in pairs(GridCells[cellKey].points) do
if id ~= point.id then
local distance = #(point.coords - otherPoint.coords)
if distance < (point.distance + otherPoint.distance) then
nearbyPoints[id] = otherPoint
end
end
end
-- local nearbyPoints = {}
-- for id, otherPoint in pairs(GridCells[cellKey].points) do
-- if id ~= point.id then
-- local distance = #(point.coords - otherPoint.coords)
-- if distance < (point.distance + otherPoint.distance) then
-- nearbyPoints[id] = otherPoint
-- end
-- end
-- end
return nearbyPoints
end
-- return nearbyPoints
-- end
---Internal function that starts the loop. Do not call this function directly.
function Point.StartLoop()
if LoopStarted then return false end
LoopStarted = true
-- Remove the "local data = {}" line from here
CreateThread(function()
while LoopStarted do
local playerPed = PlayerPedId()
while playerPed == -1 do
Wait(100)
playerPed = PlayerPedId()
end
local playerCoords = GetEntityCoords(playerPed)
local targetsExist = false
local playerCellKey = Point.GetCellKey(playerCoords)
local nearbyCells = Point.GetNearbyCells(playerCoords)
-- ---Internal function that starts the loop. Do not call this function directly.
-- function Point.StartLoop()
-- if LoopStarted then return false end
-- LoopStarted = true
-- -- Remove the "local data = {}" line from here
-- CreateThread(function()
-- while LoopStarted do
-- local playerPed = PlayerPedId()
-- while playerPed == -1 do
-- Wait(100)
-- playerPed = PlayerPedId()
-- end
-- local playerCoords = GetEntityCoords(playerPed)
-- local targetsExist = false
-- local playerCellKey = Point.GetCellKey(playerCoords)
-- local nearbyCells = Point.GetNearbyCells(playerCoords)
local playerSpeed = GetEntitySpeed(playerPed)
local maxWeight = 1000
local waitTime = ADAPTIVE_WAIT and math.max(maxWeight/10, maxWeight - playerSpeed * maxWeight/10) or maxWeight
-- Process only points in nearby cells
for _, cellKey in ipairs(nearbyCells) do
if GridCells[cellKey] then
for id, point in pairs(GridCells[cellKey].points) do
targetsExist = true
-- local playerSpeed = GetEntitySpeed(playerPed)
-- local maxWeight = 1000
-- local waitTime = ADAPTIVE_WAIT and math.max(maxWeight/10, maxWeight - playerSpeed * maxWeight/10) or maxWeight
-- -- Process only points in nearby cells
-- for _, cellKey in ipairs(nearbyCells) do
-- if GridCells[cellKey] then
-- for id, point in pairs(GridCells[cellKey].points) do
-- targetsExist = true
-- Update entity position if needed
local oldCellKey = point.cellKey
if point.isEntity then
point.coords = GetEntityCoords(point.target)
point.cellKey = Point.GetCellKey(point.coords)
Point.UpdateInGrid(point, oldCellKey)
end
local coords = point.coords and vector3(point.coords.x, point.coords.y, point.coords.z) or vector3(0, 0, 0)
local distance = #(playerCoords - coords)
--local distance = #(playerCoords - point.coords)
-- -- Update entity position if needed
-- local oldCellKey = point.cellKey
-- if point.isEntity then
-- point.coords = GetEntityCoords(point.target)
-- point.cellKey = Point.GetCellKey(point.coords)
-- Point.UpdateInGrid(point, oldCellKey)
-- end
-- local coords = point.coords and vector3(point.coords.x, point.coords.y, point.coords.z) or vector3(0, 0, 0)
-- local distance = #(playerCoords - coords)
-- --local distance = #(playerCoords - point.coords)
-- Check if player entered/exited the point
if distance < point.distance then
if not point.inside then
point.inside = true
data[point.id] = data[point.id] or point.args or {}
data[point.id] = point.onEnter(point, data[point.id])
insidePoints[point.id] = point
end
-- Modified main loop exit handler
elseif point.inside then
point.inside = false
data[point.id] = data[point.id] or point.args or {}
local result = point.onExit(point, data[point.id])
data[point.id] = result ~= nil and result or data[point.id] -- ← Use consistent fallback
point.args = data[point.id] -- ← Update point.args to match data[point.id]
insidePoints[point.id] = nil
end
-- -- Check if player entered/exited the point
-- if distance < point.distance then
-- if not point.inside then
-- point.inside = true
-- data[point.id] = data[point.id] or point.args or {}
-- data[point.id] = point.onEnter(point, data[point.id])
-- insidePoints[point.id] = point
-- end
-- -- Modified main loop exit handler
-- elseif point.inside then
-- point.inside = false
-- data[point.id] = data[point.id] or point.args or {}
-- local result = point.onExit(point, data[point.id])
-- data[point.id] = result ~= nil and result or data[point.id] -- ← Use consistent fallback
-- point.args = data[point.id] -- ← Update point.args to match data[point.id]
-- insidePoints[point.id] = nil
-- end
if point.onNearby then
point.onNearby(GridCells[cellKey]?.points, waitTime)
end
end
end
end
-- -- if point.onNearby then
-- -- point.onNearby(GridCells[cellKey]?.points, waitTime)
-- -- end
-- end
-- end
-- end
for id, insidepoint in pairs(insidePoints) do
local pos = insidepoint.coords and vector3(insidepoint.coords.x, insidepoint.coords.y, insidepoint.coords.z) or vector3(0, 0, 0)
local dist = #(playerCoords - pos)
if dist > insidepoint.distance then
insidepoint.inside = false
data[insidepoint.id] = data[insidepoint.id] or insidepoint.args or {}
local result = insidepoint.onExit(insidepoint, data[insidepoint.id])
data[insidepoint.id] = result ~= nil and result or data[insidepoint.id]
insidepoint.args = data[insidepoint.id] -- ← Keep data in sync
insidePoints[insidepoint.id] = nil
end
end
Wait(waitTime) -- Faster updates when moving quickly
end
end)
return true
end
-- for id, insidepoint in pairs(insidePoints) do
-- local pos = insidepoint.coords and vector3(insidepoint.coords.x, insidepoint.coords.y, insidepoint.coords.z) or vector3(0, 0, 0)
-- local dist = #(playerCoords - pos)
-- if dist > insidepoint.distance then
-- insidepoint.inside = false
-- data[insidepoint.id] = data[insidepoint.id] or insidepoint.args or {}
-- local result = insidepoint.onExit(insidepoint, data[insidepoint.id])
-- data[insidepoint.id] = result ~= nil and result or data[insidepoint.id]
-- insidepoint.args = data[insidepoint.id] -- ← Keep data in sync
-- insidePoints[insidepoint.id] = nil
-- end
-- end
-- Wait(waitTime) -- Faster updates when moving quickly
-- end
-- end)
-- return true
-- end
---Create a point based on a vector or entityID
---@param id string
---@param target number || vector3
---@param distance number
---@param _onEnter function
---@param _onExit function
---@param _onNearby function
---@param data self
---@return table
function Point.Register(id, target, distance, args, _onEnter, _onExit, _onNearby)
local isEntity = type(target) == "number"
local coords = isEntity and GetEntityCoords(target) or target
-- ---Create a point based on a vector or entityID
-- ---@param id string
-- ---@param target number || vector3
-- ---@param distance number
-- ---@param _onEnter function
-- ---@param _onExit function
-- ---@param _onNearby function
-- ---@param data self
-- ---@return table
-- function Point.Register(id, target, distance, args, _onEnter, _onExit, _onNearby)
-- local isEntity = type(target) == "number"
-- local coords = isEntity and GetEntityCoords(target) or target
local self = {}
self.id = id
self.target = target -- Store entity ID or Vector3
self.isEntity = isEntity
self.coords = coords
self.distance = distance
self.onEnter = _onEnter or function() end
self.onExit = _onExit or function() end
self.onNearby = _onNearby or function() end
self.inside = false -- Track if player is inside
self.args = args or {}
-- local self = {}
-- self.id = id
-- self.target = target -- Store entity ID or Vector3
-- self.isEntity = isEntity
-- self.coords = coords
-- self.distance = distance
-- self.onEnter = _onEnter or function() end
-- self.onExit = _onExit or function() end
-- self.onNearby = _onNearby or function() end
-- self.inside = false -- Track if player is inside
-- self.args = args or {}
ActivePoints[id] = self
Point.RegisterInGrid(self)
Point.StartLoop()
return self
end
-- ActivePoints[id] = self
-- Point.RegisterInGrid(self)
-- Point.StartLoop()
-- return self
-- end
---Remove an exsisting point by its id
---@param id string
function Point.Remove(id)
local point = ActivePoints[id]
if point then
local cellKey = point.cellKey
if GridCells[cellKey] and GridCells[cellKey].points[id] then
GridCells[cellKey].points[id] = nil
GridCells[cellKey].count = GridCells[cellKey].count - 1
-- ---Remove an exsisting point by its id
-- ---@param id string
-- function Point.Remove(id)
-- local point = ActivePoints[id]
-- if point then
-- local cellKey = point.cellKey
-- if GridCells[cellKey] and GridCells[cellKey].points[id] then
-- GridCells[cellKey].points[id] = nil
-- GridCells[cellKey].count = GridCells[cellKey].count - 1
if GridCells[cellKey].count <= 0 then
GridCells[cellKey] = nil
end
end
-- if GridCells[cellKey].count <= 0 then
-- GridCells[cellKey] = nil
-- end
-- end
ActivePoints[id] = nil
end
end
-- ActivePoints[id] = nil
-- end
-- end
---Returnes a point by its id
---@param id string
---@return table
function Point.Get(id)
return ActivePoints[id]
end
-- ---Returnes a point by its id
-- ---@param id string
-- ---@return table
-- function Point.Get(id)
-- return ActivePoints[id]
-- end
function Point.UpdateCoords(id, coords)
local point = ActivePoints[id]
if point then
point.coords = coords
local oldCellKey = point.cellKey
point.cellKey = Point.GetCellKey(coords)
Point.UpdateInGrid(point, oldCellKey)
end
end
-- function Point.UpdateCoords(id, coords)
-- local point = ActivePoints[id]
-- if point then
-- point.coords = coords
-- local oldCellKey = point.cellKey
-- point.cellKey = Point.GetCellKey(coords)
-- Point.UpdateInGrid(point, oldCellKey)
-- end
-- end
---Returns all points
---@return table
function Point.GetAll()
return ActivePoints
end
-- ---Returns all points
-- ---@return table
-- function Point.GetAll()
-- return ActivePoints
-- end
return Point
-- return Point
+143
View File
@@ -0,0 +1,143 @@
local GRIDE_SIZE_X = 8968.83 / 2
local GRIDE_SIZE_Y = 126200.40 / 2
local CELL_SIZE = 500
local Grid = {}
Grid.Generated = false
local Grids = {}
Point = {}
Point.All = {}
function Grid.Generate()
if Grid.Generated then return end
Grid.Generated = true
local numOfCellsX = math.ceil(GRIDE_SIZE_X / CELL_SIZE)
local numOfCellsY = math.ceil(GRIDE_SIZE_Y / CELL_SIZE)
for x = -numOfCellsX, numOfCellsX do
Grids[x] = {}
for y = -numOfCellsY, numOfCellsY do
Grids[x][y] = {}
end
end
end
function Grid.GetCellId(coords)
local cellX = math.floor(coords.x / CELL_SIZE) + 1
local cellY = math.floor(coords.y / CELL_SIZE) + 1
return string.format("%d_%d", cellX, cellY)
end
function Grid.GetCellByCoords(coords)
local cellX = math.floor(coords.x / CELL_SIZE) + 1
local cellY = math.floor(coords.y / CELL_SIZE) + 1
return Grids[cellX][cellY]
end
local Points = {}
Points.Started = false
function Point.StartLoop()
if Points.Started then return end
Points.Started = true
CreateThread(function()
while Points.Started do
local playerPed = PlayerPedId()
if playerPed ~= -1 then
local coords = GetEntityCoords(playerPed)
local cell = Grid.GetCellByCoords(coords)
for _, point in pairs(cell or {}) do
if point.isEntity then
local entity = point.target
if DoesEntityExist(entity) then
local entityCoords = GetEntityCoords(entity)
local distance = #(coords - entityCoords)
if distance < point.distance then
if not point.inside then
point.inside = true
point.args = point?.onEnter(point, point.args) or point.args
end
elseif point.inside then
point.inside = false
point.args = point?.onExit(point, point.args) or point.args
end
end
else
local distance = #(vector3(coords.x, coords.y, coords.z) - vector3(point.coords.x, point.coords.y, point.coords.z))
if distance < point.distance then
if not point.inside then
point.inside = true
point.args = point?.onEnter(point, point.args) or point.args
end
elseif point.inside then
point.inside = false
point.args = point?.onExit(point, point.args) or point.args
end
end
end
end
Wait(1000)
end
end)
end
function Point.Register(id, target, distance, args, _onEnter, _onExit)
local isEntity = type(target) == "number"
local coords = isEntity and GetEntityCoords(target) or target
Grid.Generate()
local self = {}
self.id = id
self.target = target -- Store entity ID or Vector3
self.isEntity = isEntity
self.coords = coords
self.distance = distance
self.onEnter = _onEnter or function() end
self.onExit = _onExit or function() end
self.inside = false -- Track if player is inside
self.args = args or {}
local grid = Grid.GetCellByCoords(coords)
grid[id] = self
Point.All[id] = self
Point.StartLoop()
return self
end
function Point.Remove(id)
local point = Point.All[id]
if not point then return false end
-- Remove from grid
local grid = Grid.GetCellByCoords(point.coords)
if grid then
grid[point.id] = nil
end
Point.All[id] = nil
return true
end
function Point.Get(id)
return Point.All[id]
end
function Point.UpdateCoords(id, coords)
local point = Point.All[id]
if not point then return end
local newGrid = Grid.GetCellByCoords(coords)
if not newGrid or newGrid[point.id] then return end
local oldGrid = Grid.GetCellByCoords(point.coords)
if oldGrid then
oldGrid[point.id] = nil
end
point.coords = coords
newGrid[point.id] = point
return true
end
function Point.GetAll()
return Point.All
end
return Point
+83 -132
View File
@@ -1,11 +1,9 @@
---@class Utility
Utility = Utility or {}
local blipIDs = {}
local spawnedPeds = {}
Locales = Locales or Require('modules/locales/shared.lua')
-- === Local Helpers ===
Point = Point or Require('lib/points/client/pointsv2.lua')
---Get the hash of a model (string or number)
---@param model string|number
@@ -22,6 +20,7 @@ end
---@return boolean, number
local function ensureModelLoaded(model)
local hash = getModelHash(model)
if HasModelLoaded(hash) then return true, hash end
if not IsModelValid(hash) and not IsModelInCdimage(hash) then return false, hash end
RequestModel(hash)
local count = 0
@@ -32,84 +31,6 @@ local function ensureModelLoaded(model)
return HasModelLoaded(hash), hash
end
---Add a text entry if possible
---@param key string
---@param text string
local function addTextEntryOnce(key, text)
if not AddTextEntry then return end
AddTextEntry(key, text)
end
---Create a blip safely and store its reference
---@param coords vector3
---@param sprite number
---@param color number
---@param scale number
---@param label string
---@param shortRange boolean
---@param displayType number
---@return number
local function safeAddBlip(coords, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8)
SetBlipDisplay(blip, displayType or 2)
SetBlipAsShortRange(blip, shortRange)
addTextEntryOnce(label, label)
BeginTextCommandSetBlipName(label)
EndTextCommandSetBlipName(blip)
table.insert(blipIDs, blip)
return blip
end
---Create a entiyty blip safely and store its reference
---@param entity number
---@param sprite number
---@param color number
---@param scale number
---@param label string
---@param shortRange boolean
---@param displayType number
---@return number
local function safeAddEntityBlip(entity, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForEntity(entity)
SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8)
SetBlipDisplay(blip, displayType or 2)
SetBlipAsShortRange(blip, shortRange)
ShowHeadingIndicatorOnBlip(blip, true)
addTextEntryOnce(label, label)
BeginTextCommandSetBlipName(label)
EndTextCommandSetBlipName(blip)
table.insert(blipIDs, blip)
return blip
end
---Remove a blip safely from the stored list
---@param blip number
---@return boolean
local function safeRemoveBlip(blip)
for i, storedBlip in ipairs(blipIDs) do
if storedBlip == blip then
RemoveBlip(storedBlip)
table.remove(blipIDs, i)
return true
end
end
return false
end
---Add a text entry if possible (shortcut)
---@param text string
local function safeAddTextEntry(text)
if not AddTextEntry then return end
AddTextEntry(text, text)
end
-- === Public Utility Functions ===
---Create a prop with the given model and coordinates
---@param model string|number
---@param coords vector3
@@ -147,11 +68,7 @@ function Utility.CreateVehicle(model, coords, heading, networked)
SetVehicleNeedsToBeHotwired(vehicle, false)
SetVehRadioStation(vehicle, "OFF")
SetModelAsNoLongerNeeded(hash)
return vehicle, {
networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0,
coords = GetEntityCoords(vehicle),
heading = GetEntityHeading(vehicle),
}
return vehicle, {networkid = NetworkGetNetworkIdFromEntity(vehicle) or 0,coords = GetEntityCoords(vehicle),heading = GetEntityHeading(vehicle),}
end
---Create a ped with the given model and coordinates
@@ -166,7 +83,7 @@ function Utility.CreatePed(model, coords, heading, networked, settings)
if not loaded then return nil, Prints and Prints.Error and Prints.Error("Model Has Not Loaded") end
local spawnedEntity = CreatePed(0, hash, coords.x, coords.y, coords.z, heading, networked, false)
SetModelAsNoLongerNeeded(hash)
table.insert(spawnedPeds, spawnedEntity)
spawnedPeds[tostring(spawnedEntity)] = true
return spawnedEntity
end
@@ -174,7 +91,7 @@ end
---@param text string
---@return boolean
function Utility.StartBusySpinner(text)
safeAddTextEntry(text)
AddTextEntry(text, text)
BeginTextCommandBusyString(text)
AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyString(0)
@@ -201,7 +118,17 @@ end
---@param displayType number
---@return number
function Utility.CreateBlip(coords, sprite, color, scale, label, shortRange, displayType)
return safeAddBlip(coords, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8)
SetBlipDisplay(blip, displayType or 2)
SetBlipAsShortRange(blip, shortRange)
AddTextEntry(label, label)
BeginTextCommandSetBlipName(label)
EndTextCommandSetBlipName(blip)
blipIDs[tostring(blip)] = blip
return blip
end
---Create a blip on the provided entity
@@ -214,28 +141,42 @@ end
---@param displayType number
---@return number
function Utility.CreateEntityBlip(entity, sprite, color, scale, label, shortRange, displayType)
return safeAddEntityBlip(entity, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForEntity(entity)
SetBlipSprite(blip, sprite or 8)
SetBlipColour(blip, color or 3)
SetBlipScale(blip, scale or 0.8)
SetBlipDisplay(blip, displayType or 2)
SetBlipAsShortRange(blip, shortRange)
ShowHeadingIndicatorOnBlip(blip, true)
AddTextEntry(label, label)
BeginTextCommandSetBlipName(label)
EndTextCommandSetBlipName(blip)
blipIDs[tostring(blip)] = blip
return blip
end
---Remove a blip if it exists
---@param blip number
---@return boolean
function Utility.RemoveBlip(blip)
return safeRemoveBlip(blip)
if not blipIDs[tostring(blip)] then return false, print("NO BLIP BY ID") end
RemoveBlip(blipIDs[tostring(blip)])
blipIDs[tostring(blip)] = nil
return true
end
---Load a model into memory
---@param model string|number
---@return boolean
---@return boolean, number
function Utility.LoadModel(model)
local loaded = ensureModelLoaded(model)
return loaded
return ensureModelLoaded(model)
end
---Request an animation dictionary
---@param dict string
---@return boolean
function Utility.RequestAnimDict(dict)
if HasAnimDictLoaded(dict) then return true end
RequestAnimDict(dict)
local count = 0
while not HasAnimDictLoaded(dict) and count < 30000 do
@@ -249,18 +190,12 @@ end
---@param entity number
---@return boolean
function Utility.RemovePed(entity)
local success = false
if DoesEntityExist(entity) then
DeleteEntity(entity)
end
for i, storedEntity in ipairs(spawnedPeds) do
if storedEntity == entity then
table.remove(spawnedPeds, i)
success = true
break
end
end
return success
if not spawnedPeds[tostring(entity)] then return false end
spawnedPeds[tostring(entity)] = nil
if not DoesEntityExist(entity) then return false end
SetEntityAsMissionEntity(entity, true, true)
DeleteEntity(entity)
return true
end
---Show a native input menu and return the result
@@ -270,7 +205,7 @@ end
function Utility.NativeInputMenu(text, length)
local maxLength = Math and Math.Clamp and Math.Clamp(length, 1, 50) or math.min(math.max(length or 10, 1), 50)
local menuText = text or 'enter text'
safeAddTextEntry(menuText)
AddTextEntry(menuText, menuText)
DisplayOnscreenKeyboard(1, menuText, "", "", "", "", "", maxLength)
while (UpdateOnscreenKeyboard() == 0) do
DisableAllControlActions(0)
@@ -313,10 +248,12 @@ end
---Reload the player's skin and remove attached objects
---@return boolean
function Utility.ReloadSkin()
local skinData = Utility.GetEntitySkinData(cache.ped)
Utility.SetEntitySkinData(cache.ped, skinData)
for _, props in pairs(GetGamePool("CObject")) do
if IsEntityAttachedToEntity(cache.ped, props) then
local ped = PlayerPedId()
local skinData = Utility.GetEntitySkinData(ped)
Utility.SetEntitySkinData(ped, skinData)
local poolObject = GetGamePool("CObject")
for _, props in pairs(poolObject) do
if IsEntityAttachedToEntity(ped, props) then
SetEntityAsMissionEntity(props, true, true)
DeleteObject(props)
DeleteEntity(props)
@@ -329,11 +266,25 @@ end
---@param text string
---@param duration number
function Utility.HelpText(text, duration)
safeAddTextEntry(text)
AddTextEntry(text, text)
BeginTextCommandDisplayHelp(text)
EndTextCommandDisplayHelp(0, false, true, duration or 5000)
end
local doingstuff = false
---Show a floating help text in the world
---@param text string The text to show
---@param coords table The coords to show the message at
---@return nil
function Utility.FloatingHelpText(text, coords)
AddTextEntry("community_bridge_"..text, text)
SetFloatingHelpTextWorldPosition(1, coords.x, coords.y, coords.z)
SetFloatingHelpTextStyle(1, 1, 2, -1, 3, 0)
BeginTextCommandDisplayHelp("community_bridge_"..text)
EndTextCommandDisplayHelp(2, false, false, 100)
end
---Draw 3D help text in the world
---@param coords vector3
---@param text string
@@ -343,10 +294,10 @@ function Utility.Draw3DHelpText(coords, text, scale)
if onScreen then
SetTextScale(scale or 0.35, scale or 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextProportional(true)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
SetTextCentre(true)
AddTextComponentString(text)
DrawText(x, y)
local factor = (string.len(text)) / 370
@@ -357,7 +308,7 @@ end
---Show a native notification
---@param text string
function Utility.NotifyText(text)
safeAddTextEntry(text)
AddTextEntry(text, text)
SetNotificationTextEntry(text)
DrawNotification(false, true)
end
@@ -367,6 +318,7 @@ end
---@param conditionFunction function|nil
---@param afterTeleportFunction function|nil
function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction)
local ped = PlayerPedId()
if conditionFunction ~= nil then
if not conditionFunction() then
return
@@ -374,18 +326,16 @@ function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction
end
DoScreenFadeOut(2500)
Wait(2500)
SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false)
if coords.w then
SetEntityHeading(cache.ped, coords.w)
end
FreezeEntityPosition(cache.ped, true)
SetEntityCoords(ped, coords.x, coords.y, coords.z, false, false, false, false)
if coords.w then SetEntityHeading(ped, coords.w) end
FreezeEntityPosition(ped, true)
local count = 0
while not HasCollisionLoadedAroundEntity(cache.ped) and count <= 30000 do
while not HasCollisionLoadedAroundEntity(ped) and count <= 30000 do
RequestCollisionAtCoord(coords.x, coords.y, coords.z)
Wait(0)
count = count + 1
end
FreezeEntityPosition(cache.ped, false)
FreezeEntityPosition(ped, false)
DoScreenFadeIn(1000)
if afterTeleportFunction ~= nil then
afterTeleportFunction()
@@ -407,8 +357,8 @@ end
function Utility.GetClosestPlayer(coords, distanceScope, includeMe)
local players = GetActivePlayers()
local closestPlayer = 0
local selfPed = cache.ped
local selfCoords = coords or GetEntityCoords(cache.ped)
local selfPed = PlayerPedId()
local selfCoords = coords or GetEntityCoords(selfPed)
local closestDistance = distanceScope or 5
for _, player in ipairs(players) do
@@ -435,12 +385,13 @@ function Utility.GetClosestVehicle(coords, distanceScope, includePlayerVeh)
local vehicleEntity = nil
local vehicleNetID = nil
local vehicleCoords = nil
local selfCoords = coords or GetEntityCoords(cache.ped)
local ped = PlayerPedId()
local selfCoords = coords or GetEntityCoords(ped)
local closestDistance = distanceScope or 5
local includeMyVeh = includePlayerVeh or false
local gamePoolVehicles = GetGamePool("CVehicle")
local playerVehicle = IsPedInAnyVehicle(cache.ped, false) and GetVehiclePedIsIn(cache.ped, false) or 0
local playerVehicle = IsPedInAnyVehicle(ped, false) and GetVehiclePedIsIn(ped, false) or 0
for i = 1, #gamePoolVehicles do
local thisVehicle = gamePoolVehicles[i]
@@ -460,8 +411,8 @@ function Utility.GetClosestVehicle(coords, distanceScope, includePlayerVeh)
end
-- Deprecated point functions (no changes)
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby)
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit)
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit)
end
function Utility.GetPointById(pointID)
@@ -625,13 +576,13 @@ end
AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
for _, blip in pairs(blipIDs) do
if blip and DoesBlipExist(blip) then
RemoveBlip(blip)
if blip and DoesBlipExist(tonumber(blip)) then
RemoveBlip(tonumber(blip))
end
end
for _, ped in pairs(spawnedPeds) do
if ped and DoesEntityExist(ped) then
DeleteEntity(ped)
if ped and DoesEntityExist(tonumber(ped)) then
DeleteEntity(tonumber(ped))
end
end
end)
+2 -2
View File
@@ -30,8 +30,8 @@
"place_object_scroll_down": "[Scroll Down] Turn left \n",
"object_place": "[%s] Place \n",
"object_cancel": "[%s] Cancel \n",
"object_scroll_up": "[%s] Turn right \n",
"object_scroll_down": "[%s] Turn left \n",
"rotate_clockwise": "[%s] Rotate Clockwise \n",
"rotate_counter_clockwise": "[%s] Rotate Counter-Clockwise \n",
"depth_modifier": "[%s] Depth Control Modifier \n"
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"Shops": {
"NotEnoughMoney": "Nemate dovoljno novca za kupnju ovog predmeta",
"Input": "Unos količine",
"PurchaseAmount": "Količina kupnje",
"PurchasedItem": "Kupili ste ",
"CurrencySymbol": "%s kn",
"Confirm": "Potvrdi kupnju",
"AreYouSure": "Jeste li sigurni da želite kupiti %s",
"PayByCash": "Platite %s gotovinom",
"PayByCard": "Platite %s karticom",
"CardIcon": "fa-solid fa-building-columns",
"CashIcon": "fa-solid fa-money-bill-wave",
"ShopIcon": "fa-solid fa-basket-shopping",
"ShopName": "Naziv trgovine"
},
"UNITTEST": {
"UNITTESTA": "Ja sam %s %s",
"locale-unit-test": "Ovo je test string"
},
"clipboard": {
"copy": "Kopirano u međuspremnik"
},
"placeable_object": {
"no_prop_defined": "Niste definirali nijedan objekt za postavljanje",
"cant_place_here": "Ne možete postaviti ovaj objekt ovdje",
"place_object_place": "[E] Postavi \n",
"place_object_cancel": "[X] Otkažи \n",
"place_object_scroll_up": "[Scroll Up] Okreni desno \n",
"place_object_scroll_down": "[Scroll Down] Okreni lijevo \n",
"object_place": "[%s] Postavi \n",
"object_cancel": "[%s] Otkažи \n",
"object_scroll_up": "[%s] Okreni desno \n",
"object_scroll_down": "[%s] Okreni lijevo \n",
"depth_modifier": "[%s] Modifikator kontrole dubine \n"
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"Shops": {
"NotEnoughMoney": "Neturite pakankamai pinigų šiam daiktui nusipirkti",
"Input": "Kiekio įvestis",
"PurchaseAmount": "Pirkimo kiekis",
"PurchasedItem": "Jūs nusipirkote ",
"CurrencySymbol": "%s €",
"Confirm": "Patvirtinti pirkimą",
"AreYouSure": "Ar tikrai norite nusipirkti %s",
"PayByCash": "Sumokėti %s grynaisiais",
"PayByCard": "Sumokėti %s kortele",
"CardIcon": "fa-solid fa-building-columns",
"CashIcon": "fa-solid fa-money-bill-wave",
"ShopIcon": "fa-solid fa-basket-shopping",
"ShopName": "Parduotuvės pavadinimas"
},
"UNITTEST": {
"UNITTESTA": "Aš esu %s %s",
"locale-unit-test": "Tai yra testavimo eilutė"
},
"clipboard": {
"copy": "Nukopijuota į iškarpinę"
},
"placeable_object": {
"no_prop_defined": "Nenurodėte jokio objekto, kurį reikia pastatyti",
"cant_place_here": "Čia negalite pastatyti šio objekto",
"place_object_place": "[E] Pastatyti \n",
"place_object_cancel": "[X] Atšaukti \n",
"place_object_scroll_up": "[Slinkti aukštyn] Pasukti dešinėn \n",
"place_object_scroll_down": "[Slinkti žemyn] Pasukti kairėn \n",
"object_place": "[%s] Pastatyti \n",
"object_cancel": "[%s] Atšaukti \n",
"rotate_clockwise": "[%s] Sukti pagal laikrodžio rodyklę \n",
"rotate_counter_clockwise": "[%s] Sukti prieš laikrodžio rodyklę \n",
"depth_modifier": "[%s] Gylio kontrolės modifikatorius \n"
}
}
@@ -1,16 +1,16 @@
---@diagnostic disable: duplicate-set-field
Managment = Managment or {}
Banking = Banking or {}
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'default'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return 0, print("The resource you are using does not support this function.")
end
@@ -19,7 +19,7 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.AddAccountMoney = function(account, amount, reason)
Banking.AddAccountMoney = function(account, amount, reason)
return false, print("The resource you are using does not support this function.")
end
@@ -28,8 +28,8 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, reason)
Banking.RemoveAccountMoney = function(account, amount, reason)
return false, print("The resource you are using does not support this function.")
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('fd_banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local fd_banking = exports['fd_banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'fd_banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return fd_banking:GetAccount(account)
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.AddAccountMoney = function(account, amount, reason)
Banking.AddAccountMoney = function(account, amount, reason)
return fd_banking:AddMoney(account, amount, reason)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, reason)
Banking.RemoveAccountMoney = function(account, amount, reason)
return fd_banking:RemoveMoney(account, amount, reason)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('kartik-banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local kartik = exports['kartik-banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'kartik-banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
local balance = kartik:GetAccountMoney(account)
return balance or 0
end
@@ -23,7 +23,7 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.AddAccountMoney = function(account, amount, reason)
Banking.AddAccountMoney = function(account, amount, reason)
return kartik:AddAccountMoney(account, amount, reason)
end
@@ -32,8 +32,8 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, reason)
Banking.RemoveAccountMoney = function(account, amount, reason)
return kartik:RemoveAccountMoney(account, amount, reason)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('okokBanking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local okokBanking = exports['okokBanking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'okokBanking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return okokBanking:GetAccount(account)
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.AddAccountMoney = function(account, amount, _)
Banking.AddAccountMoney = function(account, amount, _)
return okokBanking:AddMoney(account, amount)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, _)
Banking.RemoveAccountMoney = function(account, amount, _)
return okokBanking:RemoveMoney(account, amount)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('qb-banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local qbBanking = exports['qb-banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'qb-banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return qbBanking:GetAccountBalance(account)
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.AddAccountMoney = function(account, amount, reason)
Banking.AddAccountMoney = function(account, amount, reason)
return qbBanking:AddMoney(account, amount, reason)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, reason)
Banking.RemoveAccountMoney = function(account, amount, reason)
return qbBanking:RemoveMoney(account, amount, reason)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('Renewed-Banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local renewed = exports['Renewed-Banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'Renewed-Banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return renewed:getAccountMoney(account)
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.AddAccountMoney = function(account, amount, _)
Banking.AddAccountMoney = function(account, amount, _)
return renewed:addAccountMoney(account, amount)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, _)
Banking.RemoveAccountMoney = function(account, amount, _)
return renewed:removeAccountMoney(account, amount)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('tgg-banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local tgg = exports['tgg-banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'tgg-banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return tgg:GetSocietyAccountMoney(account) or 0
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.AddAccountMoney = function(account, amount, _)
Banking.AddAccountMoney = function(account, amount, _)
return tgg:AddSocietyMoney(account, amount)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, _)
Banking.RemoveAccountMoney = function(account, amount, _)
return tgg:RemoveSocietyMoney(account, amount)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('tgiann-bank') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local tgiann = exports["tgiann-bank"]
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'tgiann-bank'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
return tgiann:GetJobAccountBalance(account)
end
@@ -22,7 +22,7 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.AddAccountMoney = function(account, amount, _)
Banking.AddAccountMoney = function(account, amount, _)
return tgiann:AddJobMoney(account, amount)
end
@@ -31,8 +31,8 @@ end
---@param amount number
---@param _ string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, _)
Banking.RemoveAccountMoney = function(account, amount, _)
return tgiann:RemoveJobMoney(account, amount)
end
return Managment
return Banking
@@ -1,19 +1,19 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('wasabi_banking') == 'missing' then return end
Managment = Managment or {}
Banking = Banking or {}
local wasabi_banking = exports['wasabi_banking']
---This will get the name of the Managment system being being used.
---@return string
Managment.GetManagmentName = function()
Banking.GetManagmentName = function()
return 'wasabi_banking'
end
---This will return a number
---@param account string
---@return number
Managment.GetAccountMoney = function(account)
Banking.GetAccountMoney = function(account)
local balance = wasabi_banking:GetAccountBalance(account, 'society')
return balance or 0
end
@@ -23,7 +23,7 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.AddAccountMoney = function(account, amount, reason)
Banking.AddAccountMoney = function(account, amount, reason)
return wasabi_banking:AddMoney('society', account, amount)
end
@@ -32,8 +32,8 @@ end
---@param amount number
---@param reason string
---@return boolean
Managment.RemoveAccountMoney = function(account, amount, reason)
Banking.RemoveAccountMoney = function(account, amount, reason)
return wasabi_banking:RemoveMoney('society', account, amount)
end
return Managment
return Banking
+1 -63
View File
@@ -4,8 +4,6 @@ if GetResourceState('rcore_clothing') ~= 'missing' then return end
Clothing = Clothing or {}
-- {"glasses_2":0,"shoes_1":70,"dad":0,"shoes_2":2,"pants_1":28,"eye_squint":0,"ears_1":-1,"hair_color_1":61,"eyebrows_6":0,"bodyb_3":-1,"beard_1":11,"complexion_2":0,"arms_2":0,"hair_1":76,"nose_1":0,"blush_2":0,"bracelets_2":0,"blush_1":0,"jaw_2":0,"helmet_1":-1,"eyebrows_3":0,"watches_1":-1,"eyebrows_4":0,"jaw_1":0,"lipstick_1":0,"eyebrows_1":0,"nose_4":0,"age_2":0,"torso_1":23,"hair_2":0,"chin_2":0,"arms":1,"chain_1":22,"nose_2":0,"cheeks_1":2,"tshirt_1":4,"glasses_1":0,"pants_2":3,"lipstick_4":0,"chin_13":0,"beard_4":0,"beard_3":0,"chain_2":2,"cheeks_3":6,"sex":0,"lipstick_3":0,"makeup_1":0,"hair_color_2":29,"mask_2":0,"chin_1":0,"eyebrows_5":0,"bodyb_2":0,"sun_2":0,"watches_2":0,"sun_1":0,"chin_4":0,"nose_3":0,"helmet_2":0,"bags_2":0,"moles_2":0,"mask_1":0,"blemishes_2":0,"chest_1":0,"cheeks_2":-10,"age_1":0,"chest_2":0,"beard_2":10,"torso_2":2,"blush_3":0,"bproof_1":0,"moles_1":0,"chin_3":0,"lip_thickness":-2,"lipstick_2":0,"chest_3":0,"complexion_1":0,"bodyb_4":0,"neck_thickness":0,"bproof_2":0,"makeup_3":0,"tshirt_2":2,"makeup_2":0,"makeup_4":0,"bracelets_1":-1,"decals_2":0,"nose_6":0,"bodyb_1":-1,"bags_1":0,"blemishes_1":0,"decals_1":0,"mom":21,"eyebrows_2":0,"eye_color":0,"skin_md_weight":50,"face_md_weight":50,"nose_5":10,"ears_2":0}
Components = {}
Components.Map = {
[1] = 'mask', -- componentId
@@ -141,64 +139,4 @@ function Clothing.ConvertToDefault(esxClothing)
local components = Components.ConvertToDefault(esxClothing)
local props = Props.ConvertToDefault(esxClothing)
return { components = components, props = props }
end
-- Clothing = {}
-- StoredOldClothing = {}
-- Clothing.SetAppearance = function(clothingData)
-- if GetEntityModel(cache.ped) == `mp_m_freemode_01` then
-- clothingData = clothingData.male
-- else
-- clothingData = clothingData.female
-- end
-- local repackedTable = {}
-- local componentMap = {
-- [1] = "mask",
-- [3] = "arms",
-- [4] = "pants",
-- [5] = "bag",
-- [6] = "shoes",
-- [7] = "accessory",
-- [8] = "t-shirt",
-- [9] = "vest",
-- [10] = "decals",
-- [11] = "torso2"
-- }
-- local propMap = {
-- [0] = "hat",
-- [1] = "glass",
-- [2] = "ear",
-- [6] = "watch",
-- [7] = "bracelet"
-- }
-- local specialMap = {
-- eye_color_id = "eye_color",
-- moles_id = "moles",
-- ageing_id = "ageing",
-- hair_id = "hair",
-- face_id = "face"
-- }
-- for _, data in pairs(clothingData) do
-- if componentMap[data.component_id] then
-- repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif propMap[data.prop_id] then
-- repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.eye_color_id] then
-- repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.moles_id] then
-- repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.ageing_id] then
-- repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.hair_id] then
-- repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.face_id] then
-- repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture}
-- end
-- end
-- TriggerEvent('esx-clothing:client:loadOutfit', repackedTable)
-- end
end
+51 -44
View File
@@ -18,13 +18,22 @@ function Clothing.GetFullAppearanceData(src)
if Clothing.Players[citId] then return Clothing.Players[citId] end
local result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { citId, 1 })
if result[1] == nil then return end
local model = result[1].model
local skinData = json.decode(result[1].skin)
local converted = skinData
local result = nil
local model = GetEntityModel(GetPlayerPed(src))
local skinData = nil
local converted = nil
if Bridge.Framework.GetFrameworkName() == "es_extended" then
result = MySQL.query.await('SELECT skin FROM users WHERE identifier = ?', { citId })
if not result or not result[1] then return end
skinData = json.decode(result[1].skin)
converted = skinData
else
result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { citId, 1 })
if not result or not result[1] then return end
model = result[1].model
skinData = json.decode(result[1].skin)
converted = skinData
end
-- Store complete data in the cache
Clothing.Players[citId] = {
model = model,
@@ -156,49 +165,47 @@ Callback.Register('community_bridge:cb:GetAppearance', function(source)
return Clothing.GetAppearance(src)
end)
RegisterCommand('clothing:debug', function(source, args, rawCommand)
local src = source
Clothing.SetAppearance(src, {
components = {
{ component_id = 1, drawable = math.random(0, 50), texture = 0 },
{ component_id = 2, drawable = math.random(0, 50), texture = 0 },
{ component_id = 3, drawable = math.random(0, 50), texture = 0 },
{ component_id = 4, drawable = math.random(0, 50), texture = 0 },
{ component_id = 5, drawable = math.random(0, 50), texture = 0 },
{ component_id = 6, drawable = math.random(0, 50), texture = 0 },
{ component_id = 7, drawable = math.random(0, 50), texture = 0 },
{ component_id = 8, drawable = math.random(0, 50), texture = 0 },
},
props = {
{ prop_id = 3, drawable = 0, texture = 0 },
{ prop_id = 1, drawable = 0, texture = 0 },
{ prop_id = 2, drawable = 0, texture = 0 },
}
}, false, true)
end, false)
-- All the this below should go in unit tests if we are to continue using them.
-- RegisterCommand('clothing:debug', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
-- components = {
-- { component_id = 1, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 2, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 3, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 4, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 5, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 6, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 7, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 8, drawable = math.random(0, 50), texture = 0 },
-- },
-- props = {
-- { prop_id = 3, drawable = 0, texture = 0 },
-- { prop_id = 1, drawable = 0, texture = 0 },
-- { prop_id = 2, drawable = 0, texture = 0 },
-- }
-- }, false, true)
-- end, false)
RegisterCommand('clothing:revert', function(source, args, rawCommand)
local src = source
Clothing.Revert(src)
end, false)
-- RegisterCommand('clothing:revert', function(source, args, rawCommand)
-- local src = source
-- Clothing.Revert(src)
-- end, false)
RegisterCommand('clothing:current', function(source, args, rawCommand)
local src = source
local currentClothing = Clothing.GetAppearance(src)
if not currentClothing then return end
print(json.encode(currentClothing, { indent = true }))
end, false)
-- RegisterCommand('clothing:current', function(source, args, rawCommand)
-- local src = source
-- local currentClothing = Clothing.GetAppearance(src)
-- if not currentClothing then return end
-- print(json.encode(currentClothing, { indent = true }))
-- end, false)
RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
local src = source
Clothing.OpenMenu(src)
end, false)
-- RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
-- local src = source
-- Clothing.OpenMenu(src)
-- end, false)
-- This should be moved into unit tests
-- RegisterCommand('clothing:crowley', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
+85 -85
View File
@@ -158,96 +158,96 @@ Callback.Register('community_bridge:cb:GetAppearance', function(source)
return Clothing.GetAppearance(src)
end)
-- The below Should go to unit test
RegisterCommand('clothing:debug', function(source, args, rawCommand)
local src = source
Clothing.SetAppearance(src, {
components = {
{ component_id = 0, drawable = math.random(0, 50), texture = 0 },
{ component_id = 1, drawable = math.random(0, 50), texture = 0 },
{ component_id = 2, drawable = math.random(0, 50), texture = 0 },
{ component_id = 3, drawable = math.random(0, 50), texture = 0 },
{ component_id = 4, drawable = math.random(0, 50), texture = 0 },
{ component_id = 5, drawable = math.random(0, 50), texture = 0 },
{ component_id = 6, drawable = math.random(0, 50), texture = 0 },
{ component_id = 7, drawable = math.random(0, 50), texture = 0 },
{ component_id = 8, drawable = math.random(0, 50), texture = 0 },
{ component_id = 9, drawable = math.random(0, 50), texture = 0 },
{ component_id = 10, drawable = math.random(0, 50), texture = 0 },
{ component_id = 11, drawable = math.random(0, 50), texture = 0 },
},
props = {
{ prop_id = 0, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 1, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 2, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 3, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 4, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 5, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 6, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 7, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 8, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 9, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 10, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 11, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 12, drawable = math.random(0, 50), texture = 0 },
{ prop_id = 13, drawable = math.random(0, 50), texture = 0 },
}
}, false, true)
end, false)
-- All the this below should go in unit tests if we are to continue using them.
-- RegisterCommand('clothing:debug', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
-- components = {
-- { component_id = 0, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 1, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 2, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 3, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 4, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 5, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 6, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 7, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 8, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 9, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 10, drawable = math.random(0, 50), texture = 0 },
-- { component_id = 11, drawable = math.random(0, 50), texture = 0 },
-- },
-- props = {
-- { prop_id = 0, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 1, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 2, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 3, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 4, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 5, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 6, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 7, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 8, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 9, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 10, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 11, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 12, drawable = math.random(0, 50), texture = 0 },
-- { prop_id = 13, drawable = math.random(0, 50), texture = 0 },
-- }
-- }, false, true)
-- end, false)
RegisterCommand('clothing:revert', function(source, args, rawCommand)
local src = source
Clothing.Revert(src)
end, false)
-- RegisterCommand('clothing:revert', function(source, args, rawCommand)
-- local src = source
-- Clothing.Revert(src)
-- end, false)
RegisterCommand('clothing:current', function(source, args, rawCommand)
local src = source
local currentClothing = Clothing.GetAppearance(src)
if not currentClothing then return end
print(json.encode(currentClothing, { indent = true }))
end, false)
-- RegisterCommand('clothing:current', function(source, args, rawCommand)
-- local src = source
-- local currentClothing = Clothing.GetAppearance(src)
-- if not currentClothing then return end
-- print(json.encode(currentClothing, { indent = true }))
-- end, false)
RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
local src = source
Clothing.OpenMenu(src)
end, false)
-- RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
-- local src = source
-- Clothing.OpenMenu(src)
-- end, false)
RegisterCommand('clothing:crowley', function(source, args, rawCommand)
local src = source
Clothing.SetAppearance(src, {
components = {
{ drawable = 0, texture = 0, component_id = 0 },
{ drawable = 0, texture = 0, component_id = 1 },
{ drawable = 19, texture = 0, component_id = 2 },
{ drawable = 6, texture = 0, component_id = 3 },
{ drawable = 0, texture = 0, component_id = 4 },
{ drawable = 0, texture = 0, component_id = 5 },
{ drawable = 0, texture = 0, component_id = 6 },
{ drawable = 0, texture = 0, component_id = 7 },
{ drawable = 23, texture = 0, component_id = 8 },
{ drawable = 0, texture = 0, component_id = 9 },
{ drawable = 0, texture = 0, component_id = 10 },
{ drawable = 4, texture = 2, component_id = 11 }
},
props = {
{ drawable = 27, prop_id = 0, texture = 0 },
{ drawable = 0, prop_id = 1, texture = 0 },
{ drawable = 0, prop_id = 2, texture = 0 },
{ drawable = 0, prop_id = 3, texture = 0 },
{ drawable = 0, prop_id = 4, texture = 0 },
{ drawable = 0, prop_id = 5, texture = 0 },
{ drawable = 0, prop_id = 6, texture = 0 },
{ drawable = 0, prop_id = 7, texture = 0 },
{ drawable = 0, prop_id = 8, texture = 0 },
{ drawable = 0, prop_id = 9, texture = 0 },
{ drawable = 0, prop_id = 10, texture = 0 },
{ drawable = 0, prop_id = 11, texture = 0 },
{ drawable = 0, prop_id = 12, texture = 0 },
{ drawable = 0, prop_id = 13, texture = 0 }
-- RegisterCommand('clothing:crowley', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
-- components = {
-- { drawable = 0, texture = 0, component_id = 0 },
-- { drawable = 0, texture = 0, component_id = 1 },
-- { drawable = 19, texture = 0, component_id = 2 },
-- { drawable = 6, texture = 0, component_id = 3 },
-- { drawable = 0, texture = 0, component_id = 4 },
-- { drawable = 0, texture = 0, component_id = 5 },
-- { drawable = 0, texture = 0, component_id = 6 },
-- { drawable = 0, texture = 0, component_id = 7 },
-- { drawable = 23, texture = 0, component_id = 8 },
-- { drawable = 0, texture = 0, component_id = 9 },
-- { drawable = 0, texture = 0, component_id = 10 },
-- { drawable = 4, texture = 2, component_id = 11 }
-- },
-- props = {
-- { drawable = 27, prop_id = 0, texture = 0 },
-- { drawable = 0, prop_id = 1, texture = 0 },
-- { drawable = 0, prop_id = 2, texture = 0 },
-- { drawable = 0, prop_id = 3, texture = 0 },
-- { drawable = 0, prop_id = 4, texture = 0 },
-- { drawable = 0, prop_id = 5, texture = 0 },
-- { drawable = 0, prop_id = 6, texture = 0 },
-- { drawable = 0, prop_id = 7, texture = 0 },
-- { drawable = 0, prop_id = 8, texture = 0 },
-- { drawable = 0, prop_id = 9, texture = 0 },
-- { drawable = 0, prop_id = 10, texture = 0 },
-- { drawable = 0, prop_id = 11, texture = 0 },
-- { drawable = 0, prop_id = 12, texture = 0 },
-- { drawable = 0, prop_id = 13, texture = 0 }
}
}, false, true)
end, false)
-- }
-- }, false, true)
-- end, false)
+35 -36
View File
@@ -166,47 +166,46 @@ Callback.Register('community_bridge:cb:GetAppearance', function(source)
return Clothing.GetAppearance(src)
end)
--[[
RegisterCommand('clothing:debug', function(source, args, rawCommand)
local src = source
Clothing.SetAppearance(src, {
components ={
{component_id = 1, drawable = math.random(0, 50), texture = 0},
{component_id = 2, drawable = math.random(0, 50), texture = 0},
{component_id = 3, drawable = math.random(0, 50), texture = 0},
{component_id = 4, drawable = math.random(0, 50), texture = 0},
{component_id = 5, drawable = math.random(0, 50), texture = 0},
{component_id = 6, drawable = math.random(0, 50), texture = 0},
{component_id = 7, drawable = math.random(0, 50), texture = 0},
{component_id = 8, drawable = math.random(0, 50), texture = 0},
},
props = {
{prop_id = 3, drawable = 0, texture = 0},
{prop_id = 1, drawable = 0, texture = 0},
{prop_id = 2, drawable = 0, texture = 0},
}
}, false, true)
end, false)
-- All the this below should go in unit tests if we are to continue using them.
-- RegisterCommand('clothing:debug', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
-- components ={
-- {component_id = 1, drawable = math.random(0, 50), texture = 0},
-- {component_id = 2, drawable = math.random(0, 50), texture = 0},
-- {component_id = 3, drawable = math.random(0, 50), texture = 0},
-- {component_id = 4, drawable = math.random(0, 50), texture = 0},
-- {component_id = 5, drawable = math.random(0, 50), texture = 0},
-- {component_id = 6, drawable = math.random(0, 50), texture = 0},
-- {component_id = 7, drawable = math.random(0, 50), texture = 0},
-- {component_id = 8, drawable = math.random(0, 50), texture = 0},
-- },
-- props = {
-- {prop_id = 3, drawable = 0, texture = 0},
-- {prop_id = 1, drawable = 0, texture = 0},
-- {prop_id = 2, drawable = 0, texture = 0},
-- }
-- }, false, true)
-- end, false)
RegisterCommand('clothing:revert', function(source, args, rawCommand)
local src = source
Clothing.Revert(src)
end, false)
-- RegisterCommand('clothing:revert', function(source, args, rawCommand)
-- local src = source
-- Clothing.Revert(src)
-- end, false)
RegisterCommand('clothing:current', function(source, args, rawCommand)
local src = source
local currentClothing = Clothing.GetAppearance(src)
if not currentClothing then return end
print(json.encode(currentClothing, { indent = true }))
end, false)
-- RegisterCommand('clothing:current', function(source, args, rawCommand)
-- local src = source
-- local currentClothing = Clothing.GetAppearance(src)
-- if not currentClothing then return end
-- print(json.encode(currentClothing, { indent = true }))
-- end, false)
RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
local src = source
Clothing.OpenMenu(src)
end, false)
--]]
-- RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
-- local src = source
-- Clothing.OpenMenu(src)
-- end, false)
-- RegisterCommand('clothing:crowley', function(source, args, rawCommand)
-- local src = source
+1 -61
View File
@@ -125,64 +125,4 @@ function Clothing.ConvertToDefault(qbClothing)
local components = Components.ConvertToDefault(qbClothing)
local props = Props.ConvertToDefault(qbClothing)
return { components = components, props = props }
end
-- Clothing = {}
-- StoredOldClothing = {}
-- Clothing.SetAppearance = function(clothingData)
-- if GetEntityModel(cache.ped) == `mp_m_freemode_01` then
-- clothingData = clothingData.male
-- else
-- clothingData = clothingData.female
-- end
-- local repackedTable = {}
-- local componentMap = {
-- [1] = "mask",
-- [3] = "arms",
-- [4] = "pants",
-- [5] = "bag",
-- [6] = "shoes",
-- [7] = "accessory",
-- [8] = "t-shirt",
-- [9] = "vest",
-- [10] = "decals",
-- [11] = "torso2"
-- }
-- local propMap = {
-- [0] = "hat",
-- [1] = "glass",
-- [2] = "ear",
-- [6] = "watch",
-- [7] = "bracelet"
-- }
-- local specialMap = {
-- eye_color_id = "eye_color",
-- moles_id = "moles",
-- ageing_id = "ageing",
-- hair_id = "hair",
-- face_id = "face"
-- }
-- for _, data in pairs(clothingData) do
-- if componentMap[data.component_id] then
-- repackedTable[componentMap[data.component_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif propMap[data.prop_id] then
-- repackedTable[propMap[data.prop_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.eye_color_id] then
-- repackedTable[specialMap[data.eye_color_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.moles_id] then
-- repackedTable[specialMap[data.moles_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.ageing_id] then
-- repackedTable[specialMap[data.ageing_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.hair_id] then
-- repackedTable[specialMap[data.hair_id]] = {drawable = data.drawable, texture = data.texture}
-- elseif specialMap[data.face_id] then
-- repackedTable[specialMap[data.face_id]] = {drawable = data.drawable, texture = data.texture}
-- end
-- end
-- TriggerEvent('qb-clothing:client:loadOutfit', repackedTable)
-- end
end
@@ -66,7 +66,6 @@ function Dialogue.Open( name, dialogue, characterOptions, dialogueOptions, onSel
SetCamCoord(cam, endLocation.x, endLocation.y, endLocation.z)
RenderScriptCams(true, true, 1000, true, false)
SetCamActive(cam, true)
end
SendNUIMessage({
type = "open",
+4 -3
View File
@@ -5,15 +5,16 @@ Dispatch = Dispatch or {}
---@param data table The data to send to the dispatch system.
---@return nil
Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
TriggerServerEvent('community_bridge:Server:DispatchAlert', {
sprite = data.blipData.sprite or 161,
color = data.blipData.color or 1,
scale = data.blipData.scale or 0.8,
vehicle = data.vehicle or nil,
plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil,
ped = data.ped or cache.ped,
pedCoords = data.pedCoords or GetEntityCoords(cache.ped),
coords = data.coords or GetEntityCoords(cache.ped),
ped = data.ped or ped,
pedCoords = data.pedCoords or GetEntityCoords(ped),
coords = data.coords or GetEntityCoords(ped),
message = data.message or "An Alert Has Been Made",
code = data.code or '10-80',
icon = data.icon or 'fas fa-question',
+3 -2
View File
@@ -3,14 +3,15 @@ if GetResourceState('bub-mdt') == 'missing' then return end
Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
local alertData = {
code = data.code or '10-80',
offense = data.message,
coords = data.coords or GetEntityCoords(cache.ped),
coords = data.coords or GetEntityCoords(ped),
info = { label = data.code or '10-80', icon = data.icon or 'fas fa-question' },
blip = data.blipData.sprite or 1,
isEmergency = data.priority == 1 and true or false,
blipCoords = data.coords or cache.ped and GetEntityCoords(cache.ped) or { x = 0, y = 0},
blipCoords = data.coords or ped and GetEntityCoords(ped) or { x = 0, y = 0},
}
exports["bub-mdt"]:CustomAlert(alertData)
end
@@ -3,6 +3,7 @@ if GetResourceState('linden_outlawalert') == 'missing' then return end
Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
TriggerServerEvent('wf-alerts:svNotify', {
dispatchData = {
displayCode = data.code or '211',
@@ -14,7 +15,7 @@ Dispatch.SendAlert = function(data)
info = data.message or "Alert"
},
caller = 'Anonymous',
coords = data.coords or GetEntityCoords(cache.ped)
coords = data.coords or GetEntityCoords(ped)
})
end
@@ -17,7 +17,7 @@ Dispatch.SendAlert = function(data)
model = data.vehicle and (GetDisplayNameFromVehicleModel(GetEntityModel(data.vehicle))) or nil,
color = color,
plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil,
speed = data.vehicle and (GetEntitySpeed(veh) * 3.6)..' kmh' or nil
speed = data.vehicle and (GetEntitySpeed(data.vehicle) * 3.6)..' kmh' or nil
}
}
@@ -0,0 +1,10 @@
---@diagnostic disable: duplicate-set-field
if GetResourceState('piotreq_gpt') == 'missing' then return end
Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data)
if not data then return end
TriggerServerEvent('community_bridge:Server:piotreq_gpt', data)
end
return Dispatch
@@ -0,0 +1,39 @@
if GetResourceState('piotreq_gpt') == 'missing' then return end
Dispatch = Dispatch or {}
Dispatch.SendAlert = function(src, alertData)
-- No clue if this works, but itd be nice to have someone test it.
--https://piotreq-scripts.gitbook.io/piotreq-scripts/assets-and-guides/police-mdt/dispatch-system
exports['piotreq_gpt']:SendAlert(src, {
title = alertData.message or "No message provided",
code = alertData.code or '10-80',
icon = alertData.icon or 'fa-solid fa-question',
info = {
{icon = 'fa-solid fa-road', isStreet = true},
{icon = alertData.icon or 'fa-solid fa-question', data = alertData.message or "No additional info"},
},
blip = { -- optional
scale = alertData.blipData and alertData.blipData.scale or 1.0,
sprite = alertData.blipData and alertData.blipData.sprite or 161,
category = 1, -- default 1
color = alertData.blipData and alertData.blipData.color or 84,
hidden = false, -- default false (hidden on legend)
priority = alertData.priority or 5, -- default 5
short = true, -- as short range? default true
alpha = 200, -- default 255
name = alertData.message or "Dispatch Alert"
},
type = 'normal', -- default normal
canAnswer = false, -- default false
maxOfficers = 6, -- default 4
time = 10,-- 10 minutes, default 5
notifyTime = 8000, -- 8 seconds, default 7
})
end
RegisterNetEvent('community_bridge:Server:piotreq_gpt', function(data)
local src = source
Dispatch.SendAlert(src, data)
end)
return Dispatch
+14 -17
View File
@@ -5,27 +5,24 @@ Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data)
local alertData = {
message = data.message,
message = data.message or "No message provided",
code = data.code or '10-80',
icon = data.icon or 'fas fa-question',
priority = 2,
coords = data.coords,
priority = data.priority or 2,
coords = data.coords or GetEntityCoords(PlayerPedId()),
vehicle = data.vehicle,
plate = data.plate,
alertTime = (data.time or 10000) / 1000,
alert = {
radius = 0,
recipientList = data.jobs,
sprite = data.blipData.sprite,
color = data.blipData.color,
scale = data.blipData.scale,
length = 2,
sound = "Lose_1st",
sound2 = "GTAO_FM_Events_Soundset",
offset = false,
flash = false
},
jobs = data.jobs
alertTime = data.time and (data.time / 1000) or nil,
radius = data.blipData and data.blipData.radius or 0,
sprite = data.blipData and data.blipData.sprite or 161,
color = data.blipData and data.blipData.color or 84,
scale = data.blipData and data.blipData.scale or 1.0,
length = 2,
sound = "Lose_1st",
sound2 = "GTAO_FM_Events_Soundset",
offset = false,
flash = data.blipData and data.blipData.flash or false,
jobs = data.jobs or data.job or "police"
}
exports["ps-dispatch"]:CustomAlert(alertData)
end
+2 -1
View File
@@ -6,10 +6,11 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped
---@return string | nil
Doorlock.GetClosestDoor = function()
local ped = PlayerPedId()
local closestDoor = exports["qb-doorlock"]:GetClosestDoor()
if Table.CheckPopulated(closestDoor) then return closestDoor end
local allDoors = exports["qb-doorlock"]:GetDoorList()
local pedCoords = GetEntityCoords(cache.ped)
local pedCoords = GetEntityCoords(ped)
local door = 0
local doorDist = 1000.0
for doorID, data in pairs(allDoors) do
+2 -1
View File
@@ -6,8 +6,9 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped
---@return string | nil
Doorlock.GetClosestDoor = function()
local ped = PlayerPedId()
local allDoors = exports.rcore_doorlock:getLoadedDoors()
local pedCoords = GetEntityCoords(cache.ped)
local pedCoords = GetEntityCoords(ped)
local door = 0
local doorDist = 1000.0
for _, data in pairs(allDoors) do
+53
View File
@@ -1,3 +1,56 @@
Framework = Framework or {}
local jobsRegisteredTable = {}
local invertedJobsRegisteredTable = {}
---This is an internal function that will be used to retrieve job counts later.
---@param jobName string
---@return number
Framework.GetJobCount = function(jobName)
return #jobsRegisteredTable[jobName] or 0
end
---This will return a list of player sources for a given job.
---@param jobName string
---@return table
Framework.GetPlayerSourcesByJob = function(jobName)
if not jobsRegisteredTable[jobName] then return {} end
return jobsRegisteredTable[jobName]
end
---This will update the cached tables for job counts.
---This is used to track how many players are in a job.
---@param src number
---@param jobName string
Framework.AddJobCount = function(src, jobName)
if not jobsRegisteredTable[jobName] then jobsRegisteredTable[jobName] = {} end
if jobsRegisteredTable[jobName][src] then return false end
jobsRegisteredTable[jobName][src] = true
invertedJobsRegisteredTable[src] = jobName
return true, #jobsRegisteredTable[jobName]
end
---This will return the job name for a given source.
---This is an internal function that will be used to retrieve job names in situations where player data is unavailable.
---@param src number
Framework.SearchJobCountBySource = function(src)
if not invertedJobsRegisteredTable[src] then return nil end
return invertedJobsRegisteredTable[src]
end
---This will remove the job count for a given source.
---@param src number
---@param jobName string | nil
Framework.RemoveJobCount = function(src, jobName)
if not jobName then
jobName = Framework.SearchJobCountBySource(src)
end
if not jobName then return false end
if not jobsRegisteredTable[jobName] then return false end
if not jobsRegisteredTable[jobName][src] then return false end
invertedJobsRegisteredTable[src] = nil
jobsRegisteredTable[jobName][src] = nil
return true, #jobsRegisteredTable[jobName]
end
return Framework
+10 -12
View File
@@ -330,24 +330,16 @@ Framework.SetPlayerDuty = function(src, status)
local xPlayer = Framework.GetPlayer(src)
if not xPlayer then return false end
local job = xPlayer.getJob()
if not job.onDuty then return false end
if job.name == 'unemployed' then return false end
xPlayer.setJob(job.name, job.grade, status)
return true
end
---This will get a table of player sources that have the specified job name.
---@param job any
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local players = GetPlayers()
local playerList = {}
for _, src in pairs(players) do
local xPlayer = Framework.GetPlayer(src)
if xPlayer and xPlayer.getJob().name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
-- Sets the player's job to the specified name and grade.
@@ -363,7 +355,7 @@ Framework.SetPlayerJob = function(src, name, grade)
return
end
xPlayer.setJob(name, grade, true)
return true
return true
end
---This will add money based on the type of account (money/bank)
@@ -474,6 +466,12 @@ RegisterNetEvent("esx:playerLogout", function(src)
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
RegisterNetEvent("esx:setJob", function(src, job, lastJob)
src = src or source
if not job or not lastJob then return end
TriggerEvent("community_bridge:Server:OnPlayerJobChange", src, job.name)
end)
AddEventHandler("playerDropped", function()
local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
+8 -10
View File
@@ -361,18 +361,10 @@ Framework.GetPlayerGang = function(src)
end
---This will get a table of player sources that have the specified job name.
---@param job any
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local playerList = {}
local players = QBCore.Functions.GetPlayers()
for _, src in pairs(players) do
local player = Framework.GetPlayer(src).PlayerData
if player.job.name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
---Depricated: Returns the job name, label, grade name, and grade level of the player.
@@ -572,6 +564,12 @@ RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
RegisterNetEvent("QBCore:Server:OnJobUpdate", function(src, job)
src = src or source
if not job then return end
TriggerEvent("community_bridge:Server:OnPlayerJobChange", src, job.name)
end)
AddEventHandler("playerDropped", function()
local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
+1 -2
View File
@@ -56,8 +56,7 @@ end
---@param metadata table | string
---@return table | string | number | boolean
Framework.GetPlayerMetaData = function(metadata)
local playerData = Framework.GetPlayerData()
return playerData.metadata[metadata]
return Framework.GetPlayerData().metadata[metadata]
end
---This will send a notification to the player.
+8 -9
View File
@@ -286,18 +286,11 @@ Framework.GetPlayerGang = function(src)
return player.gang.name
end
---This will return a table of all players with the specified job.
---This will get a table of player sources that have the specified job name.
---@param job string
---@return table
Framework.GetPlayersByJob = function(job)
local playerList = {}
local players = QBox:GetQBPlayers()
for src, player in pairs(players) do
if player.PlayerData.job.name == job then
table.insert(playerList, src)
end
end
return playerList
return Framework.GetPlayerSourcesByJob(job) or {}
end
---Depricated: Returns the job name, label, grade name, and grade level of the player.
@@ -481,6 +474,12 @@ RegisterNetEvent("QBCore:Server:OnPlayerUnload", function(src)
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
end)
RegisterNetEvent("QBCore:Server:OnJobUpdate", function(src, job)
src = src or source
if not job then return end
TriggerEvent("community_bridge:Server:OnPlayerJobChange", src, job.name)
end)
AddEventHandler("playerDropped", function()
local src = source
TriggerEvent("community_bridge:Server:OnPlayerUnload", src)
+1
View File
@@ -1,6 +1,7 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "LegacyFuel"
if GetResourceState(resourceName) == 'missing' then return end
if GetResourceState("qb-fuel") == 'started' then return end
Fuel = Fuel or {}
---This will get the name of the Fuel being used (if a supported Fuel).
+29
View File
@@ -0,0 +1,29 @@
---@diagnostic disable: duplicate-set-field
local resourceName = "qb-fuel"
if GetResourceState(resourceName) == 'missing' then return end
Fuel = Fuel or {}
---This will get the name of the Fuel being used (if a supported Fuel).
---@return string
Fuel.GetResourceName = function()
return resourceName
end
---This will get the fuel level of the vehicle.
---@param vehicle number The vehicle entity ID.
---@return number fuel The fuel level of the vehicle.
Fuel.GetFuel = function(vehicle)
if not DoesEntityExist(vehicle) then return 0.0 end
return exports['qb-fuel']:GetFuel(vehicle)
end
---This will set the fuel level of the vehicle.
---@param vehicle number The vehicle entity ID.
---@param fuel number The fuel level to set.
---@return nil
Fuel.SetFuel = function(vehicle, fuel, type)
if not DoesEntityExist(vehicle) then return end
return exports['qb-fuel']:SetFuel(vehicle, fuel)
end
return Fuel
+10 -1
View File
@@ -8,7 +8,16 @@ Input = {}
function Input.Open(title, data, isQBFormat, submitText)
local inputs = data.inputs
if isQBFormat then
return lib.inputDialog(title, QBToOxInput(inputs))
local convertedData = {}
local returnData = lib.inputDialog(title, QBToOxInput(inputs))
for i, v in pairs(inputs) do
for k, j in pairs(returnData or {}) do
if k == v.name then
convertedData[v.name] = j
end
end
end
return convertedData
else
return lib.inputDialog(title, data)
end
+1 -1
View File
@@ -24,7 +24,7 @@ function Input.Open(title, data, isQBFormat, submitText)
for i, v in pairs(input) do
for k, j in pairs(returnData) do
if k == v.name then
convertedData[tonumber(i)] = j
convertedData[v.name] = j
end
end
end
+18
View File
@@ -32,9 +32,14 @@ end
---@param item string
---@return string
Inventory.GetImagePath = function(item)
print("No get image path for this inventory, using default.")
return "https://avatars.githubusercontent.com/u/47620135"
end
---This will remove the file extension from the item name if present.
---example: "item.png" will become "item"
---@param item string
---@return string
Inventory.StripPNG = function(item)
if string.find(item, ".png") then
item = string.gsub(item, ".png", "")
@@ -42,6 +47,17 @@ Inventory.StripPNG = function(item)
return item
end
---This will remove the file extension from the item name if present.
---example: "item.webp" will become "item"
---@param item string
---@return string
Inventory.StripWebp = function(item)
if string.find(item, ".webp") then
item = string.gsub(item, ".webp", "")
end
return item
end
---This will return the entire items table from the inventory.
---@return table
Inventory.Items = function()
@@ -52,4 +68,6 @@ Inventory.Items = function()
return Framework.Shared.Items
end
return Inventory
+15
View File
@@ -193,4 +193,19 @@ Inventory.StripPNG = function(item)
return item
end
---This will remove the file extension from the item name if present.
---example: "item.webp" will become "item"
---@param item string
---@return string
Inventory.StripWebp = function(item)
if string.find(item, ".webp") then
item = string.gsub(item, ".webp", "")
end
return item
end
Inventory.OpenPlayerInventory = function(src, targetSrc)
return false, Prints.Error("OpenPlayerInventory is not implemented in this inventory, because of this we dont have a way to open a players inventory.")
end
return Inventory
@@ -190,4 +190,13 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports['codem-inventory']:OpenInventory(src, target)
end
return Inventory
@@ -257,4 +257,14 @@ Inventory.Items = function()
return core:getItemsList()
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
local identifier = Framework.GetPlayerIdentifier(target)
if not identifier then return false end
exports.core_inventory:openInventory(src, 'stash-'.. identifier:gsub(':',''), 'stash', nil, nil, true, nil, false)
end
return Inventory
@@ -189,4 +189,14 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
return true
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
local identifier = Framework.GetPlayerIdentifier(target)
if not identifier then return false end
exports['jpr-inventory']:OpenInventory(src, identifier)
end
return Inventory
@@ -239,4 +239,12 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports.origen_inventory:OpenInventory(src, "otherplayer", target)
end
return Inventory
@@ -17,6 +17,7 @@ Inventory.Stashes = Inventory.Stashes or {}
---@param metadata table
---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata)
if not ox_inventory:CanCarryItem(src, item, count, metadata) then return false end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return ox_inventory:AddItem(src, item, count, metadata)
end
@@ -224,4 +225,12 @@ Inventory.GetItem = function(src, item, metadata)
return ox_inventory:GetItem(src, item, metadata, false)
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports.ox_inventory:openInventory('player', target)
end
return Inventory
@@ -21,6 +21,7 @@ end
---@param metadata table
---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata)
if getInventoryNewVersion() then if not qbInventory:CanAddItem(src, item, count) then return false end end
TriggerClientEvent('qb-inventory:client:ItemBox', src, QBCore.Shared.Items[item], 'add', count)
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return qbInventory:AddItem(src, item, count, slot, metadata, 'community_bridge')
@@ -275,4 +276,12 @@ Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGrou
end
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports['qb-inventory']:OpenInventory(src, target)
end
return Inventory
+1 -1
View File
@@ -18,7 +18,7 @@ Inventory.GetItemInfo = function(item)
stack = itemData.unique or "false",
weight = itemData.weight or "0",
description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item),
image = Inventory.GetImagePath(item),
}
end
@@ -233,4 +233,12 @@ Inventory.GetImagePath = function(item)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports['qs-inventory']:OpenInventory(src, target)
end
return Inventory
@@ -10,13 +10,14 @@ Inventory = Inventory or {}
Inventory.GetItemInfo = function(item)
local itemData = tgiann:GetItemList()
if not itemData[item] then return {} end
itemData = itemData[item]
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
weight = itemData.weight or "0",
description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item),
image = Inventory.GetImagePath(item),
}
end
@@ -39,10 +40,11 @@ end
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item)
local pngItem = Inventory.StripPNG(item)
local webpItem = Inventory.StripWebp(item)
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
local webpPath = LoadResourceFile("inventory_images", string.format("/images/%s.webp", webpItem))
local imagePath = pngPath and string.format("nui://inventory_images/images/%s.png", pngItem) or webpPath and string.format("nui://inventory_images/images/%s.webp", webpItem)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
+16 -6
View File
@@ -14,6 +14,7 @@ Inventory.Stashes = Inventory.Stashes or {}
---@param metadata table
---@return boolean
Inventory.AddItem = function(src, item, count, slot, metadata)
if not tgiann:CanCarryItem(src, item, count) then return false end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = count, slot = slot, metadata = metadata})
return tgiann:AddItem(src, item, count, slot, metadata, false)
end
@@ -200,18 +201,18 @@ Inventory.ClearStash = function(id, _type)
return true
end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---This will get the image path for this item, if not found will return placeholder.
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item)
local pngItem = Inventory.StripPNG(item)
local webpItem = Inventory.StripWebp(item)
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
local webpPath = LoadResourceFile("inventory_images", string.format("/images/%s.webp", webpItem))
local imagePath = pngPath and string.format("nui://inventory_images/images/%s.png", pngItem) or webpPath and string.format("nui://inventory_images/images/%s.webp", webpItem)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---UNUSED:
---This will return generic item data from the specified inventory, with the items total count.
---
@@ -229,4 +230,13 @@ Inventory.GetItem = function(src, item, metadata)
return item
end
Inventory.OpenPlayerInventory = function(src, target)
assert(src, "OpenPlayerInventory: src is required")
if not target then
target = src
end
exports['tgiann-inventory']:OpenInventoryById(src, target)
end
return Inventory
+22 -2
View File
@@ -25,7 +25,7 @@ local function QBToOxMenu(id, menu)
description = v.txt,
icon = v.icon,
args = v.params.args,
onSelect = function(selected, secondary, args)
onSelect = v.action or function(selected, secondary, args)
local params = menu[id]?.options?[selected]?.params
if not params then return end
local event = params.event
@@ -55,4 +55,24 @@ end
GetMenuResourceName = function()
return resourceName
end
end
-- RegisterCommand('menutest', function()
-- local test1 = function()
-- print("Test 1 executed")
-- end
-- Bridge.Menu.Open({
-- title = "test",
-- description = "test",
-- options = {
-- {
-- title = "test",
-- description = "test",
-- icon = "fas fa-box-open",
-- onSelect = test1
-- },
-- }
-- })
-- end)
+1 -1
View File
@@ -16,7 +16,7 @@ end
---@return nil
Notify.SendNotify = function(message, _type, time)
time = time or 3000
return exports['brutal_notify']:SendAlert('Notification', message, time, _type, false)
return exports['brutal_notify']:SendAlert('Notification', message, time, _type or "success", false)
end
return Notify
+2
View File
@@ -22,6 +22,8 @@ Notify.SendNotify = function(message, _type, time)
_type = tostring(2)
elseif _type == "warning" or _type == "warn" then
_type = tostring(3)
else
_type = tostring(2) -- Default to 2 if type is not recognized
end
return exports['FL-Notify']:Notify("Notification", "", message, 5000, tonumber(_type), 0)
end
+1 -1
View File
@@ -16,7 +16,7 @@ end
---@return nil
Notify.SendNotify = function(message, _type, time)
time = time or 3000
return exports.lation_ui:notify({ message = message, type = _type, duration = time, position = 'top-right' })
return exports.lation_ui:notify({ message = message, type = _type or "success", duration = time, position = 'top-right' })
end
return Notify
+1 -1
View File
@@ -15,7 +15,7 @@ end
---@return nil
Notify.SendNotify = function(message, _type, time)
time = time or 3000
return exports['okokNotify']:Alert('Notification', message, time, _type, false)
return exports['okokNotify']:Alert('Notification', message, time, _type or "Success", false)
end
return Notify
+1 -1
View File
@@ -99,7 +99,7 @@ function ProgressBar.Open(options, cb, isQBInput)
local success = exports.lation_ui:progressBar(options)
if cb then cb(not success) end
if cb then cb(success) end
return success
end
+1 -1
View File
@@ -60,7 +60,7 @@ function ProgressBar.Open(options, cb, isQBInput)
local style = options.style or 'bar'
local success = style == 'circle' and exports.ox_lib:progressCircle(options) or exports.ox_lib:progressBar(options)
if cb then cb(not success) end
if cb then cb(success) end
return success
end
@@ -57,7 +57,7 @@ function ProgressBar.Open(options, cb, qbFormat)
end
local prom = promise.new()
exports['progressbar']:Progress(options, function(cancelled)
if cb then cb(not cancelled) end
if cb then cb( not cancelled) end
prom:resolve(not cancelled)
end)
return Citizen.Await(prom)
+2 -2
View File
@@ -51,7 +51,7 @@ Shops.CompleteCheckout = function(src, shopName, item, amount, paymentType)
local mathStuff = tonumber(itemData.price) * tonumber(amount)
if balance < mathStuff then return Notify.SendNotify(src, ilocale('Shops.NotEnoughMoney'), "error", 5000) end
if not Framework.RemoveAccountBalance(src, paymentType, mathStuff) then return end
Inventory.AddItem(src, itemData.name, amount)
Inventory.AddItem(src, itemData.name, tonumber(amount))
local itemLabel = Inventory.GetItemInfo(itemData.name).label
Notify.SendNotify(src, ilocale('Shops.PurchasedItem')..itemLabel, "success", 5000)
end
@@ -63,4 +63,4 @@ RegisterNetEvent("community_bridge:completeCheckout", function(shopName, item, a
Shops.CompleteCheckout(src, shopName, item, amount, paymentType)
end)
return Shops
return Shops
+19 -8
View File
@@ -22,14 +22,25 @@ Target = Target or {}
Target.FixOptions = function(options)
for k, v in pairs(options) do
local action = v.onSelect or v.action
local select = function(entityOrData)
if type(entityOrData) == 'table' then
return action(entityOrData.entity)
if not action then
local _type = v.type
if _type and _type == "server" then
v.serverEvent = v.event
v.event = nil
end
return action(entityOrData)
else
local select = function(entityOrData)
if type(entityOrData) == 'table' then
return action(entityOrData.entity)
end
return action(entityOrData)
end
v.onSelect = select
end
options[k].onSelect = select
options[k].groups = v.job or v.groups
v.groups = v.job or v.groups
-- print(json.encode(v))
end
return options
end
@@ -151,13 +162,13 @@ end
---@param coords table
---@param radius number
---@param options table
Target.AddSphereZone = function(name, coords, radius, heading, options)
Target.AddSphereZone = function(name, coords, radius, options, debug)
options = Target.FixOptions(options)
local target = ox_target:addSphereZone({
coords = coords,
radius = radius,
name = name,
debug = targetDebug,
debug = targetDebug or debug,
options = options
})
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() })
+11 -3
View File
@@ -24,14 +24,22 @@ local qb_target = exports['qb-target']
Target.FixOptions = function(options)
for k, v in pairs(options) do
local action = v.onSelect or v.action
local select = function(entityOrData)
local select = action and function(entityOrData)
if type(entityOrData) == 'table' then
return action(entityOrData.entity)
end
return action(entityOrData)
end
if v.serverEvent then
v.type = "server"
v.event = v.serverEvent
elseif v.event then
v.type = "client"
v.event = v.event
end
options[k].action = select
options[k].job = v.job or v.groups
options[k].jobType = v.jobType
end
return options
end
@@ -170,11 +178,11 @@ end
---@param coords table
---@param radius number
---@param options table
Target.AddSphereZone = function(name, coords, radius, options)
Target.AddSphereZone = function(name, coords, radius, options, debug)
options = Target.FixOptions(options)
qb_target:AddCircleZone(name, coords, radius, {
name = name,
debugPoly = targetDebug,
debugPoly = targetDebug or debug,
}, {
options = options,
distance = options.distance or 1.5,
+3 -2
View File
@@ -28,6 +28,7 @@ Target.FixOptions = function(options)
return action(entityOrData)
end
options[k].onSelect = select
options[k].groups = v.job or v.groups
end
return options
end
@@ -145,13 +146,13 @@ end
---@param coords table
---@param radius number
---@param options table
Target.AddSphereZone = function(name, coords, radius, heading, options)
Target.AddSphereZone = function(name, coords, radius, options, debug)
options = Target.FixOptions(options)
local target = sleepless_interact:addSphereZone({
coords = coords,
radius = radius,
name = name,
debug = targetDebug,
debug = targetDebug or debug,
options = options
})
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() })
+154 -21
View File
@@ -1,36 +1,169 @@
Version = Version or {}
---Pass a github username and repo name to check for the latest version of the resource.
---
---Tebex is a optional boolean to determine if the message should be for a escrowed resource or not.
---
---Example Version.VersionChecker("TheOrderFivem/community_bridge", false)
---@param repoPath string
---@param tebex boolean | nil
---@return nil
local function parseVersion(versionString)
return versionString and versionString:match('%d+%.%d+%.%d+') or versionString
end
local function padVersion(version)
local parts = {}
for num in version:gmatch("%d+") do
table.insert(parts, tonumber(num))
end
while #parts < 3 do
table.insert(parts, 0)
end
return parts
end
local function compareVersions(v1, v2)
local a, b = padVersion(v1), padVersion(v2)
for i = 1, 3 do
if a[i] < b[i] then
return -1
elseif a[i] > b[i] then
return 1
end
end
return 0
end
local function buildPatchNotesUrl(branch, repoPath)
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
return ('https://raw.githubusercontent.com/%s/%s/%s/resources.json'):format(username, reponame, branch)
end
local function getDownloadUrl(repoPath, isTebex, actualRepoPath)
if isTebex then
return "https://portal.cfx.re/assets/granted-assets"
elseif actualRepoPath then
local username, reponame = actualRepoPath:match("([^/]+)/([^/]+)")
if username and reponame then return ('https://github.com/%s/%s/releases/latest'):format(username, reponame) end
end
return nil
end
local function printUpdateAvailable(resource, localVersion, downloadUrl)
print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, localVersion, downloadUrl))
end
local function printPatchNotes(notesToPrint)
print('^3Patch Notes:^7')
for _, entry in ipairs(notesToPrint) do
print(('^2Version %s:^7'):format(entry.version))
for _, line in ipairs(entry.notes) do
print((' - %s'):format(line))
end
end
end
local function validateRepoPath(repoPath)
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
if not username or not reponame then return false, print('Invalid repository format. Expected format: username/reponame') end
return true, username, reponame
end
local function getLocalVersion(resource)
local localVersionRaw = GetResourceMetadata(resource, "version", 0)
if not localVersionRaw then
return nil, print('No version metadata found for resource "%s". Ensure fxmanifest.lua contains a valid version string.'):format(resource)
end
local version = parseVersion(localVersionRaw)
if not version then return nil, print('Invalid version format for resource "%s". Expected format: "x.x.x"'):format(resource) end
return version
end
local function processVersions(allVersions, localVersion)
local notesToPrint = {}
for versionStr, notes in pairs(allVersions) do
if compareVersions(versionStr, localVersion) > 0 and type(notes) == "table" then
table.insert(notesToPrint, { version = versionStr, notes = notes })
end
end
table.sort(notesToPrint, function(a, b)
return compareVersions(a.version, b.version) < 0
end)
return notesToPrint
end
local function fetchPatchNotes(branch, resource, repoPath, localVersion)
local url = buildPatchNotesUrl(branch, repoPath)
PerformHttpRequest(url, function(noteStatus, noteBody)
if noteStatus == 200 then
local patchData = json.decode(noteBody)
if not patchData then return end
local resourceData = patchData[resource]
if resourceData and type(resourceData) == "table" then
local actualRepoPath = resourceData.repo or resourceData.actualRepoPath
local isTebex = not actualRepoPath -- If no repo path, it's Tebex
local allVersions = resourceData.versions or resourceData -- Support both new and old format
local notesToPrint = processVersions(allVersions, localVersion)
if #notesToPrint > 0 then
local downloadUrl = getDownloadUrl(repoPath, isTebex, actualRepoPath) or url
printUpdateAvailable(resource, localVersion, downloadUrl)
printPatchNotes(notesToPrint)
end
end
elseif branch == "main" then
-- Fallback to master branch if main doesn't exist
fetchPatchNotes("master", resource, repoPath, localVersion)
end
end, 'GET')
end
--- Pass a github username and repo name to check for the latest version of the resource.
--- Tebex is a optional boolean to determine if the message should be for a escrowed resource or not.
--- Example: Version.VersionChecker("TheOrderFivem/community_bridge", false)
--- @param repoPath string
--- @param tebex boolean | nil
--- @return nil
function Version.VersionChecker(repoPath, tebex)
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
local resource = reponame and repoPath:match("([^/]+)$")
if not username or not reponame or not resource then
return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0')
end
if not username or not reponame or not resource then return print('^1Invalid repository format. Expected format: "username/reponame"^0') end
local version = GetResourceMetadata(resource, "version", 0):match('%d+%.%d+%.%d+')
local version = GetResourceMetadata(resource, "version", 0)
if not version then return end
PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response)
if status ~= 200 then return end
local latest = json.decode(response).tag_name:match('%d+%.%d+%.%d+')
if not latest or latest == version or version:gsub('%D', '') >= latest:gsub('%D', '') then return end
version = version:match('%d+%.%d+%.%d+')
if not version then return end
local url = tebex and "https://portal.cfx.re/assets/granted-assets" or json.decode(response).html_url
print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, version, url))
end, 'GET')
PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame),
function(status, response)
if status ~= 200 then return end
local latest = json.decode(response).tag_name:match('%d+%.%d+%.%d+')
if not latest or latest == version or version:gsub('%D', '') >= latest:gsub('%D', '') then return end
local url = tebex and "https://portal.cfx.re/assets/granted-assets" or json.decode(response).html_url
print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, version, url))
end,
'GET')
end
--- Advanced version checker with patch notes support
--- Reads Tebex information and repo path directly from the resources.json file
--- @param repoPath string GitHub repository path for patch notes in format "username/reponame"
--- @param resourceName string The actual resource name to check
--- @return nil
function Version.AdvancedVersionChecker(repoPath, resourceName)
local isValid, username, reponame = validateRepoPath(repoPath)
if not isValid then return print(('^1[ERROR]^7 %s'):format(username)) end
local resource = resourceName
local localVersion, errorMsg = getLocalVersion(resource)
if not localVersion then return print(('^1[ERROR]^7 %s'):format(username)) end
fetchPatchNotes("main", resource, repoPath, localVersion)
end
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
Version.VersionChecker("TheOrderFivem/community_bridge")
-- Version.VersionChecker("TheOrderFivem/community_bridge", false)
Version.AdvancedVersionChecker("TheOrderFivem/patchnotes", resourceName)
end)
return Version
return Version