From 37028359582a2a456494b8f9b1b24b3c413af5a1 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:34:17 +0000 Subject: [PATCH 1/7] Added sellMenu() --- crafting.lua | 81 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/crafting.lua b/crafting.lua index 827ec1c..9ccf453 100644 --- a/crafting.lua +++ b/crafting.lua @@ -75,7 +75,7 @@ function craftingMenu(data) 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 } + 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 end, } @@ -137,7 +137,6 @@ function makeItem(data) local crafted, crafting = true, true local cam = createTempCam(PlayerPedId(), data.coords) startTempCam(cam) - for i = 1, amount do for k, v in pairs(data.craft) do if k ~= "amount" and k ~= "job" then @@ -209,6 +208,80 @@ RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMak end) --[[SHOPS]]-- +function sellMenu(data) + local origData = data + local Menu = {} + if data.sellTable.Items then + local itemList = {} + for k, v in pairs(data.sellTable.Items) do itemList[k] = 1 end + local hasitems, hasTable = hasItem(itemList) + for k, v in pairsByKeys(data.sellTable.Items) do + Menu[#Menu +1] = { + isMenuHeader = not hasTable[k].hasItem, + icon = invImg(k), + header = Items[k].label.. (hasTable[k].hasItem and "💰 (x"..hasTable[k].count..")" or ""), + txt = Loc[Config.Lan].info["sell_all"].." "..v.." "..Loc[Config.Lan].info["sell_each"], + onSelect = function() + sellAnim({ item = k, price = v, ped = data.ped, onBack = function() sellMenu(data) end }) + end, + } + end + else + for k, v in pairsByKeys(data.sellTable) do + if type(v) == "table" then + Menu[#Menu +1] = { + arrow = true, + header = k, + txt = "Amount of items: "..countTable(v.Items), + onSelect = function() + v.onBack = function() sellMenu(origData) end + v.sellTable = data.sellTable[k] + sellMenu(v) + end, + } + end + end + end + openMenu(Menu, { header = data.sellTable.Header or "Amount of items: "..countTable(data.sellTable.Items), canClose = true, onBack = data.onBack }) +end + +function sellAnim(data) + if not hasItem(data.item, 1) then + triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error") + return + end + for k, v in pairs(GetGamePool('CObject')) do + for _, model in pairs({`p_cs_clipboard`}) do + if GetEntityModel(v) == model then + if IsEntityAttachedToEntity(data.ped, v) then + DeleteObject(v) DetachEntity(v, 0, 0) SetEntityAsMissionEntity(v, true, true) + Wait(100) DeleteEntity(v) + end + end + end + end + TriggerServerEvent(GetCurrentResourceName().."Sellitems", data) -- Had to slip in the sell command during the animation command + lookEnt(data.ped) + local dict = "mp_common" + playAnim(dict, "givetake2_a", 0.3, 2) + playAnim(dict, "givetake2_b", 0.3, 2, data.ped) + Wait(2000) + StopAnimTask(PlayerPedId(), dict, "givetake2_a", 0.5) + StopAnimTask(data.ped, dict, "givetake2_b", 0.5) + if data.onBack then data.onBack() end +end + +RegisterNetEvent(GetCurrentResourceName().."Sellitems", function(data) + local src = source + local hasItems, hasTable = hasItem(data.item, 1, src) + if hasItems then + TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, data.item, hasTable[data.item].count, src) + TriggerEvent(GetCurrentResourceName()..":server:FundPlayer", (hasTable[data.item].count * data.price), "cash", src) + else + triggerNotify(nil,Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error", src) + end +end) + function openShop(data) if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end if GetResourceState(OXInv):find("start") then @@ -236,7 +309,7 @@ function hasItem(items, amount, src) local amount = amount and amount or 1 elseif GetResourceState(OrigenInv):find("start") then foundInv = OrigenInv - if src then grabInv = exports[OrigenInv]:getPlayerInventory(src) + if src then grabInv = exports[OrigenInv]:GetInventory(src) else grabInv = exports[OrigenInv]:getPlayerInventory() end elseif GetResourceState(CoreInv):find("start") then @@ -316,7 +389,7 @@ function getStash(stashName) local stashResource = "" stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv - stashItems = exports[OrigenInv]:GetStashItems(stashName) +stashItems = exports[OrigenInv]:GetStashItems(stashName) elseif GetResourceState(QBInv):find("start") then stashResource = QBInv local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) From f8e3f6490774211a46282057b0aa829ce27c4946 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:35:54 +0000 Subject: [PATCH 2/7] Origen Inv Fixes --- crafting.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crafting.lua b/crafting.lua index 9ccf453..e111938 100644 --- a/crafting.lua +++ b/crafting.lua @@ -389,7 +389,7 @@ function getStash(stashName) local stashResource = "" stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv -stashItems = exports[OrigenInv]:GetStashItems(stashName) + stashItems = exports[OrigenInv]:GetStashItems(stashName) elseif GetResourceState(QBInv):find("start") then stashResource = QBInv local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) @@ -478,7 +478,7 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and elseif GetResourceState(OrigenInv):find("start") then for k, v in pairs(items) do - exports[OrigenInv]:RemoveItem(stashName, k, v) + exports[OrigenInv]:RemoveFromStash(stashName, nil, k, v) if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OrigenInv, k, v) end end From 4d1b2abd3d90205ba29d7a470fa3126dbb9e0572 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:37:14 +0000 Subject: [PATCH 3/7] blip_info support preview imgs --- functions.lua | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/functions.lua b/functions.lua index bf6ba62..0d398b8 100644 --- a/functions.lua +++ b/functions.lua @@ -14,7 +14,7 @@ function loadModel(model) else if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end - while not HasModelLoaded(model) and time > 0 do time -= 1 RequestModel(model) Wait(0) end + while not HasModelLoaded(model) and time > 0 do time -= 1 RequestModel(model) print(time) Wait(0) end if not HasModelLoaded(model) then time = 500 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") end end end @@ -58,7 +58,8 @@ function playAnim(animDict, animName, duration, flag, ped) end function stopAnim(animDict, animName, ped) - StopAnimTask(ped and ped or PlayerPedId(), animName, animDict) + StopAnimTask(ped or PlayerPedId(), animDict, animName, 0.5) + StopAnimTask(ped or PlayerPedId(), animName, animDict, 0.5) unloadAnimDict(animDict) end @@ -227,8 +228,9 @@ function ensureNetToVeh(vehNetID) return vehicle end +local previewTxd = CreateRuntimeTxd(GetCurrentResourceName()..'previewTxd') function makeBlip(data) - local blip = AddBlipForCoord(data.coords) + local blip = AddBlipForCoord(vec3(data.coords.x, data.coords.y, data.coords.z)) SetBlipAsShortRange(blip, true) SetBlipSprite(blip, data.sprite or 106) SetBlipColour(blip, data.col or 5) @@ -238,8 +240,23 @@ function makeBlip(data) BeginTextCommandSetBlipName('STRING') AddTextComponentString(tostring(data.name)) EndTextCommandSetBlipName(blip) + if GetResourceState("blip_info"):find("start") or GetResourceState("blip-info"):find("start") or GetResourceState("blipinfo"):find("start") then + if data.preview then + local txname = tostring('preview'..keyGen()..keyGen()) + if data.preview:find("http") then + local newTxt = CreateDui(data.preview, 512, 256) + local duihandle = GetDuiHandle(newTxt) + while not GetDuiHandle(newTxt) do Wait(0) end + CreateRuntimeTextureFromDuiHandle(previewTxd, txname, duihandle) + else + CreateRuntimeTextureFromImage(previewTxd, txname, data.preview) + end + exports["blip_info"]:SetBlipInfoImage(blip, GetCurrentResourceName()..'previewTxd', txname) + exports["blip_info"]:SetBlipInfoTitle(blip, data.name, false) + end + end if Config.System.Debug then print("^6Bridge^7: ^6Blip ^2created for location^7: '^6"..data.name.."^7'") end - return blip + return blip end function makeEntityBlip(data) @@ -254,6 +271,21 @@ function makeEntityBlip(data) BeginTextCommandSetBlipName('STRING') AddTextComponentString(tostring(data.name)) EndTextCommandSetBlipName(blip) + if GetResourceState("blip_info"):find("start") or GetResourceState("blip-info"):find("start") or GetResourceState("blipinfo"):find("start") then + if data.preview then + local txname = tostring('preview'..keyGen()..keyGen()) + if data.preview:find("http") then + local newTxt = CreateDui(data.preview, 512, 256) + local duihandle = GetDuiHandle(newTxt) + while not GetDuiHandle(newTxt) do Wait(0) end + CreateRuntimeTextureFromDuiHandle(previewTxd, txname, duihandle) + else + CreateRuntimeTextureFromImage(previewTxd, txname, data.preview) + end + exports["blip_info"]:SetBlipInfoImage(blip, GetCurrentResourceName()..'previewTxd', txname) + exports["blip_info"]:SetBlipInfoTitle(blip, data.name, false) + end + end if Config.System.Debug then print("^6Bridge^7: ^6Blip ^2created for Entity^7: '^6"..data.name.."^7'") end return blip end From 9ae034da77fdfaceac6de378598273de6499828e Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:38:11 +0000 Subject: [PATCH 4/7] remove unused variable --- wrapper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper.lua b/wrapper.lua index b5c40ed..c2577de 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -56,7 +56,7 @@ else end -- Load Vehicles -if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then vehResource = QBExport +if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then Core = Core or exports[QBExport]:GetCoreObject() if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then RegisterNetEvent('QBCore:Client:UpdateObject', function() From f7b7718679630f0ca10619dd9dd3d05be588822d Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:38:22 +0000 Subject: [PATCH 5/7] remove unused variable --- wrapper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper.lua b/wrapper.lua index c2577de..d7d3b3a 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -26,7 +26,7 @@ for k, v in pairs(Exports) do if GetResourceState(v):find("start") then print("^6Bridge^7: '^3"..v.."^7' ^2export found ^7") end end -local itemResource, vehResource, jobResource = "", "", "" +local itemResource, jobResource = "", "" -- Load item lists if GetResourceState(OXInv):find("start") then itemResource = OXInv From 6a23e4ac912901d1c3dc605edd833ecfe6f6d3cf Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:39:02 +0000 Subject: [PATCH 6/7] Move loadModel time reset --- functions.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/functions.lua b/functions.lua index 0d398b8..0ccd45a 100644 --- a/functions.lua +++ b/functions.lua @@ -14,9 +14,10 @@ function loadModel(model) else if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end - while not HasModelLoaded(model) and time > 0 do time -= 1 RequestModel(model) print(time) Wait(0) end - if not HasModelLoaded(model) then time = 500 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") end + while not HasModelLoaded(model) and time > 0 do time -= 1 RequestModel(model) Wait(0) end + if not HasModelLoaded(model) then print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") end end + time = 500 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 From 0886d8a4b6fcc3119bff1f16f2cd7e40d32cd00c Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Thu, 8 Feb 2024 18:39:30 +0000 Subject: [PATCH 7/7] Version Bump --- fxmanifest.lua | 2 +- version.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index aa85d32..9647732 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,6 +1,6 @@ name "Jim_Bridge" author "Jimathy" -version "1.0.11" +version "1.0.12" description "Framework Bridge By Jimathy" fx_version "cerulean" game "gta5" diff --git a/version.txt b/version.txt index 4a83f81..24334aa 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.11 +1.0.12