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..d05a2ea40 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,134 @@ 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 -functions.GetPlayers = GetPlayersInScope +---@deprecated use the GetActivePlayers native directly +functions.GetPlayers = GetActivePlayers ----@deprecated use GetPeds from imports/utils.lua -functions.GetPeds = GetPeds +---@deprecated use the GetGamePool('CPed') native directly +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 ----@deprecated use GetClosestPed from imports/utils.lua + 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 ---Use GetClosestPlayer if wanting to ignore non-player peds -functions.GetClosestPed = 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 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 = function(coords) + local playerId, _, playerCoords = lib.getClosestVehicle(coords) + local playerDistance = #(coords - playerCoords) + return playerId, playerDistance +end ----@deprecated use GetPlayersFromCoords from imports/utils.lua -functions.GetPlayersFromCoords = GetPlayersFromCoords +---@deprecated use lib.getNearbyPlayers from ox_lib +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 GetClosestVehicle from imports/utils.lua -functions.GetClosestVehicle = GetClosestVehicle +---@deprecated use lib.getClosestVehicle from ox_lib +functions.GetClosestVehicle = function(coords) + local closestVehicle, vehicleCoords = lib.getClosestVehicle(coords) + local vehicleDistance = #(coords - vehicleCoords) + return closestVehicle, vehicleDistance +end ----@deprecated use GetClosestObject from imports/utils.lua -functions.GetClosestObject = GetClosestObject +---@deprecated use lib.getClosestObject from ox_lib +functions.GetClosestObject = function(coords) + local closestObject, objectCoords = lib.getClosestObject(coords) + local objectDistance = #(coords - objectCoords) + return closestObject, objectDistance +end ----@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 combinedCoords.w) or coords or combinedCoords model = type(model) == 'string' and joaat(model) or model if not IsModelInCdimage(model) then return end @@ -153,17 +266,25 @@ 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 = function(vehicle) + if vehicle == 0 then return end + return qbx.getVehiclePlate(vehicle) +end ----@deprecated use GetVehicleDisplayName from imports/utils.lua -functions.GetVehicleLabel = GetVehicleDisplayName +---@deprecated use qbx.getVehicleDisplayName from modules/lib.lua +functions.GetVehicleLabel = function(vehicle) + if vehicle == nil or vehicle == 0 then return end + return qbx.getVehicleDisplayName(vehicle) +end ----@deprecated use IsVehicleSpawnClear from imports/utils.lua -functions.SpawnClear = IsVehicleSpawnClear +---@deprecated use lib.getNearbyVehicles from ox_lib +functions.SpawnClear = function(coords, radius) + return #lib.getNearbyVehicles(coords, radius) == 0 +end ---@deprecated use lib.getVehicleProperties from ox_lib function functions.GetVehicleProperties(vehicle) @@ -261,7 +382,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 +741,123 @@ 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 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 qbx.getStreetName from modules/lib.lua +functions.GetStreetNametAtCoords = qbx.getStreetName + +---@deprecated use qbx.getZoneName from modules/lib.lua +functions.GetZoneAtCoords = qbx.getZoneName + +---@deprecated use qbx.getCardinalDirection from modules/lib.lua +functions.GetCardinalDirection = function(entity) + if not entity or not DoesEntityExist(entity) then + return 'Cardinal Direction Error' + end + + return qbx.getCardinalDirection(entity) +end ----@deprecated use StartParticleOnEntity from imports/utils.lua -functions.StartParticleOnEntity = StartParticleOnEntity +---@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 GetStreetNameAtCoords from imports/utils.lua -functions.GetStreetNametAtCoords = GetStreetNameAtCoords + if obj.hour <= 12 then + obj.ampm = 'AM' + elseif obj.hour >= 13 then + obj.ampm = 'PM' + obj.formattedHour = obj.hour - 12 + end ----@deprecated use GetZoneAtCoords from imports/utils.lua -functions.GetZoneAtCoords = GetZoneAtCoords + if obj.min <= 9 then + obj.formattedMin = ('0%s'):format(obj.min) + end ----@deprecated use GetCardinalDirection from imports/utils.lua -functions.GetCardinalDirection = GetCardinalDirection + return obj +end ----@deprecated use GetCurrentTime from imports/utils.lua -functions.GetCurrentTime = GetCurrentTime +---@deprecated use the GetGroundZFor_3dCoord native directly +functions.GetGroundZCoord = function(coords) + if not coords then return end ----@deprecated use GetGroundZCoord from imports/utils.lua -functions.GetGroundZCoord = GetGroundZCoord + 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..8aab2b08c 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,17 @@ 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) + 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 @@ -54,19 +65,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() + + 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 ----@deprecated use IsLicenseInUse from imports/utils.lua -functions.IsLicenseInUse = IsLicenseInUse + 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..a71982adf 100644 --- a/bridge/qb/server/main.lua +++ b/bridge/qb/server/main.lua @@ -85,15 +85,17 @@ 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 = qbCoreCompat.Functions.SpawnVehicle(source, model, coords, 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 = qbCoreCompat.Functions.CreateVehicle(source, model, nil, coords, warp) + if netId then cb(netId) end end) diff --git a/bridge/qb/shared/main.lua b/bridge/qb/shared/main.lua index 108b3d19e..51154d169 100644 --- a/bridge/qb/shared/main.lua +++ b/bridge/qb/shared/main.lua @@ -1,36 +1,53 @@ local qbShared = require 'shared.main' ----@deprecated use CommaValue from imports/utils.lua -qbShared.CommaValue = CommaValue - ----@deprecated use RandomLetter from imports/utils.lua -qbShared.RandomStr = RandomLetter - ----@deprecated use RandomNumber from imports/utils.lua -qbShared.RandomInt = RandomNumber - ----@deprecated use string.split from imports/utils.lua -qbShared.SplitStr = string.split - ----@deprecated use string.trim from imports/utils.lua -qbShared.Trim = string.trim - ----@deprecated use string.firstToUpper from imports/utils.lua -qbShared.FirstToUpper = string.firstToUpper - ----@deprecated use math.round from imports/utils.lua -qbShared.Round = math.round - ----@deprecated use ChangeVehicleExtra from imports/utils.lua -qbShared.ChangeVehicleExtra = ChangeVehicleExtra - ----@deprecated use SetVehicleExtras from imports/utils.lua -qbShared.SetDefaultVehicleExtras = SetVehicleExtras - ----@deprecated use MaleNoGloves from imports/utils.lua -qbShared.MaleNoGloves = MaleNoGloves - ----@deprecated use FemaleNoGloves from imports/utils.lua -qbShared.FemaleNoGloves = FemaleNoGloves +---@deprecated use lib.math.groupdigits from ox_lib +qbShared.CommaValue = lib.math.groupdigits + +---@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 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.strsplit with CfxLua 5.4 +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) + if not str then return nil end + return qbx.string.trim(str) +end + +---@deprecated use qbx.string.capitalize from modules/lib.lua +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 + +---@deprecated use qbx.setVehicleExtra from modules/lib.lua +qbShared.ChangeVehicleExtra = qbx.setVehicleExtras + +---@deprecated use qbx.setVehicleExtra from modules/lib.lua +qbShared.SetDefaultVehicleExtras = qbx.setVehicleExtras + +---@deprecated use qbx.armsWithoutGloves.male from modules/lib.lua +qbShared.MaleNoGloves = qbx.armsWithoutGloves.male + +---@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 0605a3786..9ccb97ef4 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 a95747d1e..3c07aeb7a 100644 --- a/client/events.lua +++ b/client/events.lua @@ -185,7 +185,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 533dbf1bd..5a0b56b5a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -35,7 +35,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..1ed084c74 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 lib.string.random('........') 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 lib.string.random('...............') end, }, WalletId = { diff --git a/fxmanifest.lua b/fxmanifest.lua index 3c2326378..323b36dfa 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -7,7 +7,7 @@ version '1.4.0' shared_scripts { '@ox_lib/init.lua', - 'modules/utils.lua', + 'modules/lib.lua', 'shared/locale.lua', } diff --git a/modules/lib.lua b/modules/lib.lua index b7efb13b9..bb79af6fc 100644 --- a/modules/lib.lua +++ b/modules/lib.lua @@ -5,6 +5,89 @@ qbx.string = {} qbx.math = {} qbx.table = {} +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 ---@return string @@ -335,89 +418,6 @@ 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 - }), - }) - ---Returns if the local ped is wearing gloves. ---@return boolean function qbx.isWearingGloves() 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 diff --git a/server/commands.lua b/server/commands.lua index 23be706cc..1660ee4a2 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -102,7 +102,7 @@ lib.addCommand('openserver', { config.server.closed = false Notify(source, locale('success.server_opened'), 'success') else - KickWithReason(source, locale("error.no_permission"), nil, nil) + DropPlayer(source, locale("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, locale('success.server_closed'), 'success') else - KickWithReason(source, locale("error.no_permission"), nil, nil) + DropPlayer(source, locale("error.no_permission")) end end) @@ -143,14 +143,21 @@ lib.addCommand('car', { restricted = "group.admin" }, 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 = SpawnVehicle(source, args[locale("command.car.params.model.name")], nil, true) - local plate = GetPlate(NetworkGetEntityFromNetworkId(netId)) + local netId = qbx.spawnVehicle({ + model = args[locale("command.car.params.model.name")], + spawnSource = ped, + warp = true, + }) + + local plate = qbx.getVehiclePlate(NetworkGetEntityFromNetworkId(netId)) config.giveVehicleKeys(source, plate) end) @@ -340,7 +347,7 @@ end) -- ID command lib.addCommand('id', {help = locale('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 b55b91192..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 @@ -169,11 +169,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, locale("error.no_permission"), nil, nil) + DropPlayer(src, locale("error.no_permission")) end end) @@ -182,7 +182,7 @@ RegisterNetEvent('QBCore:Server:OpenServer', function() if HasPermission(src, 'admin') then serverConfig.closed = false else - KickWithReason(src, locale("error.no_permission"), nil, nil) + DropPlayer(src, locale("error.no_permission")) end end) diff --git a/server/main.lua b/server/main.lua index d2daa6f99..959087e27 100644 --- a/server/main.lua +++ b/server/main.lua @@ -120,7 +120,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)