From ca9f83564eca3f9a241c1e5a7cec331698afab7a Mon Sep 17 00:00:00 2001 From: Kasey FItton Date: Thu, 24 Oct 2024 17:52:22 +0100 Subject: [PATCH] feat(es_extended/server): annotations --- [core]/es_extended/common/modules/math.lua | 3 +- [core]/es_extended/server/functions.lua | 71 +++++++++++++++++++++- [core]/esx_menu_dialog/client/main.lua | 5 +- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/[core]/es_extended/common/modules/math.lua b/[core]/es_extended/common/modules/math.lua index 5d43ce79..acd3fdc9 100644 --- a/[core]/es_extended/common/modules/math.lua +++ b/[core]/es_extended/common/modules/math.lua @@ -21,9 +21,10 @@ function ESX.Math.GroupDigits(value) return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. TranslateCap("locale_digit_grouping_symbol")):reverse()) .. right end ----@param value string +---@param value string | number ---@return string | nil function ESX.Math.Trim(value) + value = tostring(value) return (string.gsub(value, "^%s*(.-)%s*$", "%1")) end diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 2dd141b1..79de4a91 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -1,3 +1,5 @@ +---@param msg string +---@return nil function ESX.Trace(msg) if Config.EnableDebug then print(("[^2TRACE^7] %s^7"):format(msg)) @@ -22,12 +24,16 @@ function ESX.TriggerClientEvent(eventName, playerIds, ...) end end +---@param name string | table +---@param group string | table +---@param cb function +---@param allowConsole? boolean +---@param suggestion? table function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion) if type(name) == "table" then for _, v in ipairs(name) do ESX.RegisterCommand(v, group, cb, allowConsole, suggestion) end - return end @@ -189,6 +195,9 @@ local function updateHealthAndArmorInMetadata(xPlayer) xPlayer.setMeta("lastPlaytime", xPlayer.getPlayTime()) end +---@param xPlayer table +---@param cb? function +---@return nil function Core.SavePlayer(xPlayer, cb) if not xPlayer.spawned then return cb and cb() @@ -222,6 +231,8 @@ function Core.SavePlayer(xPlayer, cb) ) end +---@param cb? function +---@return nil function Core.SavePlayers(cb) local xPlayers = ESX.Players if not next(xPlayers) then @@ -278,6 +289,9 @@ local function checkTable(key, val, player, xPlayers) end end +---@param key? string +---@param val? string|table +---@return table function ESX.GetExtendedPlayers(key, val) local xPlayers = {} if type(val) == "table" then @@ -299,6 +313,9 @@ function ESX.GetExtendedPlayers(key, val) return xPlayers end +---@param key? string +---@param val? string|table +---@return number | table function ESX.GetNumPlayers(key, val) if not key then return #GetPlayers() @@ -327,26 +344,34 @@ function ESX.GetNumPlayers(key, val) return #ESX.GetExtendedPlayers(key, val) end +---@param source number +---@return table function ESX.GetPlayerFromId(source) return ESX.Players[tonumber(source)] end +---@param identifier string +---@return table function ESX.GetPlayerFromIdentifier(identifier) return Core.playersByIdentifier[identifier] end +---@param playerId number | string +---@return string function ESX.GetIdentifier(playerId) local fxDk = GetConvarInt("sv_fxdkMode", 0) if fxDk == 1 then return "ESX-DEBUG-LICENCE" end + playerId = tostring(playerId) + local identifier = GetPlayerIdentifierByType(playerId, "license") return identifier and identifier:gsub("license:", "") end ---@param model string|number ----@param player number playerId +---@param player number ---@param cb function ---@diagnostic disable-next-line: duplicate-set-field function ESX.GetVehicleType(model, player, cb) @@ -362,6 +387,11 @@ function ESX.GetVehicleType(model, player, cb) end, model) end +---@param name string +---@param title string +---@param color string +---@param message string +---@return nil function ESX.DiscordLog(name, title, color, message) local webHook = Config.DiscordLogs.Webhooks[name] or Config.DiscordLogs.Webhooks.default local embedData = { @@ -395,6 +425,11 @@ function ESX.DiscordLog(name, title, color, message) ) end +---@param name string +---@param title string +---@param color string +---@param fields table +---@return nil function ESX.DiscordLogFields(name, title, color, fields) local webHook = Config.DiscordLogs.Webhooks[name] or Config.DiscordLogs.Webhooks.default local embedData = { @@ -429,6 +464,7 @@ function ESX.DiscordLogFields(name, title, color, fields) ) end +---@return nil function ESX.RefreshJobs() local Jobs = {} local jobs = MySQL.query.await("SELECT * FROM jobs") @@ -463,10 +499,17 @@ function ESX.RefreshJobs() end end +---@param item string +---@param cb function +---@return nil function ESX.RegisterUsableItem(item, cb) Core.UsableItemsCallbacks[item] = cb end +---@param source number +---@param item string +---@param ... any +---@return nil function ESX.UseItem(source, item, ...) if ESX.Items[item] then local itemCallback = Core.UsableItemsCallbacks[item] @@ -483,10 +526,15 @@ function ESX.UseItem(source, item, ...) end end +---@param index string +---@param overrides table +---@return nil function ESX.RegisterPlayerFunctionOverrides(index, overrides) Core.PlayerFunctionOverrides[index] = overrides end +---@param index string +---@return nil function ESX.SetPlayerFunctionOverride(index) if not index or not Core.PlayerFunctionOverrides[index] then return print("[^3WARNING^7] No valid index provided.") @@ -495,6 +543,8 @@ function ESX.SetPlayerFunctionOverride(index) Config.PlayerFunctionOverride = index end +---@param item string +---@return string? function ESX.GetItemLabel(item) if Config.OxInventory then item = exports.ox_inventory:Items(item) @@ -510,10 +560,12 @@ function ESX.GetItemLabel(item) end end +---@return table function ESX.GetJobs() return ESX.Jobs end +---@return table function ESX.GetUsableItems() local Usables = {} for k in pairs(Core.UsableItemsCallbacks) do @@ -523,6 +575,15 @@ function ESX.GetUsableItems() end if not Config.OxInventory then + ---@param itemType string + ---@param name string + ---@param count integer + ---@param label string + ---@param playerId number + ---@param components? string | table + ---@param tintIndex? integer + ---@param coords? table | vector3 + ---@return nil function ESX.CreatePickup(itemType, name, count, label, playerId, components, tintIndex, coords) local pickupId = (Core.PickupId == 65635 and 0 or Core.PickupId + 1) local xPlayer = ESX.Players[playerId] @@ -540,11 +601,17 @@ if not Config.OxInventory then end end +---@param job string +---@param grade string +---@return boolean function ESX.DoesJobExist(job, grade) return (ESX.Jobs[job] and ESX.Jobs[job].grades[tostring(grade)] ~= nil) or false end +---@param playerId string | number +---@return boolean function Core.IsPlayerAdmin(playerId) + playerId = tostring(playerId) if (IsPlayerAceAllowed(playerId, "command") or GetConvar("sv_lan", "") == "true") and true or false then return true end diff --git a/[core]/esx_menu_dialog/client/main.lua b/[core]/esx_menu_dialog/client/main.lua index abf7a4a3..82588182 100644 --- a/[core]/esx_menu_dialog/client/main.lua +++ b/[core]/esx_menu_dialog/client/main.lua @@ -47,8 +47,9 @@ AddEventHandler("esx_menu_dialog:message:menu_submit", function(data) if menu.submit then -- is the submitted data a number? - if tonumber(data.value) then - data.value = ESX.Math.Round(tonumber(data.value)) + local value = tonumber(data.value) + if value then + data.value = ESX.Math.Round(value) -- check for negative value if tonumber(data.value) <= 0 then