diff --git a/crafting.lua b/crafting.lua index 827ec1c..e111938 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 @@ -405,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 diff --git a/functions.lua b/functions.lua index bf6ba62..0ccd45a 100644 --- a/functions.lua +++ b/functions.lua @@ -15,8 +15,9 @@ 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) and time > 0 do time -= 1 RequestModel(model) Wait(0) end - if not HasModelLoaded(model) then time = 500 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") 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 @@ -58,7 +59,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 +229,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 +241,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 +272,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 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 diff --git a/wrapper.lua b/wrapper.lua index b5c40ed..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 @@ -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()