From 2572f86030b3ff76aaaf4ae146369d79fc959e2d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Tue, 11 Mar 2025 22:41:13 +0000 Subject: [PATCH] input compat fixes --- shared/_loaders.lua | 19 +++++++++++++++- shared/coreloader.lua | 15 +++++++++---- shared/drawText.lua | 9 ++++++++ shared/input.lua | 27 +++++++++++++++++------ shared/isAnimal.lua | 17 +++++++++++++++ shared/notify.lua | 7 ++++++ shared/playerfunctions.lua | 44 +++++++++++++++++++++----------------- 7 files changed, 106 insertions(+), 32 deletions(-) diff --git a/shared/_loaders.lua b/shared/_loaders.lua index 07c617a..fe9d183 100644 --- a/shared/_loaders.lua +++ b/shared/_loaders.lua @@ -58,7 +58,7 @@ function onPlayerLoaded(func, onStart) if onPlayerFramework ~= "" then debugPrint("^6Bridge^7: ^2Registering ^3onPlayerLoaded^7()^2 with ^3" .. onPlayerFramework.."^7") else - print("^4ERROR^7: No supported core detected for onPlayerLoaded - Check exports.lua") + print("^4ERROR^7: No supported core detected for onPlayerLoaded - Check starter.lua") end end end @@ -143,6 +143,18 @@ function waitForLogin() end Wait(100) end + elseif isStarted(OXCoreExport) then + if OxPlayer["stateId"] then + loggedIn = true + end + while not OxPlayer["stateId"] do + Wait(1000) + debugPrint("Waiting for stateId to class as logged in") + if OxPlayer.get["stateId"] then + loggedIn = true + break + end + end else -- For other frameworks, use LocalPlayer.state.isLoggedIn. while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do @@ -159,3 +171,8 @@ function waitForLogin() return true end end + + +--local OxPlayer = Ox.GetPlayer() +--jsonPrint(OxPlayer) + diff --git a/shared/coreloader.lua b/shared/coreloader.lua index 331c02a..e7ebe54 100644 --- a/shared/coreloader.lua +++ b/shared/coreloader.lua @@ -49,6 +49,13 @@ for _, v in pairs(Exports) do end end +OxPlayer = nil +if isStarted(OXCoreExport) then + if not isServer() then + OxPlayer = Ox.GetPlayer() + end +end + ------------------------------------------------------------- -- Resource Variables for Items, Jobs, and Vehicles ------------------------------------------------------------- @@ -186,12 +193,12 @@ elseif isStarted(OXCoreExport) then end) else local TempJobs = triggerCallback(getScript()..":getOxGroups") - Jobs = TempJobs or {} + Jobs = {} for k, v in pairs(TempJobs) do local grades = {} - for i = 1, #v.grades do - grades[i] = { name = v.grades[i], isboss = (i == #v.grades) } - end + --for i = 1, #v.grades do + -- grades[i] = { name = v.grades[i], isboss = (i == #v.grades) } + --end Jobs[v.name] = { label = v.label, grades = grades } end Gangs = Jobs diff --git a/shared/drawText.lua b/shared/drawText.lua index 66b908e..1171958 100644 --- a/shared/drawText.lua +++ b/shared/drawText.lua @@ -64,6 +64,15 @@ function drawText(image, input, style, oxStyleTable) text = ''..text end ESX.TextUI(text, nil) + + elseif Config.System.drawText == "jim" then + for k, v in pairs(input) do + input[k] = v.."
" + end + exports["jim-nui"]:drawText({ + icon = nil, + text = text, + }) end end diff --git a/shared/input.lua b/shared/input.lua index 6c18958..efb84b5 100644 --- a/shared/input.lua +++ b/shared/input.lua @@ -39,15 +39,17 @@ function createInput(title, opts) local dialog = nil local options = {} - + local currentNum = 0 if Config.System.Menu == "ox" then for i = 1, #opts do + currentNum += 1 + if opts[i] == nil then currentNum -= 1 goto skip end if opts[i].type == "radio" then -- Convert radio options to select type for OX for k in pairs(opts[i].options) do opts[i].options[k].label = opts[i].options[k].text end - options[i] = { + options[currentNum] = { type = "select", isRequired = opts[i].isRequired, label = opts[i].label or opts[i].text, @@ -57,8 +59,8 @@ function createInput(title, opts) } end if opts[i].type == "number" then - options[i] = { - type = "number", + options[currentNum] = { + type = opts[i].type, label = (opts[i].label or opts[i].text)..(opts[i].txt and " - "..opts[i].txt or ""), isRequired = opts[i].isRequired, name = opts[i].name, @@ -66,7 +68,7 @@ function createInput(title, opts) } end if opts[i].type == "text" then - options[i] = { + options[currentNum] = { type = "input", label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""), default = opts[i].default, @@ -74,8 +76,8 @@ function createInput(title, opts) } end if opts[i].type == "select" then - options[i] = { - type = "select", + options[currentNum] = { + type = opts[i].type, label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""), isRequired = opts[i].isRequired, name = opts[i].name, @@ -85,6 +87,17 @@ function createInput(title, opts) default = opts[i].default, } end + + if opts[i].type == "color" then + options[currentNum] = { + type = opts[i].type, + label = opts[i].label, + isRequired = opts[i].isRequired, + format = opts[i].format, + default = opts[i].default, + } + end + ::skip:: end dialog = exports[OXLibExport]:inputDialog(title, options) return dialog diff --git a/shared/isAnimal.lua b/shared/isAnimal.lua index a50ec38..f99c118 100644 --- a/shared/isAnimal.lua +++ b/shared/isAnimal.lua @@ -10,6 +10,23 @@ When running client-side (not on the server), the module checks the player's Ped after they load. + Usage Examples: + -- Check if the player's Ped is an animal: + local animalStatus = isPedAnimal() + + -- Check if a given Ped is a cat: + if isCat(somePed) then print("This is a cat!") end + + -- Determine if a Ped is a dog and whether it's big or small: + local isDogFlag, isBig = isDog(somePed) + + -- Retrieve a flat list of all animal model hashes: + local allAnimalModels = getAnimalModels() + + File Separation Suggestion: + For scalability, consider separating this module into two files: + • AnimalDetection.lua (for functions and callbacks) + • AnimalPedsData.lua (for the AnimalPeds table) ]] -- Global animal classification flags. diff --git a/shared/notify.lua b/shared/notify.lua index b65a2a9..6d31689 100644 --- a/shared/notify.lua +++ b/shared/notify.lua @@ -61,6 +61,13 @@ function triggerNotify(title, message, type, src) else TriggerClientEvent(getScript()..":DisplayESXNotify", src, type, message) end + + elseif Config.System.Notify == "jim" then + if not src then + exports["jim-nui"]:Notify(type, message) + else + TriggerClientEvent("jim-nui:client:notify'", src, type, message) + end end end diff --git a/shared/playerfunctions.lua b/shared/playerfunctions.lua index 0bd647e..aa4454d 100644 --- a/shared/playerfunctions.lua +++ b/shared/playerfunctions.lua @@ -380,7 +380,8 @@ function hasJob(job, source, grade) if info.name == job then hasJobFlag = true end elseif isStarted(OXCoreExport) then - for k, v in pairs(exports[OXCoreExport]:GetPlayerData().groups) do + local info = OxPlayer.getGroups() + for k, v in pairs(info) do if k == job then hasJobFlag = true break end end @@ -482,7 +483,9 @@ function getPlayer(source) source = info.PlayerData.source, job = info.PlayerData.job.name, jobBoss = info.PlayerData.job.isboss, + jobInfo = info.PlayerData.job, gang = info.PlayerData.gang.name, + gangInfo = info.PlayerData.gang, gangBoss = info.PlayerData.gang.isboss, onDuty = info.PlayerData.job.onduty, account = info.PlayerData.charinfo.account, @@ -500,25 +503,10 @@ function getPlayer(source) source = info.source, job = info.job.name, jobBoss = info.job.isboss, + jobInfo = info.job, gang = info.gang.name, gangBoss = info.gang.isboss, - onDuty = info.job.onduty, - account = info.charinfo.account, - citizenId = info.citizenid, - } - else - local info = exports[QBExport]:GetPlayer(src).PlayerData - Player = { - firstname = info.charinfo.firstname, - lastname = info.charinfo.lastname, - name = info.charinfo.firstname.." "..info.charinfo.lastname, - cash = info.money["cash"], - bank = info.money["bank"], - source = info.source, - job = info.job.name, - jobBoss = info.job.isboss, - gang = info.gang.name, - gangBoss = info.gang.isboss, + gangInfo = info.gang, onDuty = info.job.onduty, account = info.charinfo.account, citizenId = info.citizenid, @@ -554,11 +542,23 @@ function getPlayer(source) bank = bank, } elseif isStarted(OXCoreExport) then - local info = exports[OXCoreExport]:GetPlayerData() + --local info = exports[OXCoreExport]:GetPlayerData() + Player = { - name = info.firstName.." "..info.lastName, + firstname = OxPlayer.get("firstName"), + lastname = OxPlayer.get("lastName"), + name = OxPlayer.get("firstName").." "..OxPlayer.get("lastName"), cash = exports[OXInv]:Search('count', "money"), bank = 0, + --source = info.source, + job = OxPlayer.getGroups(), + --jobBoss = info.job.isboss, + gang = OxPlayer.getGroups(), + --gangBoss = info.gang.isboss, + --onDuty = info.job.onduty, + --account = info.charinfo.account, + citizenId = OxPlayer.get("stateId"), + } elseif isStarted(QBXExport) then local info = exports[QBXExport]:GetPlayerData() @@ -571,8 +571,10 @@ function getPlayer(source) source = info.source, job = info.job.name, jobBoss = info.job.isboss, + jobInfo = info.job, gang = info.gang.name, gangBoss = info.gang.isboss, + gangInfo = info.gang, onDuty = info.job.onduty, account = info.charinfo.account, citizenId = info.citizenid, @@ -589,8 +591,10 @@ function getPlayer(source) source = info.source, job = info.job.name, jobBoss = info.job.isboss, + jobInfo = info.job, gang = info.gang.name, gangBoss = info.gang.isboss, + gangInfo = info.gang, onDuty = info.job.onduty, account = info.charinfo.account, citizenId = info.citizenid,