Merge pull request #78 from JericoFX/main

Update on cache and config
This commit is contained in:
MrNewb authored and GitHub committed 2025-05-05 14:48:32 -04:00
commit faa733c7ea
9 files changed
+425 -191

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
{
"githubPullRequests.ignoredPullRequestBranches": ["main"]
}
+1
View File
@@ -31,6 +31,7 @@ server_scripts {
'modules/notify/**/server.lua', 'modules/notify/**/server.lua',
'modules/housing/**/server.lua', 'modules/housing/**/server.lua',
'modules/skills/**/server.lua', 'modules/skills/**/server.lua',
"lib/**/server.lua",
'init.lua', 'init.lua',
} }
+32 -5
View File
@@ -1,15 +1,31 @@
Cache = Require("lib/cache/shared/cache.lua") Cache = Require("lib/cache/shared/cache.lua")
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 -- Comparison functions for client-side state
--- Get the player's ped ID
---@return integer
local function GetPed() local function GetPed()
return PlayerPedId() return PlayerPedId()
end end
--- Get the vehicle the player is in, if any
---@return integer | nil
local function GetVehicle() local function GetVehicle()
local ped = Cache.Get("Ped") -- Use cached ped for efficiency local ped = Cache.Get("Ped") -- Use cached ped for efficiency
if not ped then return end -- Or handle error/default case if not ped then return end -- Or handle error/default case
return GetVehiclePedIsIn(ped, false) return GetVehiclePedIsIn(ped, false)
end end
--- Get the seat of the player in the vehicle if the vehicle is occupied
---@return integer | nil
local function GetVehicleSeat() local function GetVehicleSeat()
local vehicle = Cache.Get("Vehicle") local vehicle = Cache.Get("Vehicle")
if not vehicle then return end if not vehicle then return end
@@ -22,15 +38,26 @@ local function GetVehicleSeat()
end end
end end
---Get The Server ID of the player
---@return integer | nil
local 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
local function GetWeapon() local function GetWeapon()
local ped = Cache.Get("Ped") local ped = Cache.Get("Ped")
if not ped then return end -- Return unarmed hash if no ped if not ped then return end -- Return unarmed hash if no ped
return GetSelectedPedWeapon(ped) return GetSelectedPedWeapon(ped)
end end
Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed) Cache.Create("Ped", GetPed, 1000) -- Check ped every second (adjust as needed)
Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms Cache.Create("Vehicle", GetVehicle, 500) -- Check vehicle every 500ms
Cache.Create("Seat", GetVehicleSeat, 500) -- Check if in 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("Weapon", GetWeapon, 250) -- Check weapon every 250ms
Cache.Create("ServerId", GetServerId, 1000) -- Check server ID every second
return Cache return Cache
+63 -16
View File
@@ -1,8 +1,20 @@
local Cache = {} local Cache = {}
local Config = require("lib/settings/clientConfig.lua")
local max = 5000
local CreateThread = CreateThread
local Wait = Wait
local GetGameTimer = GetGameTimer
Cache.Caches = Cache.Caches or {} Cache.Caches = Cache.Caches or {}
Cache.LoopRunning = Cache.LoopRunning or false Cache.LoopRunning = Cache.LoopRunning or false
local max = 5000 local function print(...)
if Config.Debug then
print("^2[Cache]^0", ...)
end
end
local function StartLoop() local function StartLoop()
if Cache.LoopRunning then return end if Cache.LoopRunning then return end
Cache.LoopRunning = true Cache.LoopRunning = true
@@ -44,30 +56,65 @@ local function StartLoop()
end end
function Cache.Create(name, compare, waitTime) function Cache.Create(name, compare, waitTime)
Cache.Caches[name] = Cache.Caches[name] or {} assert(name, "Cache name is required.")
Cache.Caches[name].WaitTime = waitTime or max assert(compare, "Comparison function is required.")
Cache.Caches[name].Compare = compare assert(type(compare) == "function", "Comparison function must be a function.")
Cache.Caches[name].OnChange = Cache.Caches[name].OnChange or {} local _name = tostring(name) -- Ensure name is a string
Cache.Caches[name].Value = compare() local cache = Cache.Caches[_name]
print("Cache created: " .. name .. " with initial value: " .. tostring(Cache.Caches[name].Value)) if cache and cache.Compare == compare then
for _, onChange in pairs(Cache.Caches[name].OnChange) do print(name .. " already exists with the same comparison function.")
onChange(Cache.Caches[name].Value, nil) return cache
end end
print("Cache created: " .. name .. " with initial value: " .. tostring(Cache.Caches[name].Value)) cache = nil -- clean variable, so we can use the same name for the new cache
local s, r = pcall(function() -- Try to create the cache and catch any errors
local _cache <const> = {
Name = _name,
Compare = compare,
WaitTime = waitTime or max,
LastChecked = nil,
OnChange = {},
Value = compare()
}
Cache.Caches[_name] = _cache
print(_name .. " created with initial value: " .. tostring(Cache.Caches[_name].Value))
for _, onChange in pairs(_cache.OnChange) do
onChange(_cache.Value, nil)
end
end)
if not s then
print("Error creating cache '" .. _name .. "': " .. tostring(r))
return nil
end
return StartLoop() return StartLoop()
end end
function Cache.Get(name) function Cache.Get(name)
local cache = Cache.Caches[name] assert(name, "Cache name is required.")
local _name = tostring(name)
local cache = Cache.Caches[_name]
return cache and cache.Value or nil return cache and cache.Value or nil
end end
function Cache.OnChange(name, onChange) function Cache.OnChange(name, onChange)
local cache = Cache.Caches[name] assert(name, "Cache name is required.")
assert(cache, "Cache with name '" .. name .. "' does not exist.") local _name = tostring(name) -- Ensure name is a string
table.insert(cache.OnChange, onChange) local cache = Cache.Caches[_name]
assert(cache, "Cache with name '" .. _name .. "' does not exist.")
cache.OnChange[#cache.OnChange + 1] = onChange
end
function Cache.Remove(name)
assert(name, "Cache name is required.")
local _name = tostring(name) -- Ensure name is a string
local cache = Cache.Caches[_name]
if cache then
Cache.Caches[_name] = nil
print(_name .. " removed from cache.")
if next(Cache.Caches) == nil then
Cache.LoopRunning = false -- Stop the loop if no caches are left
end
end
end end
return Cache return Cache
+98 -10
View File
@@ -1,6 +1,39 @@
Marker = {} Marker = {
}
local Created = setmetatable({}, { __mode = "k" })
local id = Require("lib/utility/shared/ids")
--- This will validate the marker data.
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
--- @return boolean
local function validateMarkerData(data)
if not data.position or not data.position.x or not data.position.y or not data.position.z then
print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.")
return false
end
if data.offset and (not data.offset.x or not data.offset.y or not data.offset.z) then
print("Invalid marker offset. Must be a vector3 with x, y, and z coordinates.")
return false
end
if data.rotation and (not data.rotation.x or not data.rotation.y or not data.rotation.z) then
print("Invalid marker rotation. Must be a vector3 with x, y, and z coordinates.")
return false
end
return true
end
AddEventHandler("community_bridge:client:marker", function(data)
if not validateMarkerData(data) then return end
if source == "" then return end
Marker.DrawMarker(data)
end)
--- This will create a marker.
--- @param data table{position: vector3, offset: vector3, rotation: vector3, size: vector3, color: vector3, alpha: number, bobUpAndDown: boolean, marker: number, interaction: function}
---@return number
function Marker.DrawMarker(data) function Marker.DrawMarker(data)
local _id = data.id or id.Random()
local position = data.position or vector3(0.0, 0.0, 0.0) local position = data.position or vector3(0.0, 0.0, 0.0)
local offset = data.offset or vector3(0.0, 0.0, 0.0) local offset = data.offset or vector3(0.0, 0.0, 0.0)
local marker = data.marker or 1 local marker = data.marker or 1
@@ -10,17 +43,72 @@ function Marker.DrawMarker(data)
local color = data.color or vector3(0, 255, 0) local color = data.color or vector3(0, 255, 0)
local alpha = data.alpha or 255 local alpha = data.alpha or 255
local bobUpAndDown = data.bobUpAndDown local bobUpAndDown = data.bobUpAndDown
DrawMarker( local interaction = data.interaction or false
marker, Created[_id] = {
pos.x, pos.y, pos.z, position = pos,
0.0, 0.0, 0.0, rotation = rotation,
rotation.x, rotation.y, rotation.z, size = size,
size.x, size.y, size.z, color = color,
color.r, color.g, color.b, alpha, alpha = alpha,
bobUpAndDown, false, false bobUpAndDown =
) bobUpAndDown,
marker = marker,
offset = offset,
interaction = interaction,
id = _id,
}
return _id
end end
function Marker.RemoveMarker(id)
if Created[id] then
Created[id] = nil
return true
end
return false
end
function Marker.Draw()
while true do
Wait(0)
if not next(Created) then
Wait(1000) -- Reduce CPU usage when no markers are present
goto continue
end
for id, _ in pairs(Created) do
if Created[id] then
local data = Created[id]
if #(data.position - GetEntityCoords(PlayerPedId())) > 100.0 then
goto continue
else
DrawMarker(
data.marker,
data.position.x, data.position.y, data.position.z,
0.0, 0.0, 0.0,
data.rotation.x, data.rotation.y, data.rotation.z,
data.size.x, data.size.y, data.size.z,
data.color.x, data.color.y, data.color.z, data.alpha,
data.bobUpAndDown, false, false
)
if data.interaction then
local playerCoords = GetEntityCoords(PlayerPedId())
local distance = #(data.position - playerCoords)
if distance < 2.0 then
if IsControlJustReleased(0, 38) then -- E key
data.interaction(data.id)
end
end
end
end
end
end
::continue::
end
end
Marker.Draw() -- Start the marker drawing loop
exports("Marker", Marker) exports("Marker", Marker)
return Marker return Marker
+24
View File
@@ -0,0 +1,24 @@
local function RegisterNewMarker(data)
if not data.position or not data.position.x or not data.position.y or not data.position.z then
print("Invalid marker position. Must be a vector3 with x, y, and z coordinates.")
return
end
if data.offset and (not data.offset.x or not data.offset.y or not data.offset.z) then
print("Invalid marker offset. Must be a vector3 with x, y, and z coordinates.")
return
end
if data.rotation and (not data.rotation.x or not data.rotation.y or not data.rotation.z) then
print("Invalid marker rotation. Must be a vector3 with x, y, and z coordinates.")
return
end
if not data.size or not data.size.x or not data.size.y or not data.size.z then
print("Invalid marker size. Must be a vector3 with x, y, and z dimensions.")
return
end
TriggerClientEvent("community_bridge:client:marker", source, data)
end
RegisterNetEvent("community_bridge:server:createMarker", RegisterNewMarker)
exports("RegisterNewMarker", RegisterNewMarker)
+3 -1
View File
@@ -2,6 +2,8 @@ SQL = {}
Require("lib/MySQL.lua", "oxmysql") Require("lib/MySQL.lua", "oxmysql")
function SQL.Create(tableName, columns) function SQL.Create(tableName, columns)
assert(MySQL, "Tried using module SQL without MySQL being loaded") assert(MySQL, "Tried using module SQL without MySQL being loaded")
local columnsList = {} local columnsList = {}
@@ -26,7 +28,7 @@ function SQL.InsertOrUpdate(tableName, data)
for column, value in pairs(data) do for column, value in pairs(data) do
table.insert(columns, column) table.insert(columns, column)
table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted
table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update
end end
+190 -151
View File
@@ -1,80 +1,163 @@
---@class Utility
Utility = Utility or {} Utility = Utility or {}
local blipIDs = {} local blipIDs = {}
local spawnedPeds = {} local spawnedPeds = {}
---commentThis will create a prop with the passed model string at the coords and heading specified optionally networked or not. -- === Local Helpers ===
---@param model string | number
---@param coords table ---Get the hash of a model (string or number)
---@param model string|number
---@return number
local function getModelHash(model)
if type(model) ~= 'number' then
return joaat(model)
end
return model
end
---Ensure a model is loaded into memory
---@param model string|number
---@return boolean, number
local function ensureModelLoaded(model)
local hash = getModelHash(model)
if not IsModelValid(hash) and not IsModelInCdimage(hash) then return false, hash end
RequestModel(hash)
local count = 0
while not HasModelLoaded(hash) and count < 30000 do
Wait(0)
count = count + 1
end
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
---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
---@param heading number ---@param heading number
---@param networked boolean ---@param networked boolean
---@return number | nil ---@return number|nil
Utility.CreateProp = function(model, coords, heading, networked) function Utility.CreateProp(model, coords, heading, networked)
Utility.LoadModel(model) local loaded, hash = ensureModelLoaded(model)
if not HasModelLoaded(model) then return nil, Prints.Error("Model Has Not Loaded") end if not loaded then return nil, Prints and Prints.Error and Prints.Error("Model Has Not Loaded") end
local propEntity = CreateObject(model, coords.x, coords.y, coords.z, networked, false, false) local propEntity = CreateObject(hash, coords.x, coords.y, coords.z, networked, false, false)
SetEntityHeading(propEntity, heading) SetEntityHeading(propEntity, heading)
SetModelAsNoLongerNeeded(model) SetModelAsNoLongerNeeded(hash)
return propEntity return propEntity
end end
---This will get the street name and crossing name at the specified coordinates. ---Get street and crossing names at given coordinates
---@param coords table ---@param coords vector3
---@return string ---@return string, string
---@return string function Utility.GetStreetNameAtCoords(coords)
Utility.GetStreetNameAtCoords = function(coords)
local streetHash, crossingHash = GetStreetNameAtCoord(coords.x, coords.y, coords.z) local streetHash, crossingHash = GetStreetNameAtCoord(coords.x, coords.y, coords.z)
local streetName = GetStreetNameFromHashKey(streetHash) return GetStreetNameFromHashKey(streetHash), GetStreetNameFromHashKey(crossingHash)
local crossingName = GetStreetNameFromHashKey(crossingHash)
return streetName, crossingName
end end
---This will create a vehicle with the passed model string at the coords and heading specified. ---Create a vehicle with the given model and coordinates
---@param model string ---@param model string|number
---@param coords table ---@param coords vector3
---@param heading number ---@param heading number
---@param networked boolean ---@param networked boolean
---@return number| nil ---@return number|nil, table
---@return table function Utility.CreateVehicle(model, coords, heading, networked)
Utility.CreateVehicle = function(model, coords, heading, networked) local loaded, hash = ensureModelLoaded(model)
Utility.LoadModel(model) if not loaded then return nil, {}, Prints and Prints.Error and Prints.Error("Model Has Not Loaded") end
if not HasModelLoaded(model) then return nil, {}, Prints.Error("Model Has Not Loaded") end local vehicle = CreateVehicle(hash, coords.x, coords.y, coords.z, heading, networked, false)
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, networked, false)
SetVehicleHasBeenOwnedByPlayer(vehicle, true) SetVehicleHasBeenOwnedByPlayer(vehicle, true)
SetVehicleNeedsToBeHotwired(vehicle, false) SetVehicleNeedsToBeHotwired(vehicle, false)
SetVehRadioStation(vehicle, "OFF") SetVehRadioStation(vehicle, "OFF")
SetModelAsNoLongerNeeded(model) 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 end
---This will create a ped with the passed model string at the coords and heading specified. ---Create a ped with the given model and coordinates
---@param model string ---@param model string|number
---@param coords table ---@param coords vector3
---@param heading number ---@param heading number
---@param networked boolean ---@param networked boolean
---@return number| nil ---@param settings table|nil
Utility.CreatePed = function(model, coords, heading, networked, settings) ---@return number|nil
Utility.LoadModel(model) function Utility.CreatePed(model, coords, heading, networked, settings)
if not HasModelLoaded(model) then return nil, Prints.Error("Model Has Not Loaded") end local loaded, hash = ensureModelLoaded(model)
local spawnedEntity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, networked, false) if not loaded then return nil, Prints and Prints.Error and Prints.Error("Model Has Not Loaded") end
SetModelAsNoLongerNeeded(model) local spawnedEntity = CreatePed(0, hash, coords.x, coords.y, coords.z, heading, networked, false)
SetModelAsNoLongerNeeded(hash)
table.insert(spawnedPeds, spawnedEntity) table.insert(spawnedPeds, spawnedEntity)
return spawnedEntity return spawnedEntity
end end
---This will display a busy spinner with the passed text. ---Show a busy spinner with the given text
---@param text string ---@param text string
---@return boolean ---@return boolean
Utility.StartBusySpinner = function(text) function Utility.StartBusySpinner(text)
AddTextEntry(text, text) safeAddTextEntry(text)
BeginTextCommandBusyString(text) BeginTextCommandBusyString(text)
AddTextComponentSubstringPlayerName(text) AddTextComponentSubstringPlayerName(text)
EndTextCommandBusyString(0) EndTextCommandBusyString(0)
return true return true
end end
---This will stop a busy spinner if one is currently active. ---Stop the busy spinner if active
---@return boolean ---@return boolean
Utility.StopBusySpinner = function() function Utility.StopBusySpinner()
if BusyspinnerIsOn() then if BusyspinnerIsOn() then
BusyspinnerOff() BusyspinnerOff()
return true return true
@@ -82,64 +165,38 @@ Utility.StopBusySpinner = function()
return false return false
end end
---comment Creates a blip at the specified coordinates with the specified parameters. If sprite/color/scale/label are not provided, default values will be used. ---Create a blip at the given coordinates
---@param coords table ---@param coords vector3
---@param sprite number ---@param sprite number
---@param color number ---@param color number
---@param scale number ---@param scale number
---@param label string ---@param label string
---@param shortRange boolean ---@param shortRange boolean
---@param displayType number ---@param displayType number
---@return integer ---@return number
Utility.CreateBlip = function(coords, sprite, color, scale, label, shortRange, displayType) function Utility.CreateBlip(coords, sprite, color, scale, label, shortRange, displayType)
local blip = AddBlipForCoord(coords.x, coords.y, coords.z) return safeAddBlip(coords, sprite, color, scale, label, shortRange, displayType)
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)
table.insert(blipIDs, blip)
return blip
end end
---This will remove a blip if it exists in the blipIDs table. ---Remove a blip if it exists
---@param blip number ---@param blip number
---@return boolean ---@return boolean
Utility.RemoveBlip = function(blip) function Utility.RemoveBlip(blip)
local success = false return safeRemoveBlip(blip)
for i, storedBlip in ipairs(blipIDs) do
if storedBlip == blip then
RemoveBlip(storedBlip)
table.remove(blipIDs, i)
success = true
break
end
end
return success
end end
---Loads a model into memory. If the model is not valid or not in the game files, it will return false. ---Load a model into memory
---@param model string | number ---@param model string|number
---@return boolean ---@return boolean
Utility.LoadModel = function(model) function Utility.LoadModel(model)
if type(model) ~= 'number' then model = joaat(model) end -- Use GetHashKey instead of joaat for client local loaded = ensureModelLoaded(model)
if not IsModelValid(model) and not IsModelInCdimage(model) then return false end return loaded
RequestModel(model)
local count = 0
while not HasModelLoaded(model) and count < 30000 do
Wait(0)
count = count + 1
end
return HasModelLoaded(model)
end end
---This function will request an animation dictionary and wait until it is loaded. If the dictionary is not valid, it will return false. ---Request an animation dictionary
---@param dict string ---@param dict string
---@return boolean ---@return boolean
Utility.RequestAnimDict = function(dict) function Utility.RequestAnimDict(dict)
RequestAnimDict(dict) RequestAnimDict(dict)
local count = 0 local count = 0
while not HasAnimDictLoaded(dict) and count < 30000 do while not HasAnimDictLoaded(dict) and count < 30000 do
@@ -149,10 +206,10 @@ Utility.RequestAnimDict = function(dict)
return HasAnimDictLoaded(dict) return HasAnimDictLoaded(dict)
end end
---This will remove a ped if it exists in the spawnedPeds table. It will also delete the entity if it exists. ---Remove a ped if it exists
---@param entity number ---@param entity number
---@return boolean ---@return boolean
Utility.RemovePed = function(entity) function Utility.RemovePed(entity)
local success = false local success = false
if DoesEntityExist(entity) then if DoesEntityExist(entity) then
DeleteEntity(entity) DeleteEntity(entity)
@@ -167,45 +224,44 @@ Utility.RemovePed = function(entity)
return success return success
end end
---This will use a native text input menu to allow the user to enter text. It will return the entered text or false if cancelled. ---Show a native input menu and return the result
---@param text string ---@param text string
---@param length number ---@param length number
---@return string ---@return string|boolean
Utility.NativeInputMenu = function(text, length) function Utility.NativeInputMenu(text, length)
local maxLength = Math.Clamp(length, 1, 50) local maxLength = Math and Math.Clamp and Math.Clamp(length, 1, 50) or math.min(math.max(length or 10, 1), 50)
local menutText = text or 'enter text' local menuText = text or 'enter text'
AddTextEntry(menutText, menutText) safeAddTextEntry(menuText)
DisplayOnscreenKeyboard(1, menutText, "", "", "", "", "", maxLength) DisplayOnscreenKeyboard(1, menuText, "", "", "", "", "", maxLength)
while(UpdateOnscreenKeyboard() == 0) do while (UpdateOnscreenKeyboard() == 0) do
DisableAllControlActions(0) DisableAllControlActions(0)
Wait(0) Wait(0)
end end
if(GetOnscreenKeyboardResult()) then if (GetOnscreenKeyboardResult()) then
local result = GetOnscreenKeyboardResult() return GetOnscreenKeyboardResult()
return result
end end
return false return false
end end
---This will get the current skin data of the entity passed. It will return a table with the clothing and props data. ---Get the skin data of a ped
---@param entity number ---@param entity number
---@return table ---@return table
Utility.GetEntitySkinData = function(entity) function Utility.GetEntitySkinData(entity)
local skinData = {} local skinData = { clothing = {}, props = {} }
for i = 0, 11 do for i = 0, 11 do
skinData.clothing[i] = {GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i)} skinData.clothing[i] = { GetPedDrawableVariation(entity, i), GetPedTextureVariation(entity, i) }
end end
for i = 0, 13 do for i = 0, 13 do
skinData.props[i] = {GetPedPropIndex(entity, i), GetPedPropTextureIndex(entity, i)} skinData.props[i] = { GetPedPropIndex(entity, i), GetPedPropTextureIndex(entity, i) }
end end
return skinData return skinData
end end
---This will set the skin data of the entity passed. It will set the clothing and props data from the skinData table. ---Apply skin data to a ped
---@param entity number ---@param entity number
---@param skinData table ---@param skinData table
---@return boolean ---@return boolean
Utility.SetEntitySkinData = function(entity, skinData) function Utility.SetEntitySkinData(entity, skinData)
for i = 0, 11 do for i = 0, 11 do
SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0) SetPedComponentVariation(entity, i, skinData.clothing[i][1], skinData.clothing[i][2], 0)
end end
@@ -215,9 +271,9 @@ Utility.SetEntitySkinData = function(entity, skinData)
return true return true
end end
---This will reload the skin data of the entity passed. It will set the clothing and props data from the skinData table and delete any attached objects. ---Reload the player's skin and remove attached objects
---@return boolean ---@return boolean
Utility.ReloadSkin = function() function Utility.ReloadSkin()
local skinData = Utility.GetEntitySkinData(cache.ped) local skinData = Utility.GetEntitySkinData(cache.ped)
Utility.SetEntitySkinData(cache.ped, skinData) Utility.SetEntitySkinData(cache.ped, skinData)
for _, props in pairs(GetGamePool("CObject")) do for _, props in pairs(GetGamePool("CObject")) do
@@ -230,20 +286,20 @@ Utility.ReloadSkin = function()
return true return true
end end
---This will display a native help text on the screen. It will add a text entry and display it for the specified duration. ---Show a native help text
---@param text string ---@param text string
---@param duration number ---@param duration number
Utility.HelpText = function(text, duration) function Utility.HelpText(text, duration)
AddTextEntry(text, text) safeAddTextEntry(text)
BeginTextCommandDisplayHelp(text) BeginTextCommandDisplayHelp(text)
EndTextCommandDisplayHelp(0, false, true, duration or 5000) EndTextCommandDisplayHelp(0, false, true, duration or 5000)
end end
---This will display 3D help text at the specified coordinates. ---Draw 3D help text in the world
---@param coords table ---@param coords vector3
---@param text string ---@param text string
---@param scale number ---@param scale number
Utility.Draw3DHelpText = function(coords, text, scale) function Utility.Draw3DHelpText(coords, text, scale)
local onScreen, x, y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) local onScreen, x, y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z)
if onScreen then if onScreen then
SetTextScale(scale or 0.35, scale or 0.35) SetTextScale(scale or 0.35, scale or 0.35)
@@ -259,19 +315,19 @@ Utility.Draw3DHelpText = function(coords, text, scale)
end end
end end
---This will display a native help text on the screen. It will add a text entry and display it for the specified duration. ---Show a native notification
---@param text string ---@param text string
Utility.NotifyText = function(text) function Utility.NotifyText(text)
AddTextEntry(text, text) safeAddTextEntry(text)
SetNotificationTextEntry(text) SetNotificationTextEntry(text)
DrawNotification(false, true) DrawNotification(false, true)
end end
---This will teleport a player to the specified coordinates. If a condition function is passed it will verify that condition is met and then it will fade the screen out and in, freeze the player during the teleport to allow for collisions to load, and call the afterTeleportFunction if provided. ---Teleport the player to given coordinates
---@param coords table ---@param coords vector3
---@param conditionFunction function | optional ---@param conditionFunction function|nil
---@param afterTeleportFunction function | optional ---@param afterTeleportFunction function|nil
Utility.TeleportPlayer = function(coords, conditionFunction, afterTeleportFunction) function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction)
if conditionFunction ~= nil then if conditionFunction ~= nil then
if not conditionFunction() then if not conditionFunction() then
return return
@@ -297,22 +353,19 @@ Utility.TeleportPlayer = function(coords, conditionFunction, afterTeleportFuncti
end end
end end
---This will get a model hash from a string or number. ---Get the hash from a model
---@param model string | number ---@param model string|number
---@return number ---@return number
Utility.GetEntityHashFromModel = function(model) function Utility.GetEntityHashFromModel(model)
if type(model) ~= 'number' then model = joaat(model) end -- Use GetHashKey instead of joaat for client return getModelHash(model)
return model
end end
---commentThis will get the closest player, the distance to that player from the coords and the server ID of that player. ---Get the closest player to given coordinates
---@param coords table ---@param coords vector3|nil
---@param distanceScope number ---@param distanceScope number|nil
---@param includeMe boolean ---@param includeMe boolean|nil
---@return integer ---@return number, number, number
---@return integer function Utility.GetClosestPlayer(coords, distanceScope, includeMe)
---@return integer
Utility.GetClosestPlayer = function(coords, distanceScope, includeMe)
local players = GetActivePlayers() local players = GetActivePlayers()
local closestPlayer = 0 local closestPlayer = 0
local selfPed = cache.ped local selfPed = cache.ped
@@ -334,33 +387,20 @@ Utility.GetClosestPlayer = function(coords, distanceScope, includeMe)
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer) return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
end end
---This function is is deprecated and will be removed in the future. Please use Pont.Register instead. -- Deprecated point functions (no changes)
---@param pointID string function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
---@param pointCoords table
---@param pointDistance number
---@param _onEnter function
---@param _onExit function
---@param _nearby function
Utility.RegisterPoint = function(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby) return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby)
end end
---This function is is deprecated and will be removed in the future. Please use Point.Get instead. function Utility.GetPointById(pointID)
---@param pointID string
Utility.GetPointById = function(pointID)
return Point.Get(pointID) return Point.Get(pointID)
end end
---This function is is deprecated and will be removed in the future. Please use Point.GetAll instead. function Utility.GetActivePoints()
---@return table | nil
Utility.GetActivePoints = function()
return Point.GetAll() return Point.GetAll()
end end
---This function is is deprecated and will be removed in the future. Please use Point.Remove instead. function Utility.RemovePoint(pointID)
---@param pointID string
---@return nil
Utility.RemovePoint = function(pointID)
return Point.Remove(pointID) return Point.Remove(pointID)
end end
@@ -379,5 +419,4 @@ AddEventHandler('onResourceStop', function(resource)
end) end)
exports('Utility', Utility) exports('Utility', Utility)
return Utility return Utility
+11 -8
View File
@@ -1,9 +1,12 @@
BridgeClientConfig = {} BridgeClientConfig = {}
BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | qb-input ] BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | qb-input ]
BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | qb-menu ] BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | qb-menu ]
BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | progressbar ] BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | progressbar ]
BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem BridgeClientConfig.VehicleKey =
BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ] "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem
BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place BridgeClientConfig.Fuel =
"auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ]
BridgeClientConfig.TargetSystem =
"auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place
BridgeClientConfig.Debug = false
return BridgeClientConfig return BridgeClientConfig