From 8c4c170e64be07e0b0f10792ee3da9dc49c7b800 Mon Sep 17 00:00:00 2001 From: cityparadise <108126483+cityparadise@users.noreply.github.com> Date: Thu, 3 Apr 2025 08:52:47 +0100 Subject: [PATCH 1/6] Added Accessibility Module w/ Misc Fix -- Added new accessibility module -- Added multiple colour convert functions (rgb to hex, rgb to hsl, hsl to rgb, hex to rgb) -- Added adjusment function for colours -- Added check for colourbliness alteration -- Added colourblindness command uses `accessibility.cb_command` as command string -- Added menu option to change colourblind options. -- Added multiple accessibility locale enteries within en.json -- Added multiple accessibility locale enteries within pt.json (translated via google translate) -- Fixed disabled not showing up when using qb-menu. -- Updated init.lua and fxmanifest.lua to include new module entry --- fxmanifest.lua | 1 + init.lua | 1 + locales/en.json | 57 ++++++--- locales/pt.json | 21 +++- modules/accessibility/client.lua | 210 +++++++++++++++++++++++++++++++ modules/menu/_qb-menu.lua | 1 + 6 files changed, 276 insertions(+), 15 deletions(-) create mode 100644 modules/accessibility/client.lua diff --git a/fxmanifest.lua b/fxmanifest.lua index 5fa9b29..4acca46 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -50,6 +50,7 @@ client_scripts { 'modules/notify/**/client.lua', 'modules/dialogue/**/client/*.lua', 'modules/shops/**/client.lua', + 'modules/accessibility/client.lua', 'init.lua', } diff --git a/init.lua b/init.lua index 0bc21a1..3c6340b 100644 --- a/init.lua +++ b/init.lua @@ -99,6 +99,7 @@ Bridge.RegisterModule("Weather", Weather) Bridge.RegisterModule("Target", Target) Bridge.RegisterModule("Menu", Menu) Bridge.RegisterModule("Dialogue", Dialogue) +Bridge.RegisterModule("Accessibility", Accessibility) -- new Bridge.RegisterModule("Utility", cLib.Utility) Bridge.RegisterModule("Placeable", cLib.Placeable)--new diff --git a/locales/en.json b/locales/en.json index 6b04803..fef60d1 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1,16 +1,45 @@ { - "locale-unit-test": "This is a test string", - "place_object_place": "[E] Place \n", - "place_object_cancel": "[X] Cancel \n", - "place_object_scroll_up": "[SCROLL UP] Turn right \n", - "place_object_scroll_down": "[SCROLL DOWN] Turn left", - "enter_text": "Enter Text", - "no_prop_defined": "You didnt define any object to place", - "Shops": {"NotEnoughMoney": "You dont have enough money to buy this item", "Input":"Amount Input", "PurchaseAmount":"Purchase Quanity","PurchasedItem": "You Have Purchased ", "CurrencySymbol": "$", "Confirm":"Confirm Purchase","AreYouSure":"Are you sure you want to purchase a ", "PayByCash": "Pay by cash", "PayByCard": "Pay by card" }, + "locale-unit-test": "This is a test string", + "place_object_place": "[E] Place \n", + "place_object_cancel": "[X] Cancel \n", + "place_object_scroll_up": "[SCROLL UP] Turn right \n", + "place_object_scroll_down": "[SCROLL DOWN] Turn left", + "enter_text": "Enter Text", + "no_prop_defined": "You didnt define any object to place", + "Shops": { + "NotEnoughMoney": "You dont have enough money to buy this item", + "Input": "Amount Input", + "PurchaseAmount": "Purchase Quanity", + "PurchasedItem": "You Have Purchased ", + "CurrencySymbol": "$", + "Confirm": "Confirm Purchase", + "AreYouSure": "Are you sure you want to purchase a ", + "PayByCash": "Pay by cash", + "PayByCard": "Pay by card" + }, + "UNITTEST": { + "UNITTESTA": "Im a %s %s", "UNITTEST": { - "UNITTESTA": "Im a %s %s", - "UNITTEST": { - "UNITTESTA": "\n.-._ _,-,\n`._`-._ _,-'_,'\n `._ `-._ _,-' _,'\n `._ `-._ __.-----.__ _,-' _,'\n `._ `#===\\\"\\\"\\\" \\\"\\\"\\\"===#' _,'\n `._/) ._ _. (\\_,'\n )*' **.__ __.** '*(\n # .==..__ \\\"\\\" \\\"\\\" __..==, #\n # `\\\"._(_). .(_)_.\\\"' #" - } - } -} \ No newline at end of file + "UNITTESTA": "\n.-._ _,-,\n`._`-._ _,-'_,'\n `._ `-._ _,-' _,'\n `._ `-._ __.-----.__ _,-' _,'\n `._ `#===\\\"\\\"\\\" \\\"\\\"\\\"===#' _,'\n `._/) ._ _. (\\_,'\n )*' **.__ __.** '*(\n # .==..__ \\\"\\\" \\\"\\\" __..==, #\n # `\\\"._(_). .(_)_.\\\"' #" + } + }, + "accessibility": { + "cb_command": "colourblindness", + "cb_title": "Colourblindness Options", + "cb_desc": "Select your type of colourblindness\nCurrent Colourblindness: %s", + "cb_none": "None", + "cb_updated": "Colourblindness has been updated to %s", + "cb_default_title": "No Colourblindness", + "cb_default_desc": "No colourblindness.\nThis is the default option.", + "cb_protanomaly_title": "Protanomaly", + "cb_protanomaly_desc": "Red-green color blindness.\nMakes certain shades of red look more green and less bright.\nThis type is mild and usually doesn’t get in the way of normal activities.", + "cb_deuteranomaly_title": "Deuteranomaly", + "cb_deuteranomaly_desc": "Red-green color blindness.\nIt makes certain shades of green look more red.\nThis type is mild and doesn’t usually get in the way of normal activities.", + "cb_dual_title": "Protanopia and Deuteranopia", + "cb_dual_desc": "Red-green color blindness.\nMakes someone unable to tell the difference between red and green at all.", + "cb_tritanopia_title": "Tritanopia", + "cb_tritanopia_desc": "Blue-yellow color blindness that makes someone unable to tell the difference between blue and green, purple and red, and yellow and pink.\nIt also makes colors look less bright.", + "cb_tritanomaly_title": "Tritanomaly", + "cb_tritanomaly_desc": "Blue-yellow color blindness makes it hard to tell the difference between blue and green and between yellow and red." + } +} diff --git a/locales/pt.json b/locales/pt.json index 498a81f..2c5e0a8 100644 --- a/locales/pt.json +++ b/locales/pt.json @@ -5,5 +5,24 @@ "place_object_scroll_up": "[SCROLL UP] Direita\n", "place_object_scroll_down": "[SCROLL DOWN] Esquerda", "enter_text": "Inserir Texto", - "no_prop_defined": "Não definiu nenhum objeto para colocar" + "no_prop_defined": "Não definiu nenhum objeto para colocar", + "accessibility": { + "cb_command": "daltônico", + "cb_title": "Opções de daltonismo", + "cb_desc": "Selecione seu tipo de daltonismo\nDaltonismo atual: %s", + "cb_none": "Nenhum", + "cb_updated": "O daltonismo foi atualizado para %s", + "cb_default_title": "Sem daltonismo", + "cb_default_desc": "Sem daltonismo.\nEsta é a opção padrão.", + "cb_protanomaly_title": "Protanomalia", + "cb_protanomaly_desc": "Daltonismo vermelho-verde.\nFaz com que certos tons de vermelho pareçam mais verdes e menos brilhantes.\nEste tipo é leve e geralmente não atrapalha as atividades normais.", + "cb_deuteranomaly_title": "Deuteranomalia", + "cb_deuteranomaly_desc": "Daltonismo vermelho-verde.\nFaz com que certos tons de verde pareçam mais vermelhos.\nEste tipo é leve e geralmente não atrapalha as atividades normais.", + "cb_dual_title": "Protanopia e Deuteranopia", + "cb_dual_desc": "Daltonismo vermelho-verde.\nFaz com que alguém não consiga distinguir entre vermelho e verde.", + "cb_tritanopia_title": "Tritanopia", + "cb_tritanopia_desc": "Daltonismo azul-amarelo que faz com que alguém não consiga distinguir a diferença entre azul e verde, roxo e vermelho, e amarelo e rosa.\nTambém faz com que as cores pareçam menos brilhantes.", + "cb_tritanomaly_title": "Tritanomalia", + "cb_tritanomaly_desc": "O daltonismo azul-amarelo dificulta a distinção entre azul e verde e entre amarelo e vermelho.", + } } \ No newline at end of file diff --git a/modules/accessibility/client.lua b/modules/accessibility/client.lua new file mode 100644 index 0000000..a284ca6 --- /dev/null +++ b/modules/accessibility/client.lua @@ -0,0 +1,210 @@ +local colourblind = GetResourceKvpString('colourblind') or "default" +local QB = false +if (BridgeClientConfig.MenuSystem == "auto" and GetResourceState("qb-menu") ~= "started") or (BridgeClientConfig.MenuSystem ~= "auto" and BridgeClientConfig.MenuSystem == "qb-menu") then + QB = true +end + +Accessibility = Accessibility or {} + +RegisterCommand(locale("accessibility.cb_command"), function() + Accessibility.updatecolourblindness() +end, false) + +Accessibility.updatecolourblindness = function() + local currentCB = locale("accessibility.cb_"..colourblind.."_title") + local cbIcon = "fas fa-eye-low-vision" + Menu.Open({ + id = 'colourblind_update', + title = locale("accessibility.cb_title"), + options = { + { + title = locale("accessibility.cb_title"), + description = locale("accessibility.cb_desc"):format(currentCB), + disabled = true, + }, + { + title = locale("accessibility.cb_default_title"), + description = locale("accessibility.cb_default_desc"), + icon = "fas fa-eye", + onSelect = function() + colourblind = "default" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + { + title = locale("accessibility.cb_protanomaly_title"), + description = locale("accessibility.cb_protanomaly_desc"), + icon = cbIcon, + onSelect = function() + colourblind = "protanomaly" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + { + title = locale("accessibility.cb_deuteranomaly_title"), + description = locale("accessibility.cb_deuteranomaly_desc"), + icon = cbIcon, + onSelect = function() + colourblind = "deuteranomaly" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + { + title = locale('accessibility.cb_dual_title'), + description = locale("accessibility.cb_dual_desc"), + icon = cbIcon, + onSelect = function() + colourblind = "dual" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + { + title = locale("accessibility.cb_tritanopia_title"), + description = locale("accessibility.cb_tritanopia_desc"), + icon = cbIcon, + onSelect = function() + colourblind = "tritanopia" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + { + title = locale("accessibility.cb_tritanomaly_title"), + description = locale("accessibility.cb_tritanomaly_desc"), + icon = cbIcon, + onSelect = function() + colourblind = "tritanomaly" + SetResourceKvp('colourblind', colourblind) + Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000) + end + }, + }},QB) +end +Accessibility.hexToRgb = function(hex) + hex = hex:gsub("#", "") + local r,g,b = tonumber("0x" .. hex:sub(1, 2)),tonumber("0x" .. hex:sub(3, 4)),tonumber("0x" .. hex:sub(5, 6)) + return r, g, b +end + +Accessibility.rgbToHex = function(r, g, b) + return string.format("#%02x%02x%02x", r, g, b) +end + +Accessibility.rgbToHsl = function(r, g, b) + r = r / 255 + g = g / 255 + b = b / 255 + local max = math.max(r, g, b) + local min = math.min(r, g, b) + local h, s, l = 0, 0, (max + min) / 2 + + if max == min then + h, s = 0, 0 -- achromatic + else + local d = max - min + s = l > 0.5 and d / (2 - max - min) or d / (max + min) + if max == r then + h = (g - b) / d + (g < b and 6 or 0) + elseif max == g then + h = (b - r) / d + 2 + elseif max == b then + h = (r - g) / d + 4 + end + h = h / 6 + end + return h, s, l +end + +Accessibility.hslToRgb = function(h, s, l) + local r, g, b + if s == 0 then + r, g, b = l, l, l -- achromatic + else + local function hue2rgb(p, q, t) + if t < 0 then t = t + 1 end + if t > 1 then t = t - 1 end + if t < 1 / 6 then return p + (q - p) * 6 * t end + if t < 1 / 2 then return q end + if t < 2 / 3 then return p + (q - p) * (2 / 3 - t) * 6 end + return p + end + + local q = l < 0.5 and l * (1 + s) or l + s - l * s + local p = 2 * l - q + r = hue2rgb(p, q, h + 1 / 3) + g = hue2rgb(p, q, h) + b = hue2rgb(p, q, h - 1 / 3) + end + return math.floor(r * 255), math.floor(g * 255), math.floor(b * 255) +end + +Accessibility.adjustColourForColourblindness = function(num, returnAsRGB) + local r, g, b + if type(num) ~= "table" and num:match("^#%x%x%x%x%x%x$") then + r, g, b = Accessibility.hexToRgb(num) -- Convert hex to RGB + else + r, g, b = num.r, num.g, num.b -- If it's already RGB, use it directly + end + local h, s, l = Accessibility.rgbToHsl(r, g, b) -- Convert RGB to HSL + -- Adjust hue values based on colourblindness type + if colourblind == "protanomaly" then -- Red-blind + -- Shift towards blue/cyan + h = (h + 0.5) % 1 -- Shift by 180 degrees + elseif colourblind == "deuteranomaly" then -- Green-blind + -- Shift towards blue/magenta + h = (h + 0.33) % 1 -- Shift by 120 degrees + elseif colourblind == "dual" then -- Protanopia and Deuteranopia (Red-Green blind) + -- More significant shift towards blue/yellow + -- This is a more drastic shift to maximize contrast + if h < 0.166 then -- Reddish hues + h = 0.66 -- Shift to blue + elseif h < 0.5 then -- Greenish hues + h = 0.166 -- Shift to yellow + else + h = h -- Leave blue/purple hues alone + end + -- Increase saturation and lightness to make colours more distinct + s = math.min(s * 1.5, 1) + l = math.min(l * 1.2, 1) + elseif colourblind == "tritanopia" then -- Blue-blind + -- Shift towards red/yellow + h = (h + 0.16) % 1 -- Shift by 60 degrees + elseif colourblind == "tritanomaly" then + h = (h + 0.08) % 1 + end + + -- Convert back to RGB + r, g, b = Accessibility.hslToRgb(h, s, l) + if returnAsRGB then + return {r = r, g = g, b = b} + else + -- Convert back to HEX + local newHex = Accessibility.rgbToHex(r, g, b) + return newHex + end +end + +---@returns a colour adjusted for colourblindness in HEX if variable `returnAsRGB` is false +---@param colourName string Colour name in HEX format or RGB format +-- This is the trigger function for altering colours for colourblindness :D +Accessibility.getAdjustedColour = function(colourName, returnAsRGB) + local originalHex = colourName + if originalHex then + if colourblind == "default" then + if type(colourName) == "table" and not returnAsRGB then + return Accessibility.rgbToHex(colourName.r, colourName.g, colourName.b) + else + return originalHex + end + else + return Accessibility.adjustColourForColourblindness(originalHex, returnAsRGB) + end + else + Prints.Error("Invalid Colour Name^0] [^3"..colourName.."^0") + return "#FFFFFF" -- Default to white if the colour name is invalid + end +end \ No newline at end of file diff --git a/modules/menu/_qb-menu.lua b/modules/menu/_qb-menu.lua index 511495a..411fd0e 100644 --- a/modules/menu/_qb-menu.lua +++ b/modules/menu/_qb-menu.lua @@ -18,6 +18,7 @@ function OxToQBMenu(id, menu) header = v.title, txt = v.description, icon = v.icon, + disabled = v.disabled, } if v.onSelect then From abb5e21e03d63d0d6e125a3ea30ac468e20a86ca Mon Sep 17 00:00:00 2001 From: OGReaper <102786953+OGReaperx@users.noreply.github.com> Date: Sat, 5 Apr 2025 20:58:13 +1300 Subject: [PATCH 2/6] zones --- modules/target/ox_target/client.lua | 20 ++++++++++++++++++++ modules/target/qb-target/client.lua | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 59a8b9d..6dc06cd 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -100,6 +100,26 @@ Target.AddBoxZone = function(name, coords, size, heading, options) return target end +---comment +---@param name string +---@param coords vector3 +---@param radius number +---@param heading number -- unused, but kept for compatibility +---@param options table +---@return number +Target.AddSphereZone = function(name, coords, radius, heading, options) + options = Target.FixOptions(options) + local target = ox_target:addSphereZone({ + coords = coords, + radius = radius, + name = name, + debug = targetDebug, + options = options + }) + table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() }) + return target +end + Target.RemoveGlobalPlayer = function() ox_target:removeGlobalPlayer() end diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index 9df9315..d31c065 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -92,6 +92,18 @@ Target.AddBoxZone = function(name, coords, size, heading, options) table.insert(targetZones, { name = name, creator = GetInvokingResource() }) end +Target.AddSphereZone = function(name, coords, radius, options) + options = Target.FixOptions(options) + exports['qb-target']:AddCircleZone(name, coords, radius, { + name = name, + debugPoly = targetDebug, + }, { + options = options, + distance = options.distance or 1.5, + }) + table.insert(targetZones, { name = name, creator = GetInvokingResource() }) +end + Target.RemoveGlobalPlayer = function() exports['qb-target']:RemoveGlobalPlayer() end From 9ad8c6188c97033dbfb00dcc8c3225e918671f12 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:33:05 -0400 Subject: [PATCH 3/6] Drawtext for non target partial support --- lib/utility/client/utility.lua | 20 ++++++ modules/target/_defualt/client.lua | 97 +++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 2 deletions(-) diff --git a/lib/utility/client/utility.lua b/lib/utility/client/utility.lua index dcca2e6..2b7f62f 100644 --- a/lib/utility/client/utility.lua +++ b/lib/utility/client/utility.lua @@ -239,6 +239,26 @@ Utility.HelpText = function(text, duration) EndTextCommandDisplayHelp(0, false, true, duration or 5000) end +---This will display 3D help text at the specified coordinates. +---@param coords table +---@param text string +---@param scale number +Utility.Draw3DHelpText = function(coords, text, scale) + local onScreen, x, y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z) + if onScreen then + SetTextScale(scale or 0.35, scale or 0.35) + SetTextFont(4) + SetTextProportional(1) + SetTextColour(255, 255, 255, 215) + SetTextEntry("STRING") + SetTextCentre(1) + AddTextComponentString(text) + DrawText(x, y) + local factor = (string.len(text)) / 370 + DrawRect(x, y + 0.0125, 0.015 + factor, 0.03, 41, 11, 41, 100) + end +end + ---This will display a native help text on the screen. It will add a text entry and display it for the specified duration. ---@param text string Utility.NotifyText = function(text) diff --git a/modules/target/_defualt/client.lua b/modules/target/_defualt/client.lua index bc9b892..710c524 100644 --- a/modules/target/_defualt/client.lua +++ b/modules/target/_defualt/client.lua @@ -4,6 +4,20 @@ local function warnUser() print("Currently Only Targeting Is Supported By Community Bridge, You Are Using A Resource That Requires The Target Module To Be Used.") end +Target.FixOptions = function(options) + for k, v in pairs(options) do + local action = v.onSelect or v.action + local select = function(entityOrData) + if type(entityOrData) == 'table' then + return action(entityOrData.entity) + end + return action(entityOrData) + end + options[k].onSelect = select + end + return options +end + Target.AddGlobalPlayer = function(options) warnUser() end @@ -17,15 +31,94 @@ Target.RemoveGlobalVehicle = function(options) end Target.AddLocalEntity = function(entities, _options) - warnUser() + local fixedOptions = Target.FixOptions(_options) + if type(entities) == "string" or type(entities) == "number" then + entities = { entities } + end + for _, entity in pairs(entities) do + local id = Ids.RandomString() + local menuData = { id = id, title = "Options", options = {} } + for k, v in pairs(fixedOptions) do + table.insert(menuData.options, { + title = ("Option " .. k), + description = "No Description", + icon = v.icon or "fas fa-code-pull-request", + args = {}, + onSelect = function(selected, secondary, args) + if v.onSelect then + v.onSelect(selected, secondary, args) + end + end + }) + end + Point.Register(id, entity, 5, args, + function() + local coords = GetEntityCoords(entity) + local sleep = 3000 + while DoesEntityExist(entity) do + Wait(sleep) + local distance = #(coords - GetEntityCoords(PlayerPedId())) + if distance < 10 then + sleep = 0 + Utility.Draw3DHelpText(coords, "Press [E] To Interact", 0.35) + if IsControlJustPressed(0, 38) then + Menu.Open(menuData, false) + end + else + sleep = 3000 + end + end + end, + function() + Point.Remove(id) + end, function() + --No need for this in this one + end) + end end + Target.AddModel = function(models, options) warnUser() end Target.AddBoxZone = function(name, coords, size, heading, options) - warnUser() + local fixedOptions = Target.FixOptions(_options) + local id = Ids.RandomString() + local menuData = { id = id, title = "Options", options = {} } + for k, v in pairs(fixedOptions) do + table.insert(menuData.options, { + title = ("Option " .. k), + description = "No Description", + onSelect = function(selected, secondary, args) + if v.onSelect then + v.onSelect(selected, secondary, args) + end + end + }) + end + Point.Register(id, coords, 5, args, + function() + local sleep = 3000 + while true do + Wait(sleep) + local distance = #(coords - GetEntityCoords(PlayerPedId())) + if distance < 10 then + sleep = 0 + Utility.Draw3DHelpText(coords, "Press [E] To Interact", 0.35) + if IsControlJustPressed(0, 38) then + Menu.Open(menuData, false) + end + else + sleep = 3000 + end + end + end, + function() + Point.Remove(id) + end, function() + --No need for this in this one + end) end Target.RemoveGlobalPlayer = function() From e5190cdca06d9682050a8cf1bfc19aff3d0ab13c Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:37:22 -0400 Subject: [PATCH 4/6] client side GetItemCount Qbox is hardcoded for ox and the only inventory I know that supports it other than ox is quasar, both are bridged so should be completely fine --- modules/framework/es_extended/client.lua | 9 +++++++++ modules/framework/qb-core/client.lua | 14 ++++++++++++++ modules/framework/qbx_core/client.lua | 8 ++++++++ modules/inventory/_default/client.lua | 4 ++++ modules/inventory/origen_inventory/client.lua | 12 ++++++++++++ modules/inventory/ox_inventory/client.lua | 7 +++++++ modules/inventory/qs-inventory/client.lua | 8 ++++++++ modules/inventory/tgiann-inventory/client.lua | 8 ++++++++ 8 files changed, 70 insertions(+) diff --git a/modules/framework/es_extended/client.lua b/modules/framework/es_extended/client.lua index 5c0e1ac..31bdd58 100644 --- a/modules/framework/es_extended/client.lua +++ b/modules/framework/es_extended/client.lua @@ -80,6 +80,15 @@ Framework.GetPlayerInventory = function() return playerData.inventory end +---comment +---@param item string +---@return number +Framework.GetItemCount = function(item) + local inventory = Framework.GetPlayerInventory() + if not inventory then return 0 end + return inventory[item].count or 0 +end + ---comment ---@return boolean Framework.GetIsPlayerDead = function() diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index 86f3e1c..ef07efb 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -79,6 +79,20 @@ Framework.HasItem = function(item) return QBCore.Functions.HasItem(item) end +---comment +---@param item string +---@return number +Framework.GetItemCount = function(item) + local frameworkInv = QBCore.Functions.GetPlayerData().items + local count = 0 + for _, v in pairs(frameworkInv) do + if v.name == item then + count = count + v.amount + end + end + return count +end + Framework.GetPlayerInventory = function() local items = {} local frameworkInv = QBCore.Functions.GetPlayerData().items diff --git a/modules/framework/qbx_core/client.lua b/modules/framework/qbx_core/client.lua index 3138855..9e7564a 100644 --- a/modules/framework/qbx_core/client.lua +++ b/modules/framework/qbx_core/client.lua @@ -44,6 +44,14 @@ Framework.GetPlayerInventory = function() return QBox.GetPlayerData().items end +---comment +---@param item string +---@return number +Framework.GetItemCount = function(item) + -- This seems to be exclusively for ox_inventory, if other inventories are used, they need to be bridged in the inventory module. Until then we will return 0 and a print. + return 0, print("Community_bridge:WARN: GetItemCount is not implemented for this framework, please use the inventory module to get the item count. If you are using a diffrent inventory please let us know so we can bridge it and have less nonsense.") +end + Framework.GetIsPlayerDead = function() local platerData = QBox.GetPlayerData() return platerData.metadata["isdead"] or platerData.metadata["inlaststand"] diff --git a/modules/inventory/_default/client.lua b/modules/inventory/_default/client.lua index 1cb439d..dc645f3 100644 --- a/modules/inventory/_default/client.lua +++ b/modules/inventory/_default/client.lua @@ -14,6 +14,10 @@ Inventory.HasItem = function(item) return Framework.HasItem(item) end +Inventory.GetItemCount = function(item) + return Framework.GetItemCount(item) +end + ---comment ---@param item string ---@return string diff --git a/modules/inventory/origen_inventory/client.lua b/modules/inventory/origen_inventory/client.lua index e355e7d..7f86414 100644 --- a/modules/inventory/origen_inventory/client.lua +++ b/modules/inventory/origen_inventory/client.lua @@ -27,6 +27,18 @@ Inventory.HasItem = function(item) return origin:HasItem(item) end +---comment +---@param item string +---@return number +Inventory.GetItemCount = function(item) + local searchItem = origin:Search('slots', item) + local count = 0 + for _, v in pairs(searchItem) do + count = count + v.count + end + return count +end + ---comment ---@param item string ---@return string diff --git a/modules/inventory/ox_inventory/client.lua b/modules/inventory/ox_inventory/client.lua index 709f477..721f8ca 100644 --- a/modules/inventory/ox_inventory/client.lua +++ b/modules/inventory/ox_inventory/client.lua @@ -29,6 +29,13 @@ Inventory.HasItem = function(item) return hasItem end +---comment +---@param item string +---@return number +Inventory.GetItemCount = function(item) + return ox_inventory:GetItemCount(item, nil, false) +end + ---comment ---@param item string ---@return string diff --git a/modules/inventory/qs-inventory/client.lua b/modules/inventory/qs-inventory/client.lua index 797e9f3..99a9c8b 100644 --- a/modules/inventory/qs-inventory/client.lua +++ b/modules/inventory/qs-inventory/client.lua @@ -44,6 +44,14 @@ Inventory.GetImagePath = function(item) return imagePath or "https://avatars.githubusercontent.com/u/47620135" end +---comment +---@param item string +---@return number +Inventory.GetItemCount = function(item) + local searchItem = quasar:Search(item) + return searchItem or 0 +end + ---comment ---@return table Inventory.GetPlayerInventory = function() diff --git a/modules/inventory/tgiann-inventory/client.lua b/modules/inventory/tgiann-inventory/client.lua index 5407c52..93183fd 100644 --- a/modules/inventory/tgiann-inventory/client.lua +++ b/modules/inventory/tgiann-inventory/client.lua @@ -25,6 +25,14 @@ Inventory.GetItemInfo = function(item) return repackedTable end +---comment +---@param item string +---@return number +Inventory.GetItemCount = function(item) + local searchItem = tgiann:GetItemCount(item, nil, false) + return searchItem or 0 +end + ---This will return a boolean if the player has the item in the inventory ---@param item string ---@return boolean From 29d75163a9a752785315d479cc2eaa7f06ca2034 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:10:02 -0400 Subject: [PATCH 5/6] intelisense stuff --- lib/utility/shared/ids.lua | 29 ++++++++- lib/utility/shared/prints.lua | 9 +++ modules/clothing/_default/client.lua | 10 +++ modules/dispatch/_default/client/client.lua | 3 + modules/dispatch/lb-tablet/client/client.lua | 2 + modules/doorlock/doors_creator/server.lua | 5 ++ modules/doorlock/ox_doorlock/client.lua | 2 + modules/framework/qb-core/client.lua | 21 +++++++ modules/framework/qb-core/server.lua | 61 +++++++++++++++---- modules/fuel/_defualts/client.lua | 11 +++- modules/inventory/ox_inventory/server.lua | 16 ++--- modules/vehicleKey/_default/client/client.lua | 7 +++ modules/weather/_default/client.lua | 3 +- 13 files changed, 156 insertions(+), 23 deletions(-) diff --git a/lib/utility/shared/ids.lua b/lib/utility/shared/ids.lua index 3091b9b..f0ae840 100644 --- a/lib/utility/shared/ids.lua +++ b/lib/utility/shared/ids.lua @@ -1,5 +1,11 @@ Ids = Ids or {} --- for unique ids + + +---This will generate a unique id. +---@param tbl table +---@param len number +---@param pattern string +---@return string Ids.CreateUniqueId = function(tbl, len, pattern) -- both optional tbl = tbl or {} -- table to check uniqueness. Ids to check against must be the key to the tables value len = len or 8 @@ -21,22 +27,43 @@ Ids.CreateUniqueId = function(tbl, len, pattern) -- both optional return id end + +---This will generate a unique id. +---@param tbl table +---@param len number +---@return string Ids.RandomUpper = function(tbl, len) return Ids.CreateUniqueId(tbl, len, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") end +---This will generate a unique id. +---@param tbl table +---@param len number +---@return string Ids.RandomLower = function(tbl, len) return Ids.CreateUniqueId(tbl, len, "abcdefghijklmnopqrstuvwxyz") end +---This will generate a unique id. +---@param tbl table +---@param len number +---@return string Ids.RandomString = function(tbl, len) return Ids.CreateUniqueId(tbl, len, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") end +---This will generate a unique id. +---@param tbl table +---@param len number +---@return string Ids.RandomNumber = function(tbl, len) return Ids.CreateUniqueId(tbl, len, "0123456789") end +---This will generate a unique id. +---@param tbl table +---@param len number +---@return string Ids.Random = function(tbl, len) return Ids.CreateUniqueId(tbl, len) end diff --git a/lib/utility/shared/prints.lua b/lib/utility/shared/prints.lua index 2fc00ef..6b73522 100644 --- a/lib/utility/shared/prints.lua +++ b/lib/utility/shared/prints.lua @@ -6,18 +6,27 @@ local function printMessage(level, color, message) print(color .. '[' .. level .. ']:', message) end + +---This will print a colored message to the console with the designated prefix. +---@param message string Prints.Info = function(message) printMessage('INFO', '^5', message) end +---This will print a colored message to the console with the designated prefix. +---@param message string Prints.Warn = function(message) printMessage('WARN', '^3', message) end +---This will print a colored message to the console with the designated prefix. +---@param message string Prints.Error = function(message) printMessage('ERROR', '^1', message) end +---This will print a colored message to the console with the designated prefix. +---@param message string Prints.Debug = function(message) printMessage('DEBUG', '^2', message) end diff --git a/modules/clothing/_default/client.lua b/modules/clothing/_default/client.lua index b406e5a..bd35793 100644 --- a/modules/clothing/_default/client.lua +++ b/modules/clothing/_default/client.lua @@ -4,21 +4,31 @@ Clothing = Clothing or {} ClothingBackup = {} + +---This will set the peds skin data to the specified table. It will also store previous skin in the event it needs returned to original. +---@param data table +---@return boolean Clothing.SetAppearance = function(data) ClothingBackup = Clothing.GetAppearance() Utility.SetEntitySkinData(cache.ped, data) return true end +---This will return a table of the players ped appearance +---@return table Clothing.GetAppearance = function() return Utility.GetEntitySkinData(cache.ped) end +---This will return the peds clothing to the previously stored clothing +---@return boolean Clothing.RestoreAppearance = function() Utility.SetEntitySkinData(cache.ped, ClothingBackup) return true end +---This will reload the peds skin data from the backup table. This is used when the skin data is changed and needs to be reloaded. +---@return boolean Clothing.ReloadSkin = function() Utility.SetEntitySkinData(cache.ped, ClothingBackup) return true diff --git a/modules/dispatch/_default/client/client.lua b/modules/dispatch/_default/client/client.lua index a787258..eeffe67 100644 --- a/modules/dispatch/_default/client/client.lua +++ b/modules/dispatch/_default/client/client.lua @@ -1,5 +1,8 @@ Dispatch = Dispatch or {} +---This will send an alert to currently supported dispatch systems. +---@param data table The data to send to the dispatch system. +---@return nil Dispatch.SendAlert = function(data) TriggerServerEvent('community_bridge:Server:DispatchAlert', { sprite = data.blipData.sprite or 161, diff --git a/modules/dispatch/lb-tablet/client/client.lua b/modules/dispatch/lb-tablet/client/client.lua index 85083ff..83aabee 100644 --- a/modules/dispatch/lb-tablet/client/client.lua +++ b/modules/dispatch/lb-tablet/client/client.lua @@ -13,6 +13,8 @@ local function getPriorityLevel(priority) end end +---commentThis will send an alert to the passed jobs +---@param data table Dispatch.SendAlert = function(data) local streetName, _ = Utility.GetStreetNameAtCoords(data.coords) local priority = getPriorityLevel(data.priority) diff --git a/modules/doorlock/doors_creator/server.lua b/modules/doorlock/doors_creator/server.lua index 0aee303..b9ae565 100644 --- a/modules/doorlock/doors_creator/server.lua +++ b/modules/doorlock/doors_creator/server.lua @@ -2,6 +2,11 @@ if GetResourceState('doors_creator') ~= 'started' then return end Doorlock = Doorlock or {} + +---This will toggle the lock status of the door. +---@param doorID string +---@param toggle boolean +---@return boolean Doorlock.ToggleDoorLock = function(doorID, toggle) local state = toggle if state then diff --git a/modules/doorlock/ox_doorlock/client.lua b/modules/doorlock/ox_doorlock/client.lua index b2dd1aa..3c25dd1 100644 --- a/modules/doorlock/ox_doorlock/client.lua +++ b/modules/doorlock/ox_doorlock/client.lua @@ -2,6 +2,8 @@ if GetResourceState('ox_doorlock') ~= 'started' then return end Doorlock = Doorlock or {} +---This will get the closest door to the ped +---@return string | nil Doorlock.GetClosestDoor = function() return exports.ox_doorlock:getClosestDoor() end diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index ef07efb..e9e9a04 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -5,6 +5,8 @@ QBCore = exports['qb-core']:GetCoreObject() Framework = {} +---This will get the name of the framework being used (if a supported framework). +---@return string Framework.GetFrameworkName = function() return 'qb-core' end @@ -13,6 +15,8 @@ Framework.GetPlayerData = function() return QBCore.Functions.GetPlayerData() end +---This will return a table of all the jobs in the framework. +---@return table Framework.GetFrameworkJobs = function() local jobs = {} for k, v in pairs(QBCore.Shared.Jobs) do @@ -25,12 +29,17 @@ Framework.GetFrameworkJobs = function() return jobs end +---This will get the players birth date +---@return string Framework.GetPlayerDob = function() local player = QBCore.Functions.GetPlayerData() local playerData = player.PlayerData return playerData.charinfo.birthdate end +---This will return the players metadata for the specified metadata key. +---@param metadata table | string +---@return table | string | number | boolean Framework.GetPlayerMetaData = function(metadata) return QBCore.Functions.GetPlayerData().metadata[metadata] end @@ -61,15 +70,25 @@ Framework.GetItemInfo = function(item) return repackedTable end +---This will get the players identifier (citizenid) etc. +---@return string Framework.GetPlayerIdentifier = function() return QBCore.Functions.GetPlayerData().citizenid end +---This will get the players name (first and last). +---@return string +---@return string Framework.GetPlayerName = function() local playerData = QBCore.Functions.GetPlayerData() return playerData.charinfo.firstname, playerData.charinfo.lastname end +---This will return the players job name, job label, job grade name and job grade level. +---@return string +---@return string +---@return string +---@return string Framework.GetPlayerJob = function() local playerData = QBCore.Functions.GetPlayerData() return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level @@ -111,6 +130,8 @@ Framework.GetPlayerInventory = function() return items end +---This will get a players dead status. +---@return boolean Framework.GetIsPlayerDead = function() local playerData = QBCore.Functions.GetPlayerData() return playerData.metadata["isdead"] or playerData.metadata["inlaststand"] diff --git a/modules/framework/qb-core/server.lua b/modules/framework/qb-core/server.lua index 88b1ba1..d72ce64 100644 --- a/modules/framework/qb-core/server.lua +++ b/modules/framework/qb-core/server.lua @@ -32,6 +32,7 @@ end -- Framework.GetPlayerName(src) -- Returns the first and last name of the player. +---@return string, string Framework.GetPlayerName = function(src) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -39,6 +40,8 @@ Framework.GetPlayerName = function(src) return playerData.charinfo.firstname, playerData.charinfo.lastname end +---This will get the players birth date +---@return string Framework.GetPlayerDob = function(src) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -138,6 +141,7 @@ end -- Framework.SetMetadata(src, metadata, value) -- Adds the specified metadata key and number value to the player's data. +---@return boolean | nil Framework.SetPlayerMetadata = function(src, metadata, value) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -156,6 +160,7 @@ end -- Framework.AddStress(src, value) -- Adds the specified value to the player's stress level and updates the client HUD. +---@return number | nil Framework.AddStress = function(src, value) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -168,6 +173,7 @@ end -- Framework.RemoveStress(src, value) -- Removes the specified value from the player's stress level and updates the client HUD. +---@return number | nil Framework.RemoveStress = function(src, value) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -180,6 +186,7 @@ end -- Framework.AddHunger(src, value) -- Adds the specified value from the player's hunger level. +---@return number | nil Framework.AddHunger = function(src, value) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -192,6 +199,7 @@ end -- Framework.AddThirst(src, value) -- Adds the specified value from the player's thirst level. +---@return number | nil Framework.AddThirst = function(src, value) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -202,6 +210,9 @@ Framework.AddThirst = function(src, value) return newThirst end +---This will get the hunger of a player +---@param src any +---@return number | nil Framework.GetHunger = function(src) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -210,6 +221,10 @@ Framework.GetHunger = function(src) return newHunger end + +---This will get the thirst of a player +---@param src any +---@return number | nil Framework.GetThirst = function(src) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -236,8 +251,9 @@ Framework.GetPlayerGang = function(src) return playerData.gang.name end --- Framework.GetPlayersByJob(jobname) --- returns a table of player sources that have the specified job name. +---This will get a table of player sources that have the specified job name. +---@param job any +---@return table Framework.GetPlayersByJob = function(job) local players = QBCore.Functions.GetPlayers() local playerList = {} @@ -250,8 +266,12 @@ Framework.GetPlayersByJob = function(job) return playerList end --- Framework.GetPlayerJob(src) --- Returns the job name, label, grade name, and grade level of the player. +---This will get the players job info +---@param src number +---@return string +---@return string +---@return string +---@return string Framework.GetPlayerJob = function(src) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -259,14 +279,21 @@ Framework.GetPlayerJob = function(src) return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level end --- Framework.SetPlayerJob(src, name, grade) -- Sets the player's job to the specified name and grade. +---@param src number +---@param name string +---@param grade string +---@return nil Framework.SetPlayerJob = function(src, name, grade) local player = QBCore.Functions.GetPlayer(src) if not player then return end return player.Functions.SetJob(name, grade) end +---This will toggle a players duty status +---@param src number +---@param status boolean +---@return nil Framework.ToggleDuty = function(src, status) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -274,8 +301,12 @@ Framework.ToggleDuty = function(src, status) TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty) end --- Framework.AddAccountBalance(src, _type, amount) --- Adds the specified amount to the player's account balance of the specified type. + +---This will add money based on the type of account (money/bank) +---@param src number +---@param _type string +---@param amount number +---@return boolean | nil Framework.AddAccountBalance = function(src, _type, amount) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -283,8 +314,11 @@ Framework.AddAccountBalance = function(src, _type, amount) return player.Functions.AddMoney(_type, amount) end --- Framework.RemoveAccountBalance(src, _type, amount) --- Removes the specified amount from the player's account balance of the specified type. +---This will remove money based on the type of account (money/bank) +---@param src number +---@param _type string +---@param amount number +---@return boolean | nil Framework.RemoveAccountBalance = function(src, _type, amount) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -292,8 +326,10 @@ Framework.RemoveAccountBalance = function(src, _type, amount) return player.Functions.RemoveMoney(_type, amount) end --- Framework.GetAccountBalance(src, _type) --- Returns the player's account balance of the specified type. +---This will remove money based on the type of account (money/bank) +---@param src number +---@param _type string +---@return string | nil Framework.GetAccountBalance = function(src, _type) local player = QBCore.Functions.GetPlayer(src) if not player then return end @@ -341,6 +377,9 @@ Framework.SetMetadata = function(src, item, slot, metadata) return player.Functions.AddItem(item, 1, freeSlot, metadata) end +---This will get all owned vehicles for the player +---@param src number +---@return table Framework.GetOwnedVehicles = function(src) local citizenId = Framework.GetPlayerIdentifier(src) local result = MySQL.Sync.fetchAll("SELECT vehicle, plate FROM player_vehicles WHERE citizenid = '" .. citizenId .. "'") diff --git a/modules/fuel/_defualts/client.lua b/modules/fuel/_defualts/client.lua index b6213e5..b453052 100644 --- a/modules/fuel/_defualts/client.lua +++ b/modules/fuel/_defualts/client.lua @@ -1,11 +1,18 @@ Fuel = Fuel or {} -----print("Fuel: Loading Defualt") + +---This will get the fuel level of the vehicle. +---@param vehicle number The vehicle entity ID. +---@return number fuel The fuel level of the vehicle. Fuel.GetFuel = function(vehicle) if not DoesEntityExist(vehicle) then return 0.0 end return GetVehicleFuelLevel(vehicle) end -Fuel.SetFuel = function(vehicle, fuel, type) +---This will set the fuel level of the vehicle. +---@param vehicle number The vehicle entity ID. +---@param fuel number The fuel level to set. +---@return nil +Fuel.SetFuel = function(vehicle, fuel) if not DoesEntityExist(vehicle) then return end return SetVehicleFuelLevel(vehicle, fuel) end \ No newline at end of file diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 5749bcf..e16db1e 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -37,7 +37,7 @@ Inventory.GetItem = function(src, item, metadata) return ox_inventory:GetItem(src, item, metadata, false) end ----comment +---This will get the item from the specified slot. ---@param src number ---@param slot number ---@return table @@ -63,14 +63,14 @@ Inventory.HasItem = function(src, item) return count > 0 end ----comment +---This wil return the players inventory. ---@param src number ---@return table Inventory.GetPlayerInventory = function(src) return ox_inventory:GetInventoryItems(src, false) end ----comment +---This is to get if there is available space in the inventory. ---@param src number ---@param item string ---@param count number @@ -79,7 +79,7 @@ Inventory.CanCarryItem = function(src, item, count) return ox_inventory:CanCarryItem(src, item, count) end ----comment +---This will register a stash ---@param id number||string ---@param label string ---@param slots number @@ -106,7 +106,7 @@ Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coo TriggerClientEvent('ox_inventory:openInventory', src, 'stash', 'stash_' .. id) end ----comment +---This will get the data about an item such as name, label, stack, weight, description and image. ---@param item string ---@return table Inventory.GetItemInfo = function(item) @@ -123,7 +123,7 @@ Inventory.GetItemInfo = function(item) return repackedTable end ----comment +---This will set the metadata of an item in the inventory. ---@param src number ---@param item string ---@param slot number @@ -133,7 +133,7 @@ Inventory.SetMetadata = function(src, item, slot, metadata) ox_inventory:SetMetadata(src, slot, metadata) end ----comment +---This will update the plate to the vehicle inside the inventory. (It will also update with jg-mechanic if using it) ---@param oldplate string ---@param newplate string ---@return boolean @@ -144,7 +144,7 @@ Inventory.UpdatePlate = function(oldplate, newplate) return true end ----comment +---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus) ---@param item string ---@return string Inventory.GetImagePath = function(item) diff --git a/modules/vehicleKey/_default/client/client.lua b/modules/vehicleKey/_default/client/client.lua index da6a547..5472dc7 100644 --- a/modules/vehicleKey/_default/client/client.lua +++ b/modules/vehicleKey/_default/client/client.lua @@ -1,9 +1,16 @@ VehicleKey = VehicleKey or {} +---This will give keys to the specifed vehicle/plate. +---@param vehicle number The vehicle entity ID. +---@param plate string The plate of the vehicle. VehicleKey.GiveKeys = function(vehicle, plate) return true, print("There Is No Vehicle Key System Installed") end +---This will remove keys from the specifed vehicle/plate. +---@param vehicle number The vehicle entity ID. +---@param plate string The plate of the vehicle. +---@return boolean | nil VehicleKey.RemoveKeys = function(vehicle, plate) return true, print("There Is No Vehicle Key System Installed") end \ No newline at end of file diff --git a/modules/weather/_default/client.lua b/modules/weather/_default/client.lua index b1d40fe..93a508a 100644 --- a/modules/weather/_default/client.lua +++ b/modules/weather/_default/client.lua @@ -1,7 +1,8 @@ Weather = Weather or {} ----comment +---This will toggle the players weather/time sync ---@param toggle boolean +---@return nil Weather.ToggleSync = function(toggle) end \ No newline at end of file From 24cb04a01bfb7c354c18930d3f6732bffb39982a Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Tue, 8 Apr 2025 19:27:34 -0400 Subject: [PATCH 6/6] structure arrangement's moved around, easier to find. Touched up the notes --- modules/target/ox_target/client.lua | 84 +++++++++++++------------- modules/target/qb-target/client.lua | 93 ++++++++++++++++++++--------- 2 files changed, 104 insertions(+), 73 deletions(-) diff --git a/modules/target/ox_target/client.lua b/modules/target/ox_target/client.lua index 6dc06cd..10b7026 100644 --- a/modules/target/ox_target/client.lua +++ b/modules/target/ox_target/client.lua @@ -17,6 +17,9 @@ local targetZones = {} Target = Target or {} +---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc. +---@param options table +---@return table Target.FixOptions = function(options) for k, v in pairs(options) do local action = v.onSelect or v.action @@ -31,29 +34,34 @@ Target.FixOptions = function(options) return options end ----comment +---This will add target options to players. ---@param options table ----@return nil Target.AddGlobalPlayer = function(options) options = Target.FixOptions(options) ox_target:addGlobalPlayer(options) end +---This will remove target options from all players. +Target.RemoveGlobalPlayer = function() +---@diagnostic disable-next-line: missing-parameter + ox_target:removeGlobalPlayer() +end + +---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely. +---@param bool boolean Target.DisableTargeting = function(bool) ox_target:disableTargeting(bool) end ----comment +---This will add taget options to all vehicles. ---@param options table ----@return nil Target.AddGlobalVehicle = function(options) options = Target.FixOptions(options) ox_target:addGlobalVehicle(options) end ----comment +---This will remove target options from all vehicles. ---@param options table ----@return nil Target.RemoveGlobalVehicle = function(options) local assembledLables = {} for k, v in pairs(options) do @@ -62,31 +70,40 @@ Target.RemoveGlobalVehicle = function(options) ox_target:removeGlobalVehicle(assembledLables) end ----comment ----@param entities table +---This will generate targets on non networked entites with the passed options. +---@param entities number | table ---@param options table ----@return nil Target.AddLocalEntity = function(entities, options) options = Target.FixOptions(options) ox_target:addLocalEntity(entities, options) end ----comment ----@param models table +---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity. +---@param entity any +Target.RemoveLocalEntity = function(entity) + ox_target:removeLocalEntity(entity) +end + +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param models number | table ---@param options table ----@return nil Target.AddModel = function(models, options) options = Target.FixOptions(options) ox_target:addModel(models, options) end ----comment +---This will remove target options from all specified models. +---@param model number +Target.RemoveModel = function(model) + ox_target:removeModel(model) +end + +---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ---@param coords table ---@param size table ---@param heading number ---@param options table ----@return number Target.AddBoxZone = function(name, coords, size, heading, options) options = Target.FixOptions(options) local target = ox_target:addBoxZone({ @@ -100,13 +117,11 @@ Target.AddBoxZone = function(name, coords, size, heading, options) return target end ----comment +---This will add a circle zone to the target system. This is useful for when you want to add target options to a specific area. ---@param name string ----@param coords vector3 +---@param coords table ---@param radius number ----@param heading number -- unused, but kept for compatibility ---@param options table ----@return number Target.AddSphereZone = function(name, coords, radius, heading, options) options = Target.FixOptions(options) local target = ox_target:addSphereZone({ @@ -120,28 +135,10 @@ Target.AddSphereZone = function(name, coords, radius, heading, options) return target end -Target.RemoveGlobalPlayer = function() - ox_target:removeGlobalPlayer() -end - ----comment ----@param entity number ----@return nil -Target.RemoveLocalEntity = function(entity) - ox_target:removeLocalEntity(entity) -end - ----comment ----@param model string ----@return nil -Target.RemoveModel = function(model) - ox_target:removeModel(model) -end - ----comment +---This will remove target options from a specific zone. ---@param name string ----@return nil Target.RemoveZone = function(name) + if not name then return end for _, data in pairs(targetZones) do if data.name == name then ox_target:removeZone(data.id) @@ -152,12 +149,11 @@ Target.RemoveZone = function(name) end AddEventHandler('onResourceStop', function(resource) - if resource == GetCurrentResourceName() then - for _, target in pairs(targetZones) do - if target.creator == resource then - ox_target:removeZone(target.id) - end + if resource ~= GetCurrentResourceName() then return end + for _, target in pairs(targetZones) do + if target.creator == resource then + ox_target:removeZone(target.id) end - targetZones = {} end + targetZones = {} end) diff --git a/modules/target/qb-target/client.lua b/modules/target/qb-target/client.lua index d31c065..00cc6ee 100644 --- a/modules/target/qb-target/client.lua +++ b/modules/target/qb-target/client.lua @@ -15,7 +15,12 @@ detectDebugEnabled() local targetZones = {} Target = Target or {} +local qb_target = exports['qb-target'] + +---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc. +---@param options table +---@return table Target.FixOptions = function(options) for k, v in pairs(options) do local action = v.onSelect or v.action @@ -23,7 +28,7 @@ Target.FixOptions = function(options) if type(entityOrData) == 'table' then return action(entityOrData.entity) end - return action(entityOrData) + return action(entityOrData) end options[k].action = select options[k].job = v.job or v.groups @@ -31,55 +36,90 @@ Target.FixOptions = function(options) return options end - +---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely. +---@param bool boolean Target.DisableTargeting = function(bool) - exports['qb-target']:AllowTargeting(not bool) + qb_target:AllowTargeting(not bool) end +---This will add target options to players. +---@param options table Target.AddGlobalPlayer = function(options) options = Target.FixOptions(options) - exports['qb-target']:AddGlobalPlayer({ + qb_target:AddGlobalPlayer({ options = options, distance = options.distance or 1.5 }) end +---This will remove target options from all players. +Target.RemoveGlobalPlayer = function() + qb_target:RemoveGlobalPlayer() +end +---This will add taget options to all vehicles. +---@param options table Target.AddGlobalVehicle = function(options) options = Target.FixOptions(options) - exports['qb-target']:AddGlobalVehicle({ + qb_target:AddGlobalVehicle({ options = options, distance = options.distance or 1.5 }) end +---This will remove target options from all vehicles. +---@param options table Target.RemoveGlobalVehicle = function(options) local assembledLables = {} for k, v in pairs(options) do table.insert(assembledLables, v.label) end - exports['qb-target']:RemoveGlobalVehicle(assembledLables) + qb_target:RemoveGlobalVehicle(assembledLables) end +---This will generate targets on non networked entites with the passed options. +---@param entities number | table +---@param options table Target.AddLocalEntity = function(entities, options) options = Target.FixOptions(options) - exports['qb-target']:AddTargetEntity(entities, { + qb_target:AddTargetEntity(entities, { options = options, distance = options.distance or 1.5 }) end +---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity. +---@param entity any +Target.RemoveLocalEntity = function(entity) + qb_target:RemoveTargetEntity(entity) +end + +---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type. +---@param models number | table +---@param options table Target.AddModel = function(models, options) options = Target.FixOptions(options) - exports['qb-target']:AddTargetModel(models, { + qb_target:AddTargetModel(models, { options = options, distance = options.distance or 1.5, }) end +---This will remove target options from all specified models. +---@param model number +Target.RemoveModel = function(model) + qb_target:RemoveTargetModel(model) +end + +---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area. +---@param name string +---@param coords table +---@param size table +---@param heading number +---@param options table Target.AddBoxZone = function(name, coords, size, heading, options) options = Target.FixOptions(options) - exports['qb-target']:AddBoxZone(name, coords, size.x, size.y, { + qb_target:AddBoxZone(name, coords, size.x, size.y, { name = name, debugPoly = targetDebug, heading = heading, @@ -92,9 +132,14 @@ Target.AddBoxZone = function(name, coords, size, heading, options) table.insert(targetZones, { name = name, creator = GetInvokingResource() }) end +---This will add a circle zone to the target system. This is useful for when you want to add target options to a specific area. +---@param name string +---@param coords table +---@param radius number +---@param options table Target.AddSphereZone = function(name, coords, radius, options) options = Target.FixOptions(options) - exports['qb-target']:AddCircleZone(name, coords, radius, { + qb_target:AddCircleZone(name, coords, radius, { name = name, debugPoly = targetDebug, }, { @@ -104,22 +149,13 @@ Target.AddSphereZone = function(name, coords, radius, options) table.insert(targetZones, { name = name, creator = GetInvokingResource() }) end -Target.RemoveGlobalPlayer = function() - exports['qb-target']:RemoveGlobalPlayer() -end - -Target.RemoveLocalEntity = function(entity) - exports['qb-target']:RemoveTargetEntity(entity) -end - -Target.RemoveModel = function(model) - exports['qb-target']:RemoveTargetModel(model) -end - +---This will remove target options from a specific zone. +---@param name string Target.RemoveZone = function(name) + if not name then return end for _, data in pairs(targetZones) do if data.name == name then - exports['qb-target']:RemoveZone(name) + qb_target:RemoveZone(name) table.remove(targetZones, _) break end @@ -127,12 +163,11 @@ Target.RemoveZone = function(name) end AddEventHandler('onResourceStop', function(resource) - if resource == GetCurrentResourceName() then - for _, target in pairs(targetZones) do - if target.creator == resource then - exports['qb-target']:RemoveZone(target.name) - end + if resource ~= GetCurrentResourceName() then return end + for _, target in pairs(targetZones) do + if target.creator == resource then + qb_target:RemoveZone(target.name) end - targetZones = {} end + targetZones = {} end) \ No newline at end of file