diff --git a/bridge/inventory/server.lua b/bridge/inventory/server.lua index 5390aa3..6783ead 100644 --- a/bridge/inventory/server.lua +++ b/bridge/inventory/server.lua @@ -1,47 +1,30 @@ Inventory = {} --- Framework -function GetPlayerFromId(source) - if GetResourceState('es_extended') == 'started' then - return ESX.GetPlayerFromId(source) - elseif GetResourceState('qb-core') == 'started' then - return QBCore.Functions.GetPlayer(source) - end -end - -function getInventory(player) - if GetResourceState('es_extended') == 'started' then - return player.getInventory() - elseif GetResourceState('qb-core') == 'started' then - return player.PlayerData.items - end -end - -if GetResourceState('ox_inventory') == 'started' then +if GetResourceState('ox_inventory') == 'started' then Inventory.GetWeapon = function(source, name) local data = exports.ox_inventory:GetCurrentWeapon(source) - if data then + if data then return 1, data else return 0 end end - Inventory.AddWeapon = function(source, data) + Inventory.AddWeapon = function(source, data) exports.ox_inventory:AddItem(source, data.weapon, 1, data.metadata, data.slot) end - Inventory.RemoveWeapon = function(source, data) + Inventory.RemoveWeapon = function(source, data) exports.ox_inventory:RemoveItem(source, data.weapon, 1, data.metadata, data.slot) end Inventory.CreateWeaponData = function(source, data, weaponData) - for k, v in pairs(weaponData) do + for k,v in pairs(weaponData) do data[k] = v end return data end -elseif GetResourceState('qb-inventory') == 'started' then +elseif GetResourceState('qb-inventory') == 'started' then Inventory.PlayerWeapons = {} Inventory.GetWeapon = function(source, name) @@ -57,37 +40,40 @@ elseif GetResourceState('qb-inventory') == 'started' then return 0 end - Inventory.AddWeapon = function(source, data) + Inventory.AddWeapon = function(source, data) local Player = QBCore.Functions.GetPlayer(source) Player.Functions.AddItem(data.name, 1, data.slot, data.info) end - Inventory.RemoveWeapon = function(source, data) + Inventory.RemoveWeapon = function(source, data) local Player = QBCore.Functions.GetPlayer(source) Player.Functions.RemoveItem(data.name, 1, data.slot) end Inventory.CreateWeaponData = function(source, data, weaponData) - for k, v in pairs(weaponData) do + for k,v in pairs(weaponData) do data[k] = v end return data end - + RegisterNetEvent('pickle_weaponthrowing:SetCurrentWeapon', function(weaponData) local source = source Inventory.PlayerWeapons[source] = weaponData - end) + end) + elseif GetResourceState('qs-inventory') == 'started' then - Inventory.PlayerWeapons = {} Inventory.GetWeapon = function(source, name) - local data = exports['qs-inventory']:GetCurrentWeapon(source) - if data then - return 1, data - else - return 0 + local data = exports['qs-inventory']:GetCurrentWeapon(source) + if data then + local item = exports['qs-inventory']:GetItemBySlot(source, data.slot) + if item and item.name:lower() == name:lower() then + exports['qs-inventory']:useItemSlot(source, item) + return 1, item + end end + return 0 end Inventory.AddWeapon = function(source, data) @@ -98,10 +84,11 @@ elseif GetResourceState('qs-inventory') == 'started' then exports['qs-inventory']:RemoveItem(source, data.name, 1, data.slot, nil) end - Inventory.CreateWeaponData = function(source, data, weaponData) + Inventory.CreateWeaponData = function(source, data, weaponData) for k, v in pairs(weaponData) do data[k] = v end return data - end + end + end