Merge pull request #13 from jimathy/1.0.6

1.0.6
This commit is contained in:
Jim Shield
2024-01-23 00:37:55 +00:00
committed by GitHub
6 changed files with 138 additions and 41 deletions

View File

@@ -242,10 +242,29 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
else grabInv = exports[QSInv]:getUserInventory()
end
elseif GetResourceState(OrigenInv):find("start") then
foundInv = OrigenInv
if src then
grabInv = exports[OrigenInv]:getPlayerInventory(src)
else
grabInv = exports[OrigenInv]:getPlayerInventory()
end
elseif GetResourceState(CoreInv):find("start") then
foundInv = CoreInv
if src then grabInv = exports['core_inventory']:getInventory('primary-'..src)
else grabInv = exports[CoreInv]:getInventory('primary-'..GetPlayerServerId(PlayerPedId()))
if src then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
elseif GetResourceState(ESXExport):find("start") then
local Player = ESX.GetPlayerFromId(src)
grabInv = Player.getInventory(false)
end
else
local p = promise.new()
Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end)
local result = Citizen.Await(p)
if type(result) == "string" then result = json.decode(result) end
grabInv = result
end
elseif GetResourceState(CodeMInv):find("start") then
@@ -305,16 +324,27 @@ end
function getStash(stashName)
local stashItems, items = {}, {}
if GetResourceState(OXInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7ox_inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OXInv) end
stashItems = exports[OXInv]:Inventory(stashName).items
elseif GetResourceState(QSInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QSInv) end
stashItems = exports[QSInv]:GetStashItems(stashName)
elseif GetResourceState(CoreInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CoreInv) end
stashItems = exports[CoreInv]:getInventory(stashName)
elseif GetResourceState(CodeMInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CodeMInv) end
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
elseif GetResourceState(OrigenInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OrigenInv) end
stashItems = exports[OrigenInv]:GetStash(stashName)
elseif GetResourceState(QBInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qb-inventory") end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QBInv) end
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end
end
@@ -322,18 +352,18 @@ function getStash(stashName)
for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()]
if itemInfo then
items[item.slot] = {
name = itemInfo["name"],
items[#items+1] = {
name = itemInfo["name"] ~= nil and itemInfo["slot"] or nil,
amount = tonumber(item.amount) or tonumber(item.count),
info = item.info ~= nil and item.info or "",
label = itemInfo["label"],
label = itemInfo["label"] ~= nil and itemInfo["slot"] or nil,
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
weight = itemInfo["weight"] ~= nil and itemInfo["slot"] or nil,
type = itemInfo["type"] ~= nil and itemInfo["slot"] or nil,
unique = itemInfo["unique"] ~= nil and itemInfo["slot"] or nil,
useable = itemInfo["useable"] ~= nil and itemInfo["slot"] or nil,
image = itemInfo["image"] ~= nil and itemInfo["slot"] or nil,
slot = itemInfo["slot"] ~= nil and itemInfo["slot"] or nil,
}
end
end
@@ -349,23 +379,30 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end
end
elseif GetResourceState(QSInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
for k, v in pairs(items) do
for l in pairs(stashItems) do
if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
end
end
elseif GetResourceState(CoreInv):find("start") then
for k, v in pairs(items) do
exports[CoreInv]:removeItemExact(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CoreInv, k, v) end
end
elseif GetResourceState(CodeMInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
@@ -387,6 +424,13 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then
print("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
end
elseif GetResourceState(OrigenInv):find("start") then
for k, v in pairs(items) do
exports[OrigenInv]:RemoveItem(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OrigenInv, k, v) end
end
elseif GetResourceState(QBInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do

View File

@@ -7,8 +7,9 @@ Exports = {
OXInv = "ox_inventory",
QBInv = "qb-inventory",
QSInv = "qs-inventory",
CoreInv = "core-inventory",
CoreInv = "core_inventory",
CodeMInv = "codem-inventory",
OrigenInv = "origen_inventory",
OXLibExport = "ox_lib",

View File

@@ -513,7 +513,7 @@ function setThirst(src, thirst)
if GetResourceState(ESXExport):find("start") then
TriggerClientEvent('esx_status:add', src, 'thirst', thirst)
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
local Player = QBCore.Functions.GetPlayer(src)
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('thirst', thirst)
TriggerClientEvent("hud:client:UpdateNeeds", src, thirst, Player.PlayerData.metadata.thirst)
end
@@ -523,7 +523,7 @@ function setHunger(src, hunger)
if GetResourceState(ESXExport):find("start") then
TriggerClientEvent('esx_status:add', src, 'hunger', hunger)
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
local Player = QBCore.Functions.GetPlayer(src)
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('hunger', hunger)
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.hunger)
end
@@ -586,21 +586,35 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QSInv):find("start") then
local success = exports[QSInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CoreInv):find("start") then
local success = exports[CoreInv]:removeItemExact('primary-'..src, item, amount)
elseif GetResourceState(CoreInv):find("start") then
if GetResourceState(QBExport):find("start") then
Core.Functions.GetPlayer(src).Functions.RemoveItem(item, amount, nil)
elseif GetResourceState(ESXExport):find("start") then
ESX.GetPlayerFromId(src).removeInventoryItem(item, count)
end
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
elseif GetResourceState(OrigenInv):find("start") then
local success = exports[OrigenInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OrigenInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
local success = exports[CodeMInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QBInv):find("start") then
while remamount > 0 do
if Core.Functions.GetPlayer(src).Functions.RemoveItem(item, 1) then end
@@ -625,21 +639,35 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QSInv):find("start") then
local success = exports[QSInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CoreInv):find("start") then
local success = exports[CoreInv]:addItem('primary-'..src, item, amount)
if Config.System.Debug then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
Core.Functions.GetPlayer(src).Functions.AddItem(item, amount, nil, nil)
elseif GetResourceState(ESXExport):find("start") then
ESX.GetPlayerFromId(src).addInventoryItem(item, amount)
end
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
local success = exports[CodeMInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(OrigenInv):find("start") then
local success = exports[OrigenInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OrigenInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QBInv):find("start") then
if Core.Functions.GetPlayer(src).Functions.AddItem(item, amount or 1) then
--if Config.Crafting.showItemBox then
@@ -649,6 +677,7 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QBInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
end

View File

@@ -1,6 +1,6 @@
name "Jim_Bridge"
author "Jimathy"
version "1.0.5"
version "1.0.6"
description "Framework Bridge By Jimathy"
fx_version "cerulean"
game "gta5"

View File

@@ -1 +1 @@
1.0.5
1.0.6

View File

@@ -1,5 +1,8 @@
Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil
if GetResourceState("ps-inventory"):find("start") then Exports.QBInv = "ps-inventory" end
if GetResourceState("lj-inventory"):find("start") then Exports.QBInv = "lj-inventory" end
OXLibExport = Exports and Exports.OXLibExport or ""
QBXExport = Exports and Exports.QBXExport or ""
@@ -12,6 +15,7 @@ QBInv = Exports and Exports.QBInv or ""
QSInv = Exports and Exports.QSInv or ""
CoreInv = Exports and Exports.CoreInv or ""
CodeMInv = Exports and Exports.CodeMInv or ""
OrigenInv = Exports and Exports.OrigenInv or ""
QBMenuExport = Exports and Exports.QBMenuExport or ""
@@ -223,16 +227,19 @@ end
function openMenu(Menu, data)
if Config.System.Menu == "ox" then
if data.onBack then
local index = nil
if data.onBack and not data.onSelected then
table.insert(Menu, 1, { icon = "fas fa-circle-arrow-left",
title = "Return",
onSelect = data.onBack,
label = "Return"
})
end
for k in pairs(Menu) do
if not Menu[k].title then
if Menu[k].header ~= nil and Menu[k].header ~= "" then
Menu[k].title = Menu[k].header
Menu[k].label = Menu[k].header
if Menu[k].txt then Menu[k].description = Menu[k].txt else Menu[k].description = "" end
else
Menu[k].title = Menu[k].txt
@@ -246,8 +253,22 @@ function openMenu(Menu, data)
Menu[k].disabled = true
end
end
lib.registerContext({id = 'Menu', title = data.header..br..br..(data.headertxt and data.headertxt or ""), position = 'top-right', options = Menu, canClose = data.canClose and data.canClose or nil, onExit = data.onExit and data.onExit or nil, })
lib.showContext("Menu")
local menuID = 'Menu'
(data.onSelected and lib.registerMenu or lib.registerContext)({
id = menuID,
title = data.header..br..br..(data.headertxt and data.headertxt or ""),
position = 'top-right',
options = Menu,
canClose = data.canClose and data.canClose or nil,
onClose = (data.onBack and data.onBack) or (data.onExit and data.onExit) or nil,
onExit = data.onExit and data.onExit or nil,
onSelected = data.onSelected and (function(selected) index = selected end) or nil,
}, (data.onSelected and (function(x, y, args) Menu[x].onSelect() end) or nil))
if data.onSelected then
lib.showMenu(menuID, 1)
else
lib.showContext(menuID)
end
elseif Config.System.Menu == "qb" then
if data.onBack then
table.insert(Menu, 1, { icon = "fas fa-circle-arrow-left",
@@ -750,7 +771,7 @@ function createInput(title, opts)
isRequired = opts[i].isRequired,
label = opts[i].label or opts[i].text,
name = opts[i].name,
default = opts[i].options[1].value,
default = opts[i].default or opts[i].options[1].value,
options = opts[i].options,
}
end
@@ -1240,6 +1261,8 @@ function invImg(item)
imgLink = "nui://"..QSInv.."/html/images/"..(Items[item].image or "")
elseif GetResourceState(CoreInv and CoreInv or ""):find("start") then
imgLink = "nui://"..CoreInv.."/html/img/"..(Items[item].image or "")
elseif GetResourceState(OrigenInv and OrigenInv or ""):find("start") then
imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "")
elseif GetResourceState(QBInv and QBInv or ""):find("start") then
imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "")
else