From 2c455cd5b3b7bc57e9f587a5a535cdb1f90b9ecf Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:17:49 -0500 Subject: [PATCH 01/27] feat: switch from utils to lib --- .vscode/settings.json | 4 +- bridge/qb/client/events.lua | 2 +- bridge/qb/client/functions.lua | 284 ++++++++++++++++++++++++++------- bridge/qb/server/functions.lua | 80 ++++++++-- bridge/qb/server/main.lua | 8 +- bridge/qb/shared/main.lua | 51 +++--- client/character.lua | 4 +- client/events.lua | 2 +- client/main.lua | 2 +- config/server.lua | 4 +- fxmanifest.lua | 4 +- server/commands.lua | 12 +- server/events.lua | 8 +- server/main.lua | 2 +- 14 files changed, 349 insertions(+), 118 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5302c7eba..63d1850ef 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,8 @@ "Lua.runtime.nonstandardSymbol": ["/**/", "`", "+=", "-=", "*=", "/="], "Lua.runtime.version": "Lua 5.4", "Lua.diagnostics.globals": [ - "lib" + "lib", + "MySQL", + "cache" ] } \ No newline at end of file diff --git a/bridge/qb/client/events.lua b/bridge/qb/client/events.lua index d99a98086..7f353346e 100644 --- a/bridge/qb/client/events.lua +++ b/bridge/qb/client/events.lua @@ -8,7 +8,7 @@ end) RegisterNetEvent('QBCore:Client:VehicleInfo', function(info) local vehicle = NetworkGetEntityFromNetworkId(info.netId) - local plate = GetPlate(vehicle) + local plate = qbx.getVehiclePlate(vehicle) local hasKeys = config.hasKeys() local data = { diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 138e774ab..ebfa2f3ec 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -11,29 +11,64 @@ function functions.GetPlayerData(cb) cb(QBX.PlayerData) end ----@deprecated use GetCoordsFromEntity from imports/utils.lua -functions.GetCoords = GetCoordsFromEntity +---@deprecated use the GetEntityCoords and GetEntityHeading natives directly +functions.GetCoords = function(entity) -- luacheck: ignore + local coords = GetEntityCoords(entity) + return vec4(coords.x, coords.y, coords.z, GetEntityHeading(entity)) +end ---@deprecated use https://overextended.dev/ox_inventory/Functions/Client#search -functions.HasItem = HasItem +functions.HasItem = function(items, amount) + amount = amount or 1 + local count = exports.ox_inventory:Search('count', items) + if type(items) == 'table' and type(count) == 'table' then + for _, v in pairs(count) do + if v < amount then + return false + end + end + return true + end + return count >= amount +end -- Utility ----@deprecated use DrawText2D from imports/utils.lua +---@deprecated use qbx.drawText2d from modules/lib.lua functions.DrawText = function(x, y, width, height, scale, r, g, b, a, text) - DrawText2D(text, vec2(x, y), width, height, scale, 4, r, g, b, a) + qbx.drawText2d({ + text = text, + coords = vec2(x, y), + scale = scale, + font = 4, + color = vec4(r, g, b, a), + width = width, + height = height, + }) end ----@deprecated use DrawText3D from imports/utils.lua +---@deprecated use qbx.drawText3d from modules/lib.lua functions.DrawText3D = function(x, y, z, text) - DrawText3D(text, vec3(x, y, z), 0.35, 4, 255, 255, 255, 215) + qbx.drawText3d({ + text = text, + coords = vec3(x, y, z), + scale = 0.35, + font = 4, + color = vec4(255, 255, 255, 215) + }) end ---@deprecated use lib.requestAnimDict from ox_lib functions.RequestAnimDict = lib.requestAnimDict ----@deprecated use PlayAnim from imports/utils.lua -functions.PlayAnim = PlayAnim +---@deprecated use lib.requestAnimDict from ox_lib, and the TaskPlayAnim and RemoveAnimDict natives directly +functions.PlayAnim = function(animDict, animName, upperbodyOnly, duration) + local flags = upperbodyOnly and 16 or 0 + local runTime = duration or -1 + lib.requestAnimDict(animDict) + TaskPlayAnim(cache.ped, animDict, animName, 8.0, 3.0, runTime, flags, 0.0, false, false, true) + RemoveAnimDict(animDict) +end ---@deprecated use lib.requestModel from ox_lib functions.LoadModel = lib.requestModel @@ -86,56 +121,97 @@ end -- Getters ----@deprecated use GetVehicles from imports/utils.lua -functions.GetVehicles = GetVehicles +---@deprecated use the GetGamePool('CVehicle') native directly +functions.GetVehicles = function() + GetGamePool('CVehicle') +end ----@deprecated use GetObjects from imports/utils.lua -functions.GetObjects = GetObjects +---@deprecated use the GetGamePool('CObject') native directly +functions.GetObjects = function() + GetGamePool('CObject') +end ----@deprecated use GetPlayersInScope from imports/utils.lua +---@deprecated use the GetPlayersInScope native directly functions.GetPlayers = GetPlayersInScope ----@deprecated use GetPeds from imports/utils.lua -functions.GetPeds = GetPeds +---@deprecated use the GetGamePool('CPed') native directly +functions.GetPeds = function() + GetGamePool('CPed') +end ----@deprecated use GetClosestPed from imports/utils.lua +---@deprecated use lib.getClosestPed from ox_lib ---Use GetClosestPlayer if wanting to ignore non-player peds -functions.GetClosestPed = GetClosestPed +functions.GetClosestPed = lib.getClosestPed ----@deprecated use IsWearingGloves from imports/utils.lua -functions.IsWearingGloves = IsWearingGloves +---@deprecated use qbx.isWearingGloves from modules/lib.lua +functions.IsWearingGloves = qbx.isWearingGloves ----@deprecated use GetClosestPlayer from imports/utils.lua -functions.GetClosestPlayer = GetClosestPlayer +---@deprecated use lib.getClosestPlayer from ox_lib +functions.GetClosestPlayer = lib.getClosestPlayer ----@deprecated use GetPlayersFromCoords from imports/utils.lua -functions.GetPlayersFromCoords = GetPlayersFromCoords +---@deprecated use lib.getNearbyPlayers from ox_lib +functions.GetPlayersFromCoords = lib.getNearbyPlayers ----@deprecated use GetClosestVehicle from imports/utils.lua -functions.GetClosestVehicle = GetClosestVehicle +---@deprecated use lib.getClosestVehicle from ox_lib +functions.GetClosestVehicle = lib.getClosestVehicle ----@deprecated use GetClosestObject from imports/utils.lua -functions.GetClosestObject = GetClosestObject +---@deprecated use lib.getClosestObject from ox_lib +functions.GetClosestObject = lib.getClosestObject ----@deprecated use GetClosestBone from imports/utils.lua -functions.GetClosestBone = GetClosestBone +---@deprecated use the GetWorldPositionOfEntityBone native and calculate distance directly +functions.GetClosestBone = function(entity, list) + local playerCoords = GetEntityCoords(cache.ped) + + ---@type integer | {id: integer} | {id: integer, type: string, name: string}, vector3, number + local bone, coords, distance + for _, element in pairs(list) do + local boneCoords = GetWorldPositionOfEntityBone(entity, element.id or element) + local boneDistance = #(playerCoords - boneCoords) + if not coords or distance > boneDistance then + bone = element + coords = boneCoords + distance = boneDistance + end + end + if not bone then + bone = {id = GetEntityBoneIndexByName(entity, 'bodyshell'), type = 'remains', name = 'bodyshell'} + coords = GetWorldPositionOfEntityBone(entity, bone.id) + distance = #(coords - playerCoords) + end + return bone, coords, distance +end ----@deprecated use GetBoneDistance from imports/utils.lua -functions.GetBoneDistance = GetBoneDistance +---@deprecated use the GetWorldPositionOfEntityBone native and calculate distance directly +functions.GetBoneDistance = function(entity, boneType, bone) + local boneIndex = boneType == 1 and GetPedBoneIndex(entity, bone --[[@as integer]]) or GetEntityBoneIndexByName(entity, bone --[[@as string]]) + local boneCoords = GetWorldPositionOfEntityBone(entity, boneIndex) + local playerCoords = GetEntityCoords(cache.ped) + return #(playerCoords - boneCoords) +end ----@deprecated use AttachProp from imports/utils.lua -functions.AttachProp = AttachProp +---@deprecated use the AttachEntityToEntity native directly +functions.AttachProp = function(ped, model, boneId, x, y, z, xR, yR, zR, vertex) + local modelHash = type(model) == 'string' and joaat(model) or model + local bone = GetPedBoneIndex(ped, boneId) + lib.requestModel(modelHash) + local prop = CreateObject(modelHash, 1.0, 1.0, 1.0, true, true, false) + AttachEntityToEntity(prop, ped, bone, x, y, z, xR, yR, zR, true, true, false, true, not vertex and 2 or 0, true) + SetModelAsNoLongerNeeded(modelHash) + return prop +end -- Vehicle ----@deprecated call server function CreateVehicle instead from imports/utils.lua. +---@deprecated use qbx.spawnVehicle from modules/lib.lua ---@param model string|number ---@param cb? fun(vehicle: number) ---@param coords? vector4 player position if not specified ---@param isnetworked? boolean defaults to true ---@param teleportInto boolean teleport player to driver seat if true function functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto) - coords = type(coords) == 'table' and vec4(coords.x, coords.y, coords.z, coords.w or GetEntityHeading(cache.ped)) or coords or GetCoordsFromEntity(cache.ped) + local playerCoords = GetEntityCoords(cache.ped) + local combinedCoords = vec4(playerCoords.x, playerCoords.y, playerCoords.z, GetEntityHeading(cache.ped)) + coords = type(coords) == 'table' and vec4(coords.x, coords.y, coords.z, coords.w or GetEntityHeading(cache.ped)) or coords or combinedCoords model = type(model) == 'string' and joaat(model) or model if not IsModelInCdimage(model) then return end @@ -153,17 +229,17 @@ function functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto) if cb then cb(veh) end end ----@deprecated use DeleteVehicle from imports/utils.lua -functions.DeleteVehicle = DeleteVehicle +---@deprecated use qbx.deleteVehicle from modules/lib.lua +functions.DeleteVehicle = qbx.deleteVehicle ----@deprecated use GetPlate from imports/utils.lua -functions.GetPlate = GetPlate +---@deprecated use qbx.getVehiclePlate from modules/lib.lua +functions.GetPlate = qbx.getVehiclePlate ----@deprecated use GetVehicleDisplayName from imports/utils.lua -functions.GetVehicleLabel = GetVehicleDisplayName +---@deprecated use qbx.getVehicleDisplayName from modules/lib.lua +functions.GetVehicleLabel = qbx.getVehicleDisplayName ----@deprecated use IsVehicleSpawnClear from imports/utils.lua -functions.SpawnClear = IsVehicleSpawnClear +---@deprecated use lib.getNearbyVehicles from ox_lib +functions.SpawnClear = lib.getNearbyVehicles ---@deprecated use lib.getVehicleProperties from ox_lib function functions.GetVehicleProperties(vehicle) @@ -261,7 +337,6 @@ function functions.SetVehicleProperties(vehicle, props) props.modLightbar = props.modLightbar or props.modKit49 props.modRoofLivery = props.modRoofLivery or props.liveryRoof - --- lib.setVehicleProperties copied and pasted from Overextended below so that we can remove the error so that setting properties is best effort if not DoesEntityExist(vehicle) then error(("Unable to set vehicle properties for '%s' (entity does not exist)"): @@ -621,26 +696,117 @@ end ---@deprecated use lib.requestNamedPtfxAsset from ox_lib functions.LoadParticleDictionary = lib.requestNamedPtfxAsset ----@deprecated use StartParticleAtCoord from imports/utils.lua -functions.StartParticleAtCoord = StartParticleAtCoord +---@deprecated use ParticleFx natives directly +functions.StartParticleAtCoord = function(dict, ptName, looped, coords, rot, scale, alpha, color, duration) -- luacheck: ignore + coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords or GetEntityCoords(cache.ped) + + lib.requestNamedPtfxAsset(dict) + UseParticleFxAssetNextCall(dict) + SetPtfxAssetNextCall(dict) + local particleHandle + if looped then + particleHandle = StartParticleFxLoopedAtCoord(ptName, coords.x, coords.y, coords.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false, false) + if color then + SetParticleFxLoopedColour(particleHandle, color.r, color.g, color.b, false) + end + SetParticleFxLoopedAlpha(particleHandle, alpha or 10.0) + if duration then + Wait(duration) + StopParticleFxLooped(particleHandle, false) + end + else + SetParticleFxNonLoopedAlpha(alpha or 1.0) + if color then + SetParticleFxNonLoopedColour(color.r, color.g, color.b) + end + StartParticleFxNonLoopedAtCoord(ptName, coords.x, coords.y, coords.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false) + end + return particleHandle +end ----@deprecated use StartParticleOnEntity from imports/utils.lua -functions.StartParticleOnEntity = StartParticleOnEntity +---@deprecated use ParticleFx natives directly +functions.StartParticleOnEntity = function(dict, ptName, looped, entity, bone, offset, rot, scale, alpha, color, evolution, duration) -- luacheck: ignore + lib.requestNamedPtfxAsset(dict) + UseParticleFxAssetNextCall(dict) + local particleHandle = nil + ---@cast bone number + local pedBoneIndex = bone and GetPedBoneIndex(entity, bone) or 0 + ---@cast bone string + local nameBoneIndex = bone and GetEntityBoneIndexByName(entity, bone) or 0 + local entityType = GetEntityType(entity) + local boneID = entityType == 1 and (pedBoneIndex ~= 0 and pedBoneIndex) or (looped and nameBoneIndex ~= 0 and nameBoneIndex) + if looped then + if boneID then + particleHandle = StartParticleFxLoopedOnEntityBone(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, boneID, scale or 1.0, false, false, false) + else + particleHandle = StartParticleFxLoopedOnEntity(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false) + end + if evolution then + SetParticleFxLoopedEvolution(particleHandle, evolution.name, evolution.amount, false) + end + if color then + SetParticleFxLoopedColour(particleHandle, color.r, color.g, color.b, false) + end + SetParticleFxLoopedAlpha(particleHandle, alpha or 1.0) + if duration then + Wait(duration) + StopParticleFxLooped(particleHandle, false) + end + else + SetParticleFxNonLoopedAlpha(alpha or 1.0) + if color then + SetParticleFxNonLoopedColour(color.r, color.g, color.b) + end + if boneID then + StartParticleFxNonLoopedOnPedBone(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, boneID, scale or 1.0, false, false, false) + else + StartParticleFxNonLoopedOnEntity(ptName, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale or 1.0, false, false, false) + end + end + return particleHandle +end ----@deprecated use GetStreetNameAtCoords from imports/utils.lua -functions.GetStreetNametAtCoords = GetStreetNameAtCoords +---@deprecated use qbx.getStreetName from modules/lib.lua +functions.GetStreetNametAtCoords = qbx.getStreetName ----@deprecated use GetZoneAtCoords from imports/utils.lua -functions.GetZoneAtCoords = GetZoneAtCoords +---@deprecated use qbx.getZoneName from modules/lib.lua +functions.GetZoneAtCoords = qbx.getZoneName ----@deprecated use GetCardinalDirection from imports/utils.lua -functions.GetCardinalDirection = GetCardinalDirection +---@deprecated use qbx.getCardinalDirection from modules/lib.lua +functions.GetCardinalDirection = qbx.getCardinalDirection ----@deprecated use GetCurrentTime from imports/utils.lua -functions.GetCurrentTime = GetCurrentTime +---@deprecated use the GetClockMinutes and GetClockHours natives and format the output directly +functions.GetCurrentTime = function() + local obj = {} + obj.min = GetClockMinutes() + obj.hour = GetClockHours() ----@deprecated use GetGroundZCoord from imports/utils.lua -functions.GetGroundZCoord = GetGroundZCoord + if obj.hour <= 12 then + obj.ampm = 'AM' + elseif obj.hour >= 13 then + obj.ampm = 'PM' + obj.formattedHour = obj.hour - 12 + end + + if obj.min <= 9 then + obj.formattedMin = ('0%s'):format(obj.min) + end + + return obj +end + +---@deprecated use the GetGroundZFor_3dCoord native directly +functions.GetGroundZCoord = function(coords) + if not coords then return end + + local retval, groundZ = GetGroundZFor_3dCoord(coords.x, coords.y, coords.z, false) + if retval then + return vec3(coords.x, coords.y, groundZ) + end + + lib.print.verbose('Couldn\'t find Ground Z Coordinates given 3D Coordinates:', coords) + return coords +end ---Text box popup for player which dissappears after a set time. ---@param text table|string text of the notification diff --git a/bridge/qb/server/functions.lua b/bridge/qb/server/functions.lua index b29128cc6..8b4cb1a0c 100644 --- a/bridge/qb/server/functions.lua +++ b/bridge/qb/server/functions.lua @@ -4,8 +4,11 @@ local functions = {} local createQbExport = require 'bridge.qb.shared.export-function' ----@deprecated -functions.GetCoords = GetCoordsFromEntity +---@deprecated use the GetEntityCoords and GetEntityHeading natives directly +functions.GetCoords = function(entity) + local coords = GetEntityCoords(entity) + return vec4(coords.x, coords.y, coords.z, GetEntityHeading(entity)) +end ---@deprecated use the native GetPlayerIdentifierByType? functions.GetIdentifier = GetPlayerIdentifierByType @@ -21,7 +24,7 @@ function functions.GetPlayers() return sources end ----@deprecated use SpawnVehicle from imports/utils.lua +---@deprecated use qbx.spawnVehicle from modules/lib.lua ---@return number? function functions.SpawnVehicle(source, model, coords, warp) local ped = GetPlayerPed(source) @@ -40,9 +43,9 @@ function functions.SpawnVehicle(source, model, coords, warp) return veh end ----@deprecated use SpawnVehicle from imports/utils.lua +---@deprecated use qbx.spawnVehicle from modules/lib.lua function functions.CreateVehicle(source, model, _, coords, warp) - local netId = SpawnVehicle(source, model, coords, warp) + local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) return NetworkGetEntityFromNetworkId(netId) end @@ -54,19 +57,72 @@ function functions.UseItem(source, item) exports['qb-inventory']:UseItem(source, item) end ----@deprecated use KickWithReason from imports/utils.lua -functions.Kick = KickWithReason +local discordLink = GetConvar('qbx:discordlink', 'discord.gg/qbox') +---@deprecated use setKickReason or deferrals for connecting players, and the DropPlayer native directly otherwise +functions.Kick = function(source, reason, setKickReason, deferrals) + reason = '\n' .. reason .. '\n🔸 Check our Discord for further information: ' .. discordLink + if setKickReason then + setKickReason(reason) + end + CreateThread(function() + if deferrals then + deferrals.update(reason) + Wait(2500) + end + if source then + DropPlayer(source --[[@as string]], reason) + end + for _ = 0, 4 do + while true do + if source then + if GetPlayerPing(source --[[@as string]]) >= 0 then + break + end + Wait(100) + CreateThread(function() + DropPlayer(source --[[@as string]], reason) + end) + end + end + Wait(5000) + end + end) +end + +---@deprecated check for license usage directly yourself +functions.IsLicenseInUse = function(license) + local players = GetPlayers() ----@deprecated use IsLicenseInUse from imports/utils.lua -functions.IsLicenseInUse = IsLicenseInUse + for _, player in pairs(players) do + local plyLicense2 = GetPlayerIdentifierByType(player --[[@as string]], 'license2') + local plyLicense = GetPlayerIdentifierByType(player --[[@as string]], 'license') + if plyLicense2 == license or plyLicense == license then + return true + end + end + + return false +end -- Utility functions ---@deprecated use https://overextended.dev/ox_inventory/Functions/Server#search -functions.HasItem = HasItem +functions.HasItem = function(source, items, amount) -- luacheck: ignore + amount = amount or 1 + local count = exports.ox_inventory:Search(source, 'count', items) + if type(items) == 'table' and type(count) == 'table' then + for _, v in pairs(count) do + if v < amount then + return false + end + end + return true + end + return count >= amount +end ----@deprecated use GetPlate from imports/utils.lua -functions.GetPlate = GetPlate +---@deprecated use qbx.getVehiclePlate from modules/lib.lua +functions.GetPlate = qbx.getVehiclePlate -- Single add item ---@deprecated incompatible with ox_inventory. Update ox_inventory item config instead. diff --git a/bridge/qb/server/main.lua b/bridge/qb/server/main.lua index 90ca117d6..e31e11ecc 100644 --- a/bridge/qb/server/main.lua +++ b/bridge/qb/server/main.lua @@ -85,15 +85,15 @@ function qbCoreCompat.Functions.TriggerCallback(name, source, cb, ...) qbCoreCompat.ServerCallbacks[name](source, cb, ...) end ----@deprecated call server function SpawnVehicle instead from imports/utils.lua. +---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) - local netId = SpawnVehicle(source, model, coords, warp) + local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) if netId then cb(netId) end end) ----@deprecated call server function SpawnVehicle instead from imports/utils.lua. +---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:CreateVehicle', function(source, cb, model, coords, warp) - local netId = SpawnVehicle(source, model, coords, warp) + local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) if netId then cb(netId) end end) diff --git a/bridge/qb/shared/main.lua b/bridge/qb/shared/main.lua index 108b3d19e..c6940b359 100644 --- a/bridge/qb/shared/main.lua +++ b/bridge/qb/shared/main.lua @@ -1,36 +1,43 @@ local qbShared = require 'shared.main' ----@deprecated use CommaValue from imports/utils.lua -qbShared.CommaValue = CommaValue +---@deprecated use lib.math.groupdigits from ox_lib +qbShared.CommaValue = lib.math.groupdigits ----@deprecated use RandomLetter from imports/utils.lua -qbShared.RandomStr = RandomLetter +---@deprecated use lib.string.random from ox_lib +qbShared.RandomStr = function(length) + if length <= 0 then return '' end + local pattern = math.random(2) == 1 and 'a' or 'A' + return qbShared.RandomStr(length - 1) .. lib.string.random(pattern) +end ----@deprecated use RandomNumber from imports/utils.lua -qbShared.RandomInt = RandomNumber +---@deprecated use lib.string.random from ox_lib +qbShared.RandomInt = function(length) + if length <= 0 then return '' end + return qbShared.RandomInt(length - 1) .. lib.string.random('1') +end ----@deprecated use string.split from imports/utils.lua -qbShared.SplitStr = string.split +---@deprecated use string.strsplit with CfxLua 5.4 +qbShared.SplitStr = string.strsplit ----@deprecated use string.trim from imports/utils.lua -qbShared.Trim = string.trim +---@deprecated use qbx.string.trim from modules/lib.lua +qbShared.Trim = qbx.string.trim ----@deprecated use string.firstToUpper from imports/utils.lua -qbShared.FirstToUpper = string.firstToUpper +---@deprecated use qbx.string.capitalize from modules/lib.lua +qbShared.FirstToUpper = qbx.string.capitalize ----@deprecated use math.round from imports/utils.lua -qbShared.Round = math.round +---@deprecated use qbx.math.round from modules/lib.lua +qbShared.Round = qbx.math.round ----@deprecated use ChangeVehicleExtra from imports/utils.lua -qbShared.ChangeVehicleExtra = ChangeVehicleExtra +---@deprecated use qbx.setVehicleExtra from modules/lib.lua +qbShared.ChangeVehicleExtra = qbx.setVehicleExtras ----@deprecated use SetVehicleExtras from imports/utils.lua -qbShared.SetDefaultVehicleExtras = SetVehicleExtras +---@deprecated use qbx.setVehicleExtra from modules/lib.lua +qbShared.SetDefaultVehicleExtras = qbx.setVehicleExtras ----@deprecated use MaleNoGloves from imports/utils.lua -qbShared.MaleNoGloves = MaleNoGloves +---@deprecated use qbx.armsWithoutGloves.male from modules/lib.lua +qbShared.MaleNoGloves = qbx.armsWithoutGloves.male ----@deprecated use FemaleNoGloves from imports/utils.lua -qbShared.FemaleNoGloves = FemaleNoGloves +---@deprecated use qbx.armsWithoutGloves.female from modules/lib.lua +qbShared.FemaleNoGloves = qbx.armsWithoutGloves.female return qbShared \ No newline at end of file diff --git a/client/character.lua b/client/character.lua index 9c620b4cb..ffb3618c5 100644 --- a/client/character.lua +++ b/client/character.lua @@ -287,8 +287,8 @@ local function chooseCharacter() Birthdate = character.charinfo.birthdate, Nationality = character.charinfo.nationality, ['Account Number'] = character.charinfo.account, - Bank = CommaValue(character.money.bank), - Cash = CommaValue(character.money.cash), + Bank = lib.math.groupdigits(character.money.bank), + Cash = lib.math.groupdigits(character.money.cash), Job = character.job.label, ['Job Grade'] = character.job.grade.name, Gang = character.gang.label, diff --git a/client/events.lua b/client/events.lua index 815359354..2a9323215 100644 --- a/client/events.lua +++ b/client/events.lua @@ -181,7 +181,7 @@ AddStateBagChangeHandler('me', nil, function(bagName, _, value) local displayTime = 5000 + GetGameTimer() while displayTime > GetGameTimer() do playerPed = isLocalPlayer and cache.ped or GetPlayerPed(playerId) - DrawText3D(value, GetEntityCoords(playerPed)) + qbx.drawText3d({text = value, coords = GetEntityCoords(playerPed)}) Wait(0) end end) diff --git a/client/main.lua b/client/main.lua index a659635f7..e92383f3e 100644 --- a/client/main.lua +++ b/client/main.lua @@ -33,7 +33,7 @@ exports('GetVehiclesByHash', GetVehiclesByHash) ---@return table function GetVehiclesByCategory() - return MapTableBySubfield('category', QBX.Shared.Vehicles) + return qbx.table.mapBySubfield(QBX.Shared.Vehicles, 'category') end exports('GetVehiclesByCategory', GetVehiclesByCategory) diff --git a/config/server.lua b/config/server.lua index a33e93e5d..aa5bd847c 100644 --- a/config/server.lua +++ b/config/server.lua @@ -25,7 +25,7 @@ return { identifierTypes = { citizenid = { valueFunction = function() - return tostring(RandomLetter(3) .. RandomNumber(5)):upper() + return tostring(lib.string.random('A', 3) .. lib.string.random(1, 2)) end, }, AccountNumber = { @@ -40,7 +40,7 @@ return { }, FingerId = { valueFunction = function() - return tostring(RandomLetter(2) .. RandomNumber(3) .. RandomLetter(1) .. RandomNumber(2) .. RandomLetter(3) .. RandomNumber(4)) + return tostring(lib.string.random(1, 2) .. lib.string.random(1, 3) .. lib.string.random(1, 1) .. lib.string.random(1, 2) .. lib.string.random(1, 3) .. lib.string.random(1, 4)) end, }, WalletId = { diff --git a/fxmanifest.lua b/fxmanifest.lua index f6e15feae..b6d3ac665 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,14 +7,14 @@ version '1.4.0' shared_scripts { '@ox_lib/init.lua', - 'modules/utils.lua', + 'modules/lib.lua', 'shared/locale.lua', 'locale/en.lua', 'locale/*.lua', } client_scripts { - 'modules/utils.lua', + 'modules/lib.lua', 'client/main.lua', 'client/functions.lua', 'client/loops.lua', diff --git a/server/commands.lua b/server/commands.lua index 39f32e955..131b80a40 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -102,7 +102,7 @@ lib.addCommand('openserver', { config.server.closed = false Notify(source, Lang:t('success.server_opened'), 'success') else - KickWithReason(source, Lang:t("error.no_permission"), nil, nil) + DropPlayer(source, Lang:t("error.no_permission")) end end) @@ -123,12 +123,12 @@ lib.addCommand('closeserver', { config.server.closedReason = reason for k in pairs(QBX.Players) do if not HasPermission(k, config.server.whitelistPermission) then - KickWithReason(k, reason, nil, nil) + DropPlayer(k, reason) end end Notify(source, Lang:t('success.server_closed'), 'success') else - KickWithReason(source, Lang:t("error.no_permission"), nil, nil) + DropPlayer(source, Lang:t("error.no_permission")) end end) @@ -142,8 +142,8 @@ lib.addCommand('car', { restricted = "group.admin" }, function(source, args) if not args then return end - local netId = SpawnVehicle(source, args[Lang:t("command.car.params.model.name")], nil, true) - local plate = GetPlate(NetworkGetEntityFromNetworkId(netId)) + local netId = qbx.spawnVehicle({spawnSource = source, model = args[Lang:t("command.car.params.model.name")], warp = true}) + local plate = qbx.getVehiclePlate(NetworkGetEntityFromNetworkId(netId)) config.giveVehicleKeys(source, plate) end) @@ -326,7 +326,7 @@ end) -- ID command lib.addCommand('id', {help = Lang:t('info.check_id')}, function(source) - exports.qbx_core:Notify(source, 'ID: ' .. source) + Notify(source, 'ID: ' .. source) end) -- Character commands diff --git a/server/events.lua b/server/events.lua index bee9c8ed3..097706c4e 100644 --- a/server/events.lua +++ b/server/events.lua @@ -77,7 +77,7 @@ local function onPlayerConnecting(name, _, deferrals) if not license then deferrals.done(Lang:t('error.no_valid_license')) - elseif serverConfig.checkDuplicateLicense and IsLicenseInUse(license) then + elseif serverConfig.checkDuplicateLicense and usedLicenses[license] then deferrals.done(Lang:t('error.duplicate_license')) end @@ -166,11 +166,11 @@ RegisterNetEvent('QBCore:Server:CloseServer', function(reason) serverConfig.closedReason = reason for k in pairs(QBX.Players) do if not HasPermission(k, serverConfig.whitelistPermission) then - KickWithReason(k, reason, nil, nil) + DropPlayer(k, reason) end end else - KickWithReason(src, Lang:t("error.no_permission"), nil, nil) + DropPlayer(src, Lang:t("error.no_permission")) end end) @@ -179,7 +179,7 @@ RegisterNetEvent('QBCore:Server:OpenServer', function() if HasPermission(src, 'admin') then serverConfig.closed = false else - KickWithReason(src, Lang:t("error.no_permission"), nil, nil) + DropPlayer(src, Lang:t("error.no_permission")) end end) diff --git a/server/main.lua b/server/main.lua index d010459cb..7817c91a7 100644 --- a/server/main.lua +++ b/server/main.lua @@ -118,7 +118,7 @@ exports('GetVehiclesByHash', GetVehiclesByHash) ---@return table function GetVehiclesByCategory() - return MapTableBySubfield('category', QBX.Shared.Vehicles) + return qbx.table.mapBySubfield(QBX.Shared.Vehicles, 'category') end exports('GetVehiclesByCategory', GetVehiclesByCategory) From 7c95c7a512b5a0532591b53cc26a1d8fded5456a Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Mon, 15 Jan 2024 21:39:09 -0500 Subject: [PATCH 02/27] fix: armsWithoutGloves issue? --- modules/lib.lua | 161 ++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/modules/lib.lua b/modules/lib.lua index b7efb13b9..3dbe4b28e 100644 --- a/modules/lib.lua +++ b/modules/lib.lua @@ -4,6 +4,7 @@ local qbx = {} qbx.string = {} qbx.math = {} qbx.table = {} +qbx.armsWithoutGloves = {} ---Returns the given string with its trailing whitespaces removed. ---@param str string @@ -335,87 +336,85 @@ else end end - qbx.armsWithoutGloves = lib.table.freeze({ - male = lib.table.freeze({ - [0] = true, - [1] = true, - [2] = true, - [3] = true, - [4] = true, - [5] = true, - [6] = true, - [7] = true, - [8] = true, - [9] = true, - [10] = true, - [11] = true, - [12] = true, - [13] = true, - [14] = true, - [15] = true, - [18] = true, - [26] = true, - [52] = true, - [53] = true, - [54] = true, - [55] = true, - [56] = true, - [57] = true, - [58] = true, - [59] = true, - [60] = true, - [61] = true, - [62] = true, - [112] = true, - [113] = true, - [114] = true, - [118] = true, - [125] = true, - [132] = true - }), - - female = lib.table.freeze({ - [0] = true, - [1] = true, - [2] = true, - [3] = true, - [4] = true, - [5] = true, - [6] = true, - [7] = true, - [8] = true, - [9] = true, - [10] = true, - [11] = true, - [12] = true, - [13] = true, - [14] = true, - [15] = true, - [19] = true, - [59] = true, - [60] = true, - [61] = true, - [62] = true, - [63] = true, - [64] = true, - [65] = true, - [66] = true, - [67] = true, - [68] = true, - [69] = true, - [70] = true, - [71] = true, - [129] = true, - [130] = true, - [131] = true, - [135] = true, - [142] = true, - [149] = true, - [153] = true, - [157] = true, - [161] = true, - [165] = true - }), + qbx.armsWithoutGloves.male = lib.table.freeze({ + [0] = true, + [1] = true, + [2] = true, + [3] = true, + [4] = true, + [5] = true, + [6] = true, + [7] = true, + [8] = true, + [9] = true, + [10] = true, + [11] = true, + [12] = true, + [13] = true, + [14] = true, + [15] = true, + [18] = true, + [26] = true, + [52] = true, + [53] = true, + [54] = true, + [55] = true, + [56] = true, + [57] = true, + [58] = true, + [59] = true, + [60] = true, + [61] = true, + [62] = true, + [112] = true, + [113] = true, + [114] = true, + [118] = true, + [125] = true, + [132] = true + }) + + qbx.armsWithoutGloves.female = lib.table.freeze({ + [0] = true, + [1] = true, + [2] = true, + [3] = true, + [4] = true, + [5] = true, + [6] = true, + [7] = true, + [8] = true, + [9] = true, + [10] = true, + [11] = true, + [12] = true, + [13] = true, + [14] = true, + [15] = true, + [19] = true, + [59] = true, + [60] = true, + [61] = true, + [62] = true, + [63] = true, + [64] = true, + [65] = true, + [66] = true, + [67] = true, + [68] = true, + [69] = true, + [70] = true, + [71] = true, + [129] = true, + [130] = true, + [131] = true, + [135] = true, + [142] = true, + [149] = true, + [153] = true, + [157] = true, + [161] = true, + [165] = true }) ---Returns if the local ped is wearing gloves. From 3e86d1db4ee6df6736193d41da46d9304a19d924 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:30:51 -0500 Subject: [PATCH 03/27] fix: move armsWithoutGloves to shared --- modules/lib.lua | 165 ++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 82 deletions(-) diff --git a/modules/lib.lua b/modules/lib.lua index 3dbe4b28e..bb79af6fc 100644 --- a/modules/lib.lua +++ b/modules/lib.lua @@ -4,7 +4,89 @@ local qbx = {} qbx.string = {} qbx.math = {} qbx.table = {} -qbx.armsWithoutGloves = {} + +qbx.armsWithoutGloves = lib.table.freeze({ + male = lib.table.freeze({ + [0] = true, + [1] = true, + [2] = true, + [3] = true, + [4] = true, + [5] = true, + [6] = true, + [7] = true, + [8] = true, + [9] = true, + [10] = true, + [11] = true, + [12] = true, + [13] = true, + [14] = true, + [15] = true, + [18] = true, + [26] = true, + [52] = true, + [53] = true, + [54] = true, + [55] = true, + [56] = true, + [57] = true, + [58] = true, + [59] = true, + [60] = true, + [61] = true, + [62] = true, + [112] = true, + [113] = true, + [114] = true, + [118] = true, + [125] = true, + [132] = true + }), + + female = lib.table.freeze({ + [0] = true, + [1] = true, + [2] = true, + [3] = true, + [4] = true, + [5] = true, + [6] = true, + [7] = true, + [8] = true, + [9] = true, + [10] = true, + [11] = true, + [12] = true, + [13] = true, + [14] = true, + [15] = true, + [19] = true, + [59] = true, + [60] = true, + [61] = true, + [62] = true, + [63] = true, + [64] = true, + [65] = true, + [66] = true, + [67] = true, + [68] = true, + [69] = true, + [70] = true, + [71] = true, + [129] = true, + [130] = true, + [131] = true, + [135] = true, + [142] = true, + [149] = true, + [153] = true, + [157] = true, + [161] = true, + [165] = true + }), +}) ---Returns the given string with its trailing whitespaces removed. ---@param str string @@ -336,87 +418,6 @@ else end end - qbx.armsWithoutGloves.male = lib.table.freeze({ - [0] = true, - [1] = true, - [2] = true, - [3] = true, - [4] = true, - [5] = true, - [6] = true, - [7] = true, - [8] = true, - [9] = true, - [10] = true, - [11] = true, - [12] = true, - [13] = true, - [14] = true, - [15] = true, - [18] = true, - [26] = true, - [52] = true, - [53] = true, - [54] = true, - [55] = true, - [56] = true, - [57] = true, - [58] = true, - [59] = true, - [60] = true, - [61] = true, - [62] = true, - [112] = true, - [113] = true, - [114] = true, - [118] = true, - [125] = true, - [132] = true - }) - - qbx.armsWithoutGloves.female = lib.table.freeze({ - [0] = true, - [1] = true, - [2] = true, - [3] = true, - [4] = true, - [5] = true, - [6] = true, - [7] = true, - [8] = true, - [9] = true, - [10] = true, - [11] = true, - [12] = true, - [13] = true, - [14] = true, - [15] = true, - [19] = true, - [59] = true, - [60] = true, - [61] = true, - [62] = true, - [63] = true, - [64] = true, - [65] = true, - [66] = true, - [67] = true, - [68] = true, - [69] = true, - [70] = true, - [71] = true, - [129] = true, - [130] = true, - [131] = true, - [135] = true, - [142] = true, - [149] = true, - [153] = true, - [157] = true, - [161] = true, - [165] = true - }) - ---Returns if the local ped is wearing gloves. ---@return boolean function qbx.isWearingGloves() From 22d86da76532728a12e4fe56e4ed7d21a8f84a45 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Tue, 16 Jan 2024 14:43:56 -0500 Subject: [PATCH 04/27] fix: spawnVehicle usage --- bridge/qb/server/functions.lua | 10 +++++++++- bridge/qb/server/main.lua | 20 ++++++++++++++++++-- server/commands.lua | 9 ++++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/bridge/qb/server/functions.lua b/bridge/qb/server/functions.lua index 8b4cb1a0c..8aab2b08c 100644 --- a/bridge/qb/server/functions.lua +++ b/bridge/qb/server/functions.lua @@ -45,7 +45,15 @@ end ---@deprecated use qbx.spawnVehicle from modules/lib.lua function functions.CreateVehicle(source, model, _, coords, warp) - local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) + model = type(model) == 'string' and joaat(model) or (model --[[@as integer]]) + local ped = GetPlayerPed(source) + + local netId = qbx.spawnVehicle({ + model = model, + spawnSource = coords or ped, + warp = warp and ped or nil, + }) + return NetworkGetEntityFromNetworkId(netId) end diff --git a/bridge/qb/server/main.lua b/bridge/qb/server/main.lua index e31e11ecc..e93c05656 100644 --- a/bridge/qb/server/main.lua +++ b/bridge/qb/server/main.lua @@ -87,13 +87,29 @@ end ---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) - local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) + model = type(model) == 'string' and joaat(model) or (model --[[@as integer]]) + local ped = GetPlayerPed(source) + + local netId = qbx.spawnVehicle({ + model = model, + spawnSource = coords or ped, + warp = warp and ped or nil, + }) + if netId then cb(netId) end end) ---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:CreateVehicle', function(source, cb, model, coords, warp) - local netId = qbx.spawnVehicle({spawnSource = source, model = model, coords = coords, warp = warp}) + model = type(model) == 'string' and joaat(model) or (model --[[@as integer]]) + local ped = GetPlayerPed(source) + + local netId = qbx.spawnVehicle({ + model = model, + spawnSource = coords or ped, + warp = warp and ped or nil, + }) + if netId then cb(netId) end end) diff --git a/server/commands.lua b/server/commands.lua index 131b80a40..16336dd5a 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -142,7 +142,14 @@ lib.addCommand('car', { restricted = "group.admin" }, function(source, args) if not args then return end - local netId = qbx.spawnVehicle({spawnSource = source, model = args[Lang:t("command.car.params.model.name")], warp = true}) + local ped = GetPlayerPed(source) + + local netId = qbx.spawnVehicle({ + model = args[Lang:t("command.car.params.model.name")], + spawnSource = ped, + warp = ped, + }) + local plate = qbx.getVehiclePlate(NetworkGetEntityFromNetworkId(netId)) config.giveVehicleKeys(source, plate) end) From e78f6a3187cfaf3e6411fa25186c09e9962f2ca5 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:22:09 -0500 Subject: [PATCH 05/27] fix(config/server): lib.string.random --- config/server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/server.lua b/config/server.lua index aa5bd847c..ad0af505b 100644 --- a/config/server.lua +++ b/config/server.lua @@ -25,7 +25,7 @@ return { identifierTypes = { citizenid = { valueFunction = function() - return tostring(lib.string.random('A', 3) .. lib.string.random(1, 2)) + return tostring(lib.string.random('A', 3) .. lib.string.random('1', 5)) end, }, AccountNumber = { @@ -40,7 +40,7 @@ return { }, FingerId = { valueFunction = function() - return tostring(lib.string.random(1, 2) .. lib.string.random(1, 3) .. lib.string.random(1, 1) .. lib.string.random(1, 2) .. lib.string.random(1, 3) .. lib.string.random(1, 4)) + return tostring(lib.string.random('1', 2) .. lib.string.random('1', 3) .. lib.string.random('1', 1) .. lib.string.random('1', 2) .. lib.string.random('1', 3) .. lib.string.random('1', 4)) end, }, WalletId = { From 254c0260ffd229bf518e02458392d84eaa013825 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:41:54 -0500 Subject: [PATCH 06/27] Update server/commands.lua Co-authored-by: David Malchin --- server/commands.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index 16336dd5a..cb5e39cc6 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -142,12 +142,10 @@ lib.addCommand('car', { restricted = "group.admin" }, function(source, args) if not args then return end - local ped = GetPlayerPed(source) - local netId = qbx.spawnVehicle({ model = args[Lang:t("command.car.params.model.name")], - spawnSource = ped, - warp = ped, + spawnSource = GetPlayerPed(source), + warp = true, }) local plate = qbx.getVehiclePlate(NetworkGetEntityFromNetworkId(netId)) From 7bffe7bc8f3d3a07140360e7e82d49ba093115b6 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:42:33 -0500 Subject: [PATCH 07/27] Update config/server.lua Co-authored-by: David Malchin --- config/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/server.lua b/config/server.lua index ad0af505b..17b2c0897 100644 --- a/config/server.lua +++ b/config/server.lua @@ -25,7 +25,7 @@ return { identifierTypes = { citizenid = { valueFunction = function() - return tostring(lib.string.random('A', 3) .. lib.string.random('1', 5)) + return lib.string.random('........') end, }, AccountNumber = { From bdfd7ccb21634b325f53123e5c975fc35e12c89d Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:42:41 -0500 Subject: [PATCH 08/27] Update config/server.lua Co-authored-by: David Malchin --- config/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/server.lua b/config/server.lua index 17b2c0897..1ed084c74 100644 --- a/config/server.lua +++ b/config/server.lua @@ -40,7 +40,7 @@ return { }, FingerId = { valueFunction = function() - return tostring(lib.string.random('1', 2) .. lib.string.random('1', 3) .. lib.string.random('1', 1) .. lib.string.random('1', 2) .. lib.string.random('1', 3) .. lib.string.random('1', 4)) + return lib.string.random('...............') end, }, WalletId = { From d5a950db502dfe3918d252a5649c34f5eb6a4c21 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:43:03 -0500 Subject: [PATCH 09/27] Update bridge/qb/client/functions.lua Co-authored-by: David Malchin --- bridge/qb/client/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index ebfa2f3ec..ba12305f2 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -769,7 +769,7 @@ end ---@deprecated use qbx.getStreetName from modules/lib.lua functions.GetStreetNametAtCoords = qbx.getStreetName ----@deprecated use qbx.getZoneName from modules/lib.lua +---@deprecated use qbx.getZoneName from modules/lib.lua functions.GetZoneAtCoords = qbx.getZoneName ---@deprecated use qbx.getCardinalDirection from modules/lib.lua From b514110addb47ca4bc94880be07accf8ab797979 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:43:30 -0500 Subject: [PATCH 10/27] Update bridge/qb/server/main.lua Co-authored-by: David Malchin --- bridge/qb/server/main.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bridge/qb/server/main.lua b/bridge/qb/server/main.lua index e93c05656..4d27ac45c 100644 --- a/bridge/qb/server/main.lua +++ b/bridge/qb/server/main.lua @@ -87,14 +87,7 @@ end ---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:SpawnVehicle', function(source, cb, model, coords, warp) - model = type(model) == 'string' and joaat(model) or (model --[[@as integer]]) - local ped = GetPlayerPed(source) - - local netId = qbx.spawnVehicle({ - model = model, - spawnSource = coords or ped, - warp = warp and ped or nil, - }) + local netId = qbCoreCompat.Functions.SpawnVehicle(source, model, coords, warp) if netId then cb(netId) end end) From 13312a01cf3016410224e6391640a87dc1a14c3f Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:44:10 -0500 Subject: [PATCH 11/27] Update bridge/qb/server/main.lua Co-authored-by: David Malchin --- bridge/qb/server/main.lua | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/bridge/qb/server/main.lua b/bridge/qb/server/main.lua index 4d27ac45c..a71982adf 100644 --- a/bridge/qb/server/main.lua +++ b/bridge/qb/server/main.lua @@ -94,14 +94,7 @@ end) ---@deprecated call server function qbx.spawnVehicle from modules/lib.lua qbCoreCompat.Functions.CreateCallback('QBCore:Server:CreateVehicle', function(source, cb, model, coords, warp) - model = type(model) == 'string' and joaat(model) or (model --[[@as integer]]) - local ped = GetPlayerPed(source) - - local netId = qbx.spawnVehicle({ - model = model, - spawnSource = coords or ped, - warp = warp and ped or nil, - }) + local netId = qbCoreCompat.Functions.CreateVehicle(source, model, nil, coords, warp) if netId then cb(netId) end end) From ab2a6b75669d0e10b8c225bffbac0d0b966fb7e9 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:50:46 -0500 Subject: [PATCH 12/27] fix: manifest and GetPeds --- bridge/qb/client/functions.lua | 18 ++++++++++++++++-- fxmanifest.lua | 1 - 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index ba12305f2..4ceb2dd86 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -135,8 +135,22 @@ end functions.GetPlayers = GetPlayersInScope ---@deprecated use the GetGamePool('CPed') native directly -functions.GetPeds = function() - GetGamePool('CPed') +functions.GetPeds = function(ignoreList) + ignoreList = ignoreList or {} + local pedPool = GetGamePool('CPed') + local peds = {} + local ignoreMap = {} + for i = 1, #ignoreList do + ignoreMap[ignoreList[i]] = true + end + + for i = 1, #pedPool do + local entity = pedPool[i] + if not ignoreMap[entity] then + peds[#peds + 1] = entity + end + end + return peds end ---@deprecated use lib.getClosestPed from ox_lib diff --git a/fxmanifest.lua b/fxmanifest.lua index b6d3ac665..5b550ef08 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -14,7 +14,6 @@ shared_scripts { } client_scripts { - 'modules/lib.lua', 'client/main.lua', 'client/functions.lua', 'client/loops.lua', From 0e868969ea7b98d1407fcd1cad6fea1aee035db1 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:00:50 -0500 Subject: [PATCH 13/27] fix: GetPlate and GetVehicleDisplayName --- bridge/qb/client/functions.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 4ceb2dd86..82d0a0b49 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -247,10 +247,16 @@ end functions.DeleteVehicle = qbx.deleteVehicle ---@deprecated use qbx.getVehiclePlate from modules/lib.lua -functions.GetPlate = qbx.getVehiclePlate +functions.GetPlate = function(vehicle) + if vehicle == 0 then return end + return qbx.getVehiclePlate(vehicle) +end ---@deprecated use qbx.getVehicleDisplayName from modules/lib.lua -functions.GetVehicleLabel = qbx.getVehicleDisplayName +functions.GetVehicleLabel = function(vehicle) + if vehicle == nil or vehicle == 0 then return end + return qbx.getVehicleDisplayName(vehicle) +end ---@deprecated use lib.getNearbyVehicles from ox_lib functions.SpawnClear = lib.getNearbyVehicles From 390b59bea915f88f27090daa46ae8620a4152f50 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:35:40 -0500 Subject: [PATCH 14/27] fix: Trim, FirstToUpper, and Cardinal Direction --- bridge/qb/shared/main.lua | 10 ++++++++-- modules/lib.lua | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bridge/qb/shared/main.lua b/bridge/qb/shared/main.lua index c6940b359..8932a9ea3 100644 --- a/bridge/qb/shared/main.lua +++ b/bridge/qb/shared/main.lua @@ -20,10 +20,16 @@ end qbShared.SplitStr = string.strsplit ---@deprecated use qbx.string.trim from modules/lib.lua -qbShared.Trim = qbx.string.trim +qbShared.Trim = function(str) + if not str then return nil end + return qbx.string.trim(str) +end ---@deprecated use qbx.string.capitalize from modules/lib.lua -qbShared.FirstToUpper = qbx.string.capitalize +qbShared.FirstToUpper = function(str) + if not str then return nil end + return qbx.string.capitalize(str) +end ---@deprecated use qbx.math.round from modules/lib.lua qbShared.Round = qbx.math.round diff --git a/modules/lib.lua b/modules/lib.lua index bb79af6fc..322ef6ef9 100644 --- a/modules/lib.lua +++ b/modules/lib.lua @@ -173,6 +173,10 @@ end ---@param entity integer ---@return 'North' | 'South' | 'East' | 'West' function qbx.getCardinalDirection(entity) + if not DoesEntityExist(entity) then + return lib.print.error('Cardinal Direction Error') + end + -- heading is between 0 - 360 (excluding 360) local heading = GetEntityHeading(entity) % 360 From 24682c6326a33bd3649f262496cfef17cc7970a1 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:44:11 -0500 Subject: [PATCH 15/27] fix: add string.split from utils to bridge --- bridge/qb/shared/main.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bridge/qb/shared/main.lua b/bridge/qb/shared/main.lua index 8932a9ea3..51154d169 100644 --- a/bridge/qb/shared/main.lua +++ b/bridge/qb/shared/main.lua @@ -17,7 +17,11 @@ qbShared.RandomInt = function(length) end ---@deprecated use string.strsplit with CfxLua 5.4 -qbShared.SplitStr = string.strsplit +qbShared.SplitStr = function(str, delimiter) + local result = table.pack(string.strsplit(delimiter, str)) + result.n = nil + return result +end ---@deprecated use qbx.string.trim from modules/lib.lua qbShared.Trim = function(str) From cf6e71d535daf591b17db03058b2b059abdb8b5a Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:46:27 -0500 Subject: [PATCH 16/27] fix: GetPlayers --- bridge/qb/client/functions.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 82d0a0b49..74f3f7288 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -131,8 +131,8 @@ functions.GetObjects = function() GetGamePool('CObject') end ----@deprecated use the GetPlayersInScope native directly -functions.GetPlayers = GetPlayersInScope +---@deprecated use the GetActivePlayers native directly +functions.GetPlayers = GetActivePlayers ---@deprecated use the GetGamePool('CPed') native directly functions.GetPeds = function(ignoreList) From 2ca97b7a8f47ec05e301a5b1a5aacea275c58642 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:54:42 -0500 Subject: [PATCH 17/27] fix: SpawnClear --- bridge/qb/client/functions.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 74f3f7288..57ac12681 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -259,7 +259,11 @@ functions.GetVehicleLabel = function(vehicle) end ---@deprecated use lib.getNearbyVehicles from ox_lib -functions.SpawnClear = lib.getNearbyVehicles +functions.SpawnClear = function(coords, radius) + local vehicles = lib.getNearbyVehicles(coords, radius) + if #vehicles > 0 then return false end + return true +end ---@deprecated use lib.getVehicleProperties from ox_lib function functions.GetVehicleProperties(vehicle) From 1f37eba0e18375d2879d4e91e1ac01d9b3f9fa2f Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Thu, 18 Jan 2024 21:17:12 -0500 Subject: [PATCH 18/27] fix: GetClosestPlayer, GetClosestVehicle, and GetClosestObject --- bridge/qb/client/functions.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 57ac12681..c2021d8b1 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -161,16 +161,28 @@ functions.GetClosestPed = lib.getClosestPed functions.IsWearingGloves = qbx.isWearingGloves ---@deprecated use lib.getClosestPlayer from ox_lib -functions.GetClosestPlayer = lib.getClosestPlayer +functions.GetClosestPlayer = function(coords) + local playerId, _, playerCoords = lib.getClosestVehicle(coords) + local playerDistance = #(coords - playerCoords) + return playerId, playerDistance +end ---@deprecated use lib.getNearbyPlayers from ox_lib functions.GetPlayersFromCoords = lib.getNearbyPlayers ---@deprecated use lib.getClosestVehicle from ox_lib -functions.GetClosestVehicle = lib.getClosestVehicle +functions.GetClosestVehicle = function(coords) + local closestVehicle, vehicleCoords = lib.getClosestVehicle(coords) + local vehicleDistance = #(coords - vehicleCoords) + return closestVehicle, vehicleDistance +end ---@deprecated use lib.getClosestObject from ox_lib -functions.GetClosestObject = lib.getClosestObject +functions.GetClosestObject = function(coords) + local closestObject, objectCoords = lib.getClosestObject(coords) + local objectDistance = #(coords - objectCoords) + return closestObject, objectDistance +end ---@deprecated use the GetWorldPositionOfEntityBone native and calculate distance directly functions.GetClosestBone = function(entity, list) From 4bbabeef3c77f65acf9be7623324692df0e7df31 Mon Sep 17 00:00:00 2001 From: Matthew <22198949+MafewTM@users.noreply.github.com> Date: Thu, 18 Jan 2024 21:26:41 -0500 Subject: [PATCH 19/27] fix: GetPlayerFromCoords --- bridge/qb/client/functions.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index c2021d8b1..c5def5cd6 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -168,7 +168,14 @@ functions.GetClosestPlayer = function(coords) end ---@deprecated use lib.getNearbyPlayers from ox_lib -functions.GetPlayersFromCoords = lib.getNearbyPlayers +functions.GetPlayersFromCoords = function(coords, radius) + local playerIds = {} + local players = lib.getNearbyPlayers(coords, radius) + for _, player in ipairs(players) do + playerIds[#playerIds + 1] = player.id + end + return playerIds +end ---@deprecated use lib.getClosestVehicle from ox_lib functions.GetClosestVehicle = function(coords) From 18d8efa573df5d19c579a3d5d77edbe27b8e7b71 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Jan 2024 13:08:07 +0100 Subject: [PATCH 20/27] feat(lint): new lib --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9fa457166..df9fda6d0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ jobs: with: capture: "junit.xml" args: "-t --formatter JUnit" - extra_libs: ox_lib+mysql+qblocales+qbox+qbox_playerdata+qbox_utils+qbox_utils_sv+qbox_utils_cl + extra_libs: ox_lib+mysql+qblocales+qbox+qbox_playerdata+qbox_lib - name: Generate Lint Report if: always() uses: mikepenz/action-junit-report@v3 From 2b030402e224da7c989a67580486ec81c565b776 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Jan 2024 13:14:44 +0100 Subject: [PATCH 21/27] fix(bridge): qb closestped compat --- bridge/qb/client/functions.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index c5def5cd6..5bd47803f 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -155,7 +155,11 @@ end ---@deprecated use lib.getClosestPed from ox_lib ---Use GetClosestPlayer if wanting to ignore non-player peds -functions.GetClosestPed = lib.getClosestPed +functions.GetClosestPed = function(_, coords) -- Don't use ignoreList here because, who even uses that + local closestPed, closestCoords = lib.getClosestPed(coords, 999) -- qb doesn't have a max distance so we just set this very high for compatibility + local closestDistance = closestCoords and #(closestCoords - coords) or -1 + return closestPed or -1, closestDistance +end ---@deprecated use qbx.isWearingGloves from modules/lib.lua functions.IsWearingGloves = qbx.isWearingGloves From fbf6c64bdb6fec53f610dd28ce6ace8f982eb5cd Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:30:07 +0100 Subject: [PATCH 22/27] tweak(bridge): simplify SpawnClear --- bridge/qb/client/functions.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 5bd47803f..0d65ffdf2 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -283,9 +283,7 @@ end ---@deprecated use lib.getNearbyVehicles from ox_lib functions.SpawnClear = function(coords, radius) - local vehicles = lib.getNearbyVehicles(coords, radius) - if #vehicles > 0 then return false end - return true + return #lib.getNearbyVehicles(coords, radius) == 0 end ---@deprecated use lib.getVehicleProperties from ox_lib From 198e964122ac3fe4b2ccc65aa23a2eab89ec70dc Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:31:01 +0100 Subject: [PATCH 23/27] tweak(bridge): don't redefine heading --- bridge/qb/client/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index 0d65ffdf2..c4b66ca66 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -248,7 +248,7 @@ end function functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto) local playerCoords = GetEntityCoords(cache.ped) local combinedCoords = vec4(playerCoords.x, playerCoords.y, playerCoords.z, GetEntityHeading(cache.ped)) - coords = type(coords) == 'table' and vec4(coords.x, coords.y, coords.z, coords.w or GetEntityHeading(cache.ped)) or coords or combinedCoords + coords = type(coords) == 'table' and vec4(coords.x, coords.y, coords.z, coords.w or combinedCoords.w) or coords or combinedCoords model = type(model) == 'string' and joaat(model) or model if not IsModelInCdimage(model) then return end From dab97521e084b49f1dac2d0b2655b2493e53c69a Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 20 Jan 2024 15:52:04 +0100 Subject: [PATCH 24/27] tweak: wrap cardinal direction instead --- bridge/qb/client/functions.lua | 8 +++++++- modules/lib.lua | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bridge/qb/client/functions.lua b/bridge/qb/client/functions.lua index c4b66ca66..d05a2ea40 100644 --- a/bridge/qb/client/functions.lua +++ b/bridge/qb/client/functions.lua @@ -818,7 +818,13 @@ functions.GetStreetNametAtCoords = qbx.getStreetName functions.GetZoneAtCoords = qbx.getZoneName ---@deprecated use qbx.getCardinalDirection from modules/lib.lua -functions.GetCardinalDirection = qbx.getCardinalDirection +functions.GetCardinalDirection = function(entity) + if not entity or not DoesEntityExist(entity) then + return 'Cardinal Direction Error' + end + + return qbx.getCardinalDirection(entity) +end ---@deprecated use the GetClockMinutes and GetClockHours natives and format the output directly functions.GetCurrentTime = function() diff --git a/modules/lib.lua b/modules/lib.lua index 322ef6ef9..bb79af6fc 100644 --- a/modules/lib.lua +++ b/modules/lib.lua @@ -173,10 +173,6 @@ end ---@param entity integer ---@return 'North' | 'South' | 'East' | 'West' function qbx.getCardinalDirection(entity) - if not DoesEntityExist(entity) then - return lib.print.error('Cardinal Direction Error') - end - -- heading is between 0 - 360 (excluding 360) local heading = GetEntityHeading(entity) % 360 From 5dc062cfe1664dc82de9ee7226a4d3cb3ea37e88 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:00:08 +0100 Subject: [PATCH 25/27] fix(server/events): use table instead of old func --- server/events.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events.lua b/server/events.lua index d6396b320..9aaa6a6d7 100644 --- a/server/events.lua +++ b/server/events.lua @@ -78,7 +78,7 @@ local function onPlayerConnecting(name, _, deferrals) if not license then deferrals.done(locale('error.no_valid_license')) - elseif serverConfig.checkDuplicateLicense and IsLicenseInUse(license) then + elseif serverConfig.checkDuplicateLicense and usedLicenses[license] then deferrals.done(locale('error.duplicate_license')) end From 2a5caf888f4048f47bdcf853a4841807d75e1467 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:05:07 +0100 Subject: [PATCH 26/27] perf(server/commands): reuse variable instead --- server/commands.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/commands.lua b/server/commands.lua index ac36bdc76..1660ee4a2 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -144,15 +144,16 @@ lib.addCommand('car', { }, function(source, args) if not args then return end + local ped = GetPlayerPed(source) local keepCurrentVehicle = args[locale("command.car.params.keepCurrentVehicle.name")] - local currentVehicle = GetVehiclePedIsIn(GetPlayerPed(source), false) - if not keepCurrentVehicle then + local currentVehicle = not keepCurrentVehicle and GetVehiclePedIsIn(ped, false) + if currentVehicle and currentVehicle ~= 0 then DeleteVehicle(currentVehicle) end local netId = qbx.spawnVehicle({ model = args[locale("command.car.params.model.name")], - spawnSource = GetPlayerPed(source), + spawnSource = ped, warp = true, }) From bfb94dfa09f3a86a73f7f50bc681533f0fa60df1 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Mon, 22 Jan 2024 14:26:37 +0100 Subject: [PATCH 27/27] fix: lint --- modules/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/utils.lua b/modules/utils.lua index 803975bee..0ed96f629 100644 --- a/modules/utils.lua +++ b/modules/utils.lua @@ -116,7 +116,7 @@ end --- @param subfield string --- @param table table --- @return table -function MapTableBySubfield(subfield, table) +function MapTableBySubfield(subfield, table) -- luacheck: ignore return qbx.table.mapBySubfield(table, subfield) end