Skip to content

Commit

Permalink
Merge pull request #24 from Scartane/feat/scn/core_inventory-integration
Browse files Browse the repository at this point in the history
feat(core): Add core inventory integration
  • Loading branch information
PickleModifications authored Dec 14, 2024
2 parents cc8e7b8 + 7e497c5 commit 01c77a0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bridge/inventory/client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
if GetResourceState('qb-inventory') == 'started' then
if GetResourceState('qb-inventory') == 'started' then
RegisterNetEvent('inventory:client:UseWeapon', function(weaponData, shootbool)
TriggerServerEvent("pickle_weaponthrowing:SetCurrentWeapon", weaponData)
end)
end
end

if GetResourceState('core_inventory') == 'started' then
RegisterNetEvent('core_inventory:client:handleWeapon', function(currentWeapon, currentWeaponData, currentWeaponInventory)
TriggerServerEvent("pickle_weaponthrowing:SetCurrentWeapon", currentWeaponData, currentWeaponInventory)
end)
end
45 changes: 45 additions & 0 deletions bridge/inventory/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,49 @@ elseif GetResourceState('qs-inventory') == 'started' then
end
return data
end
elseif GetResourceState('core_inventory') == 'started' then
Inventory.PlayerWeapons = {}

Inventory.GetWeapon = function(source, name)
local data = Inventory.PlayerWeapons[source]
if data then
return 1, data
else
return 0
end
end

Inventory.CreateWeaponData = function(source, data, weaponData)
for k,v in pairs(weaponData) do
data[k] = v
end
return data
end

Inventory.AddWeapon = function(source, data)
local result = exports.core_inventory:addItem(source, data.name, 1, data.metadata, 'content')
if result then
TriggerClientEvent('core_inventory:client:notification', source, data.name, 'add', 1)
end
return result
end

Inventory.RemoveWeapon = function(source, data)
local result = exports.core_inventory:removeItem(data.currentInventory, data.name, 1, nil)
if result then
TriggerClientEvent('core_inventory:client:notification', source, data.name, 'remove', 1)
TriggerClientEvent('core_inventory:client:inventoryCleared', source, data.currentInventory)
end
return result
end

RegisterNetEvent('pickle_weaponthrowing:SetCurrentWeapon', function(weaponData, weaponInventory)
local source = source
if weaponData then
weaponData.defaultData = weaponData
weaponData.currentInventory = weaponInventory
weaponData.weapon = weaponData.name
end
Inventory.PlayerWeapons[source] = weaponData
end)
end

0 comments on commit 01c77a0

Please sign in to comment.