diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index db7c127df..584089651 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,9 +3,7 @@ name: Bug report about: Create a report to help us improve title: "[Bug] - esx_script - Issue" labels: bug -assignees: - - TheFantomas - - Gellipapa +assignees: Arctos2win, Kenshiin13 --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bc4eaabaf..305b3f1b6 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,9 +3,7 @@ name: Feature Request about: Help us improve esx with your ideas title: "[Feature Request] - esx_script - Add better configuration" labels: enhancement -assignees: - - TheFantomas - - Gellipapa +assignees: Arctos2win, Kenshiin13 --- diff --git a/[core]/es_extended/shared/functions.lua b/[core]/es_extended/shared/functions.lua index 184def1bd..51718a2c6 100644 --- a/[core]/es_extended/shared/functions.lua +++ b/[core]/es_extended/shared/functions.lua @@ -210,3 +210,31 @@ function ESX.Await(conditionFunc, errorMessage, timeoutMs) return false end + +---@param switchValue any The value that matches the case to execute. +---@param caseTable table A table mapping values to function references (cases). +---@param defaultFunction? function|nil Optional. default function to execute if no case matches. +---@param ... any Optional. Additional parameters to pass to the matched function (or default function) +---@return any: Result of the executed function (case or default). +function ESX.Switch(switchValue, caseTable, defaultFunction, ...) + assert(switchValue ~= nil, "'switchValue' parameter cannot be nil!") + ESX.AssertType(caseTable, "table") + + if defaultFunction then + assert(ESX.IsFunctionReference(defaultFunction), "'defaultFunction' must be a function reference!") + end + + local caseFunction = caseTable[switchValue] + + if caseFunction and ESX.IsFunctionReference(caseFunction) then + local success, result = pcall(caseFunction, ...) + assert(success, ("Error executing case for value '%s': %s"):format(tostring(switchValue), result)) + return result + elseif defaultFunction then + local success, result = pcall(defaultFunction, ...) + assert(success, ("Error executing default function: %s"):format(result)) + return result + else + return false + end +end \ No newline at end of file