forked from Simnation/Main
ed
This commit is contained in:
parent
875c8448e1
commit
c81ae4bb6d
219 changed files with 8036 additions and 7 deletions
93
resources/[tools]/bl_bridge/server/inventory/qs.lua
Normal file
93
resources/[tools]/bl_bridge/server/inventory/qs.lua
Normal file
|
@ -0,0 +1,93 @@
|
|||
local utils = require 'utils'
|
||||
local retreiveExportsData = utils.retreiveExportsData
|
||||
local overrideFunction = {}
|
||||
local registeredInventories = {}
|
||||
local qs_inventory = exports['qs-inventory']
|
||||
|
||||
overrideFunction.methods = retreiveExportsData(qs_inventory, {
|
||||
addItem = {
|
||||
originalMethod = 'AddItem',
|
||||
modifier = {
|
||||
passSource = true,
|
||||
effect = function(originalFun, src, name, amount, metadata, slot)
|
||||
return originalFun(src, name, amount, slot, metadata)
|
||||
end
|
||||
}
|
||||
},
|
||||
removeItem = {
|
||||
originalMethod = 'RemoveItem',
|
||||
modifier = {
|
||||
passSource = true,
|
||||
}
|
||||
},
|
||||
setMetaData = {
|
||||
originalMethod = 'SetItemMetadata',
|
||||
modifier = {
|
||||
passSource = true,
|
||||
}
|
||||
},
|
||||
canCarryItem = {
|
||||
originalMethod = 'CanCarryItem',
|
||||
modifier = {
|
||||
passSource = true,
|
||||
}
|
||||
},
|
||||
getItem = {
|
||||
originalMethod = 'GetItemByName',
|
||||
modifier = {
|
||||
passSource = true, -- Src doesn't actually seem to be passed to originalFunc
|
||||
effect = function(originalFunc, src, itemName)
|
||||
local data = originalFunc(src, itemName)
|
||||
if not data then
|
||||
return false, 'Item does not exist or you don\'t have it'
|
||||
end
|
||||
return {
|
||||
label = data.label,
|
||||
name = data.name,
|
||||
weight = data.weight,
|
||||
slot = data.slot,
|
||||
close = data.shouldClose,
|
||||
stack = not data.unique,
|
||||
metadata = data.info ~= '' and data.info or {},
|
||||
count = data.amount or 1
|
||||
}
|
||||
end
|
||||
}
|
||||
},
|
||||
items = {
|
||||
originalMethod = 'GetInventory',
|
||||
modifier = {
|
||||
passSource = true,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
function overrideFunction.registerInventory(id, data)
|
||||
local type, name, items, slots, maxWeight in data
|
||||
|
||||
for k,v in ipairs(items) do
|
||||
v.amount = v.amount or 10
|
||||
v.slot = k
|
||||
end
|
||||
|
||||
registeredInventories[('%s-%s'):format(type, id)] = {
|
||||
label = name,
|
||||
items = items,
|
||||
slots = slots or #items,
|
||||
maxweight = maxWeight
|
||||
}
|
||||
end
|
||||
|
||||
function overrideFunction.registerUsableItem(name, cb)
|
||||
qs_inventory:CreateUsableItem(name, function(source, item)
|
||||
cb(source, item and item.slot, item and item.info)
|
||||
end)
|
||||
end
|
||||
|
||||
utils.register('bl_bridge:validInventory', function(_, invType, invId)
|
||||
local inventory = registeredInventories[('%s-%s'):format(invType, invId)]
|
||||
if not inventory then return end
|
||||
return inventory
|
||||
end)
|
||||
|
||||
return overrideFunction
|
Loading…
Add table
Add a link
Reference in a new issue