From fbc92aea41c7a84579fa8c399939586c27b16623 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 26 Jan 2024 19:02:02 +0000 Subject: [PATCH 1/4] update common functions to be smurter --- functions.lua | 51 +++++++++++++++++++++++++++++++++++++++++--------- fxmanifest.lua | 2 +- version.txt | 2 +- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/functions.lua b/functions.lua index 90fea12..870ab9a 100644 --- a/functions.lua +++ b/functions.lua @@ -10,18 +10,51 @@ end local time = 100 function loadModel(model) - if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end - while not HasModelLoaded(model) do if time > 0 then time -= 1 RequestModel(model) - else time = 1000 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") break end - Wait(10) end + if not IsModelValid(model) then print("^6Bridge^7: ^1ERROR^7: ^2Model^7 - '^6"..model.."^7' ^2does not exist in server") return + else + if not HasModelLoaded(model) then + if Config.System.Debug then + print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") + end + if lib then lib.requestModel(model, time) + else while not HasModelLoaded(model) and time > 0 do time -= 1 end end + if not HasModelLoaded(model) then time = 100 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") end + end + end +end +function unloadModel(model) if Config.System.Debug then print("^6Bridge^7: ^2Removing Model from memory cache^7: '^6"..model.."^7'") end SetModelAsNoLongerNeeded(model) end + +function loadAnimDict(animDict) + if not DoesAnimDictExist(animDict) then print("^6Bridge^7: ^1ERROR^7: ^2Anim Dictionary^7 - '^6"..animDict.."^7' ^2does not exist in server") return + else + if Config.System.Debug then print("^6Bridge^7: ^2Loading Anim Dictionary^7: '^6"..animDict.."^7'") end + if lib then lib.requestAnimDict(animDict, 100) + else while not HasAnimDictLoaded(animDict) do RequestAnimDict(animDict) Wait(5) end end + end +end +function unloadAnimDict(animDict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Anim Dictionary from memory cache^7: '^6"..animDict.."^7'") end RemoveAnimDict(animDict) end + +function loadPtfxDict(ptFxName) + if not HasNamedPtfxAssetLoaded(ptFxName) then + if Config.System.Debug then + if not HasNamedPtfxAssetLoaded(ptFxName) then + print("^6Bridge^7: ^2Loading Ptfx Dictionary^7: '^6"..ptFxName.."^7'") + end + end + if lib then lib.requestNamedPtfxAsset(ptFxName, 100) + else while not HasNamedPtfxAssetLoaded(ptFxName) do RequestNamedPtfxAsset(ptFxName) Wait(5) end end end end -function unloadModel(model) if Config.System.Debug then print("^6Bridge^7: ^2Removing Model^7: '^6"..model.."^7'") end SetModelAsNoLongerNeeded(model) end -function loadAnimDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Loading Anim Dictionary^7: '^6"..dict.."^7'") end while not HasAnimDictLoaded(dict) do RequestAnimDict(dict) Wait(5) end end -function unloadAnimDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Anim Dictionary^7: '^6"..dict.."^7'") end RemoveAnimDict(dict) end -function loadPtfxDict(dict) if Config.System.Debug then if not HasNamedPtfxAssetLoaded(dict) then print("^6Bridge^7: ^2Loading Ptfx Dictionary^7: '^6"..dict.."^7'") end end while not HasNamedPtfxAssetLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end function unloadPtfxDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Ptfx Dictionary^7: '^6"..dict.."^7'") end RemoveNamedPtfxAsset(dict) end -function loadTextureDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Loading Texture Dictionary^7: '^6"..dict.."^7'") end while not HasStreamedTextureDictLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end +function loadTextureDict(dict) + if not HasStreamedTextureDictLoaded(dict) then + if Config.System.Debug then + print("^6Bridge^7: ^2Loading Texture Dictionary^7: '^6"..dict.."^7'") + end + if lib then lib.requestStreamedTextureDict(textureDict, timeout) + else while not HasStreamedTextureDictLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end + end +end function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end diff --git a/fxmanifest.lua b/fxmanifest.lua index 0eeb09f..1b54e06 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim_Bridge" author "Jimathy" -version "1.0.9" +version "1.0.10" description "Framework Bridge By Jimathy" fx_version "cerulean" game "gta5" diff --git a/version.txt b/version.txt index ab7e7da..fb0df62 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.9 +1.0.10 From 6f413c555db8eab4acba6b8a85d1e73dc36013f8 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 26 Jan 2024 20:31:10 +0000 Subject: [PATCH 2/4] add basic canCarry function --- crafting.lua | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/crafting.lua b/crafting.lua index 11d494f..bf0262f 100644 --- a/crafting.lua +++ b/crafting.lua @@ -33,6 +33,15 @@ function craftingMenu(data) if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end local Menu, hasjob = {}, false local Recipes = data.craftable.Recipes + local tempCarryTable = {} + for i = 1, #Recipes do + for k in pairs(Recipes[i]) do + if k ~= "amount" and k ~= "job" and k ~= "gang" then + tempCarryTable[k] = Recipes[i].amount or 1 + end + end + end + local canCarryTable = triggerCallback(GetCurrentResourceName()..':server:canCarry', tempCarryTable) for i = 1, #Recipes do if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end for k, v in pairs(Recipes[i]) do @@ -51,14 +60,21 @@ function craftingMenu(data) itemTable[l] = b Wait(0) end + while not canCarryTable do Wait(0) end + print(json.encode(canCarryTable, {indent = true})) if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end if data.stashName then disable = not stashhasItem(stashItems, itemTable) else disable = not hasItem(itemTable) end - setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - "..tostring(k))..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") + setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - " .. tostring(k)) .. (Recipes[i]["amount"] > 1 and " x" .. Recipes[i]["amount"] or "") + if not disable then + if not canCarryTable[k] then setheader = setheader .. " 📦" + else setheader = setheader .. " ✔️" end + elseif not canCarryTable[k] then setheader = setheader .. " 📦" end Menu[#Menu + 1] = { - isMenuHeader = disable, + isMenuHeader = disable or not canCarryTable[k], icon = invImg(tostring(k)), - header = setheader, txt = settext, + header = setheader, + txt = settext, onSelect = function() local transdata = { item = k, craft = data.craftable.Recipes[i], craftable = data.craftable, coords = data.coords, stashName = data.stashName, onBack = data.onBack } if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end @@ -174,7 +190,6 @@ end RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName) local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName) - if stashName then local itemRemove = {} for k, v in pairs(craftable[ItemMake] or {}) do @@ -447,4 +462,62 @@ function stashhasItem(stashItems, items, amount) end for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end return true, hasTable +end + +if IsDuplicityVersion() then + if GetResourceState(OXLibExport):find("start") then + createCallback(GetCurrentResourceName()..':server:canCarry', function(source, itemTable) local result = canCarry(itemTable, source) return result end) + else + createCallback(GetCurrentResourceName()..':server:canCarry', function(source, cb, itemTable) local result = canCarry(itemTable, source) cb(result) end) + end +end + +function canCarry(itemTable, src) + print("checking if player can carry") + local resultTable = {} + if src then + if GetResourceState(OXInv):find("start") then + for k, v in pairs(itemTable) do + resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v) + end + + elseif GetResourceState(QSInv):find("start") then + for k, v in pairs(itemTable) do + resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v) + end + + elseif GetResourceState(CoreInv):find("start") then + --?? + + elseif GetResourceState(CodeMInv):find("start") then + for k, v in pairs(itemTable) do + local weight = Items[k].weight + resultTable[k] = exports[CodeMInv]:CanCarryItem(src, weight, v) + end + + elseif GetResourceState(OrigenInv):find("start") then + for k, v in pairs(itemTable) do + resultTable[k] = exports[OrigenInv]:canCarryItem(src, k, v) + end + + elseif GetResourceState(QBInv):find("start") then + local Player = Core.Functions.GetPlayer(src) + local items = Player.PlayerData.items + local weight, totalWeight = 0, 0 + if not items then return false end + for _, item in pairs(items) do weight += item.weight * item.amount end + totalWeight = tonumber(weight) + + for k, v in pairs(itemTable) do + local itemInfo = Items[k] + if not itemInfo and not Player.Offline then + triggerNotify(nil, 'Item does not exist', 'error', src) + resultTable[k] = true + else + resultTable[k] = (totalWeight + (Items[k]['weight'] * v)) <= 120000 + end + end + end + end + return resultTable end \ No newline at end of file From 5a2304b78535f935c871cdecdc778bf99743c10d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 26 Jan 2024 20:31:46 +0000 Subject: [PATCH 3/4] quick linting --- wrapper.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wrapper.lua b/wrapper.lua index f7e6def..14c1c72 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -1124,6 +1124,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true if ganginfo.name == job then hasJob = true if grade and not (grade <= ganginfo.grade.level) then hasJob = false end end + elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then local info = nil Core.Functions.GetPlayerData(function(PlayerData) @@ -1139,6 +1140,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true hasJob = true if grade and not (grade <= ganginfo.grade.level) then hasJob = false end end + else print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3exports^1.^2lua^7") end @@ -1157,6 +1159,7 @@ function getPlayer(source) local Player = {} cash = info.getMoney(), bank = info.getAccount("bank").money, } + elseif GetResourceState(OXCoreExport):find("start") then local file = ('imports/%s.lua'):format('server') local import = LoadResourceFile('ox_core', file) @@ -1168,6 +1171,7 @@ function getPlayer(source) local Player = {} cash = exports[OXInv]:Search(src, 'count', "money"), bank = 0, } + elseif GetResourceState(QBXExport):find("start") then local info = exports[QBXExport]:GetPlayer(src) Player = { @@ -1175,6 +1179,7 @@ function getPlayer(source) local Player = {} cash = exports[OXInv]:Search(src, 'count', "money"), bank = info.Functions.GetMoney("bank"), } + elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then if Core.Functions.GetPlayer ~= nil then -- support older qb-core functions local info = Core.Functions.GetPlayer(src).PlayerData @@ -1191,6 +1196,7 @@ function getPlayer(source) local Player = {} bank = info.money["bank"], } end + else print("^4ERROR^7: ^2No Core detected for getPlayer() ^7- ^2Check ^3exports^1.^2lua^7") end From b71ec146155f3b57c0f3497c1c019c9a3b9b7f64 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Sat, 27 Jan 2024 12:55:56 +0000 Subject: [PATCH 4/4] sendPhoneMail - mutli phone support --- wrapper.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/wrapper.lua b/wrapper.lua index 14c1c72..a2c82d1 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -1242,6 +1242,60 @@ function getPlayer(source) local Player = {} return Player end +function sendPhoneMail(data) local phoneResource = "" + if GetResourceState("gksphone"):find("start") then phoneResource = "gksphone" + exports["gksphone"]:SendNewMail(data) + + elseif GetResourceState("yflip-phone"):find("start") then phoneResource = "yflip-phone" + TriggerServerEvent(GetCurrentResourceName()..":yflip:SendMail", data) + + elseif GetResourceState("qs-smartphone"):find("start") then phoneResource = "qs-smartphone" + TriggerServerEvent('qs-smartphone:server:sendNewMail', data) + + elseif GetResourceState("qs-smartphone-pro"):find("start") then phoneResource = "qs-smartphone-pro" + TriggerServerEvent('phone:sendNewMail', data) + + elseif GetResourceState("roadphone"):find("start") then phoneResource = "roadphone" + data.message = data.message:gsub("%
", "\n") + exports['roadphone']:sendMail(data) + + elseif GetResourceState("lb-phone"):find("start") then phoneResource = "lb-phone" + TriggerServerEvent(GetCurrentResourceName()..":lbphone:SendMail", data) + + elseif GetResourceState("qb-phone"):find("start") then phoneResource = "qb-phone" + TriggerServerEvent('qb-phone:server:sendNewMail', data) + end + + if phoneResource ~= "" then if Config.System.Debug then print("^6Bridge^7[^3"..phoneResource.."^7]: ^2Sending mail to player") end + else print("^6Bridge^7: ^1ERROR ^2Sending mail to player ^7 - ^2No supported phone found") end +end + +RegisterNetEvent(GetCurrentResourceName()..":lbphone:SendMail", function(data) + local src = source + local phoneNumber = exports["lb-phone"]:GetEquippedPhoneNumber(src) + local emailAddress = exports["lb-phone"]:GetEmailAddress(phoneNumber) + exports["lb-phone"]:SendMail({ + to = emailAddress, + subject = data.subject, + message = data.message, + --[[attachments = { + "https://cdn.discordapp.com/attachments/1035667053115363349/1042500877426110474/upload.png", + },]] + actions = data.buttons, + }) +end) + +RegisterNetEvent(GetCurrentResourceName()..":yflip:SendMail", function(data) + local src = source + exports["yflip-phone"]:SendMail({ + title = data.subject, + sender = data.sender, + senderDisplayName = data.sender, + content = data.message, + actions = data.buttons, + }, 'source', src) +end) + function registerCommand(command, options) if GetResourceState(OXLibExport):find("start") then if Config.System.Debug then print("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) end