256 changes: 256 additions & 0 deletions data/qbitem_install.lua
@@ -0,0 +1,256 @@
return {
burger = {
name = "burger",
weight = 50,
image = "burger.png",
shouldClose = true,
label = "Burger",
useable = true,
type = "item",
},
water = {
name = "water",
weight = 50,
image = "water.png",
shouldClose = true,
label = "Water",
useable = true,
type = "item",
},
coffee = {
name = "coffee",
weight = 50,
image = "coffee.png",
shouldClose = true,
label = "Coffee",
useable = true,
type = "item",
},

donut = {
name = "donut",
weight = 50,
image = "donut.png",
shouldClose = true,
label = "Donut",
useable = true,
type = "item",
},

sandwich = {
name = "sandwich",
weight = 50,
image = "sandwich.png",
shouldClose = true,
label = "Sandwich",
useable = true,
type = "item",
},
ground_beef = {
name = "ground_beef",
weight = 50,
image = "ground_beef.png",
shouldClose = "true",
label = "Ground Beef",
useable = "true",
type = "item",
},
taco = {
name = "taco",
weight = 50,
image = "taco.png",
shouldClose = "true",
label = "Taco",
useable = "true",
type = "item",
},
hotdogsandwich = {
name = "hotdogsandwich",
weight = 350,
image = "hotdogsandwich.png",
shouldClose = "true",
label = "Hot Dog Sandwich",
useable = "true",
type = "item",
},
onion = {
name = "onion",
weight = 50,
image = "onion.png",
shouldClose = "true",
label = "Onion",
useable = "true",
type = "item",
},
beef = {
name = "beef",
weight = 50,
image = "beef.png",
shouldClose = "true",
label = "Beef",
useable = "true",
type = "item",
},
bread = {
name = "bread",
weight = 50,
image = "bread.png",
shouldClose = "true",
label = "Bread",
useable = "true",
type = "item",
},
cheese = {
name = "cheese",
weight = 50,
image = "cheese.png",
shouldClose = "true",
label = "Cheese",
useable = "true",
type = "item",
},
hotsauce = {
name = "hotsauce",
weight = 50,
image = "hotsauce.png",
shouldClose = "true",
label = "Hot Sauce",
useable = "true",
type = "item",
},
latte = {
name = "latte",
weight = 50,
image = "latte.png",
shouldClose = "true",
label = "Latte",
useable = "true",
type = "item",
},
hotdog = {
name = "hotdog",
weight = 50,
image = "hotdog.png",
shouldClose = "true",
label = "Hotdog",
useable = "true",
type = "item",
},
pasta = {
name = "pasta",
weight = 50,
image = "pasta.png",
shouldClose = "true",
label = "Pasta",
useable = "true",
type = "item",
},
mayonaise = {
name = "mayonaise",
weight = 50,
image = "mayonaise.png",
shouldClose = "true",
label = "Mayonaise",
useable = "true",
type = "item",
},
chicken = {
name = "chicken",
weight = 50,
image = "chicken.png",
shouldClose = "true",
label = "Chicken",
useable = "true",
type = "item",
},
item = {
name = "item",
weight = 50,
image = "item.png",
shouldClose = "true",
label = "Default Item",
useable = "true",
type = "item",
},
tacosauce = {
name = "tacosauce",
weight = 50,
image = "tacosauce.png",
shouldClose = "true",
label = "Tacosauce",
useable = "true",
type = "item",
},
fish = {
name = "fish",
weight = 50,
image = "fish.png",
shouldClose = "true",
label = "Fish",
useable = "true",
type = "item",
},
tacoshells = {
name = "tacoshells",
weight = 50,
image = "tacoshells.png",
shouldClose = "true",
label = "Taco Shells",
useable = "true",
type = "item",
},
burgerpatty = {
name = "burgerpatty",
weight = 50,
image = "burgerpatty.png",
shouldClose = "true",
label = "Burger Patty",
useable = "true",
type = "item",
},
tomatosauce = {
name = "tomatosauce",
weight = 50,
image = "tomatosauce.png",
shouldClose = "true",
label = "Tomato Sauce",
useable = "true",
type = "item",
},
tomato = {
name = "tomato",
weight = 50,
image = "tomato.png",
shouldClose = "true",
label = "Tomato",
useable = "true",
type = "item",
},
sprunk = {
name = "sprunk",
weight = 50,
image = "sprunk.png",
shouldClose = "true",
label = "Sprunk",
useable = "true",
type = "item",
},
lettuce = {
name = "lettuce",
weight = 50,
image = "lettuce.png",
shouldClose = "true",
label = "Lettuce",
useable = "true",
type = "item",
},
martini = {
name = "martini",
weight = 50,
image = "martini.png",
shouldClose = "true",
label = "Martini",
useable = "true",
type = "item",
},
}
45 changes: 28 additions & 17 deletions init.lua
@@ -1,6 +1,8 @@
ESX,QBCORE = nil, nil
shared = {}
shared.framework = 'ESX' -- ESX || QBCORE
shared.inventory = 'ox_inventory' -- 'ox_inventory' or 'qb-inventory' -- QBCORE is BETA and WIP, will only work with my qb-inventory forked https://github.com/renzuzu/qb-inventory

-- use ox_inventory Shops UI (experimental feature) only with my forked ox_inventory REPO https://github.com/renzuzu/ox_inventory
shared.oxShops = false -- if true this resource will use ox_inventory Shops UI instead of built in UI
shared.allowplayercreateitem = false -- if false only admin can create new items via /stores
Expand Down Expand Up @@ -111,6 +113,13 @@ if not IsDuplicityVersion() then
Shops = setmetatable(Shops, {
__call = function(self)
self = request('client/main')
self.ImagesPath = function(item)
if shared.inventory == 'ox_inventory' then
return 'https://cfx-nui-ox_inventory/web/images/'..item..'.png'
else
return 'https://cfx-nui-qb-inventory/html/images/'..item..'.png'
end
end
self.LoadJobShops = function()
for k,zones in pairs(self.JobSpheres) do
if zones then
Expand All @@ -124,7 +133,7 @@ if not IsDuplicityVersion() then
local jobshop = GlobalState.JobShop
for k,shops in pairs(shared.OwnedShops) do
for k,shop in pairs(shops) do
if jobshop[shop.label] == self.PlayerData.job?.name then
if self.PlayerData and self.PlayerData.job and jobshop[shop.label] == self.PlayerData.job?.name then
if not shared.target then
self.temporalspheres[shop.label] = self.Add(shop.coord,'My Store '..shop.label,self.StoreOwner,false,shop)
self.JobSpheres[self.PlayerData.job?.name] = self.temporalspheres[shop.label]
Expand All @@ -145,17 +154,16 @@ if not IsDuplicityVersion() then
end)
elseif shared.framework == 'QBCORE' then
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
QBCore.Functions.GetPlayerData(function(p)
self.PlayerData = p
self.LoadShops()
self.LoadJobShops()
if PlayerData.job ~= nil then
self.PlayerData.job.grade = self.PlayerData.job.grade.level
end
if PlayerData.identifier == nil then
self.PlayerData.identifier = self.PlayerData.license
end
end)
Wait(1500)
self.PlayerData = QBCore.Functions.GetPlayerData()
if self.PlayerData.job ~= nil then
self.PlayerData.job.grade = self.PlayerData.job.grade.level
end
if self.PlayerData.identifier == nil then
self.PlayerData.identifier = self.PlayerData.license
end
self.LoadShops()
self.LoadJobShops()
end)
end
end
Expand All @@ -164,11 +172,14 @@ if not IsDuplicityVersion() then
if shared.framework == 'ESX' then
return ESX.GetPlayerData()
else
local data = promise:new()
QBCore.Functions.GetPlayerData(function(playerdata)
data:resolve(playerdata)
end)
return Citizen.Await(data)
local Player = QBCore.Functions.GetPlayerData()
if Player.job ~= nil then
Player.job.grade = Player.job.grade.level
end
if Player.identifier == nil then
Player.identifier = Player.license
end
return Player
end
end

Expand Down
106 changes: 81 additions & 25 deletions server/framework/main.lua
Expand Up @@ -2,7 +2,7 @@ if shared.framework == 'ESX' then
vehicletable = 'owned_vehicles'
vehiclemod = 'vehicle'
elseif shared.framework == 'QBCORE' then
vehicletable = 'player_vehicles '
vehicletable = 'player_vehicles'
vehiclemod = 'mods'
owner = 'license'
stored = 'state'
Expand Down Expand Up @@ -33,68 +33,124 @@ function GetPlayerFromId(src)
if shared.framework == 'ESX' then
return ESX.GetPlayerFromId(self.src)
elseif shared.framework == 'QBCORE' then
selfcore = {}
selfcore.data = QBCore.Functions.GetPlayer(self.src)
if selfcore.data.identifier == nil then
selfcore.data.identifier = selfcore.data.PlayerData.license
Player = QBCore.Functions.GetPlayer(self.src)
if not Player then return end
if Player.identifier == nil then
Player.identifier = Player.PlayerData.license
end
if selfcore.data.citizenid == nil then
selfcore.data.citizenid = selfcore.data.PlayerData.citizenid
if Player.citizenid == nil then
Player.citizenid = Player.PlayerData.citizenid
end
if selfcore.data.job == nil then
selfcore.data.job = selfcore.data.PlayerData.job
if Player.job == nil then
Player.job = Player.PlayerData.job
end

selfcore.data.getMoney = function(value)
return selfcore.data.PlayerData.money['cash']
Player.getMoney = function(value)
return Player.PlayerData.money['cash']
end
selfcore.data.addMoney = function(value)
Player.addMoney = function(value)
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.AddMoney('cash',tonumber(value))
return true
end
selfcore.data.addAccountMoney = function(type, value)
Player.addAccountMoney = function(type, value)
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.AddMoney(type,tonumber(value))
return true
end
selfcore.data.removeMoney = function(value)
Player.removeMoney = function(value)
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.RemoveMoney('cash',tonumber(value))
return true
end
selfcore.data.getAccount = function(type)
Player.getAccount = function(type)
if type == 'money' then
type = 'cash'
end
return {money = selfcore.data.PlayerData.money[type]}
return {money = Player.PlayerData.money[type]}
end
selfcore.data.removeAccountMoney = function(type,val)
Player.removeAccountMoney = function(type,val)
if type == 'money' then
type = 'cash'
end
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.RemoveMoney(type,tonumber(val))
return true
end
selfcore.data.showNotification = function(msg)
Player.showNotification = function(msg)
TriggerEvent('QBCore:Notify',self.src, msg)
return true
end
selfcore.data.addInventoryItem = function(item,amount,info,slot)
Player.addInventoryItem = function(item,amount,info,slot)
local info = info
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.AddItem(item,amount,slot or false,info)
end
selfcore.data.removeInventoryItem = function(item,amount,slot)
Player.removeInventoryItem = function(item,amount,slot)
QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.RemoveItem(item, amount, slot or false)
end
selfcore.data.getInventoryItem = function(item)
Player.getInventoryItem = function(item)
local gi = QBCore.Functions.GetPlayer(tonumber(self.src)).Functions.GetItemByName(item) or {count = 0}
gi.count = gi.amount or 0
return gi
end
selfcore.data.getGroup = function()
Player.getGroup = function()
return QBCore.Functions.IsOptin(self.src)
end
if selfcore.data.source == nil then
selfcore.data.source = self.src
if Player.source == nil then
Player.source = self.src
end
return Player
end
end

Inventory.AddItem = function(source,item,count,metadata,slot)
if shared.inventory == 'ox_inventory' then
return exports.ox_inventory:AddItem(source,item,count,metadata,slot)
else
if item == 'money' then
local Player = GetPlayerFromId(source)

if not Player then
if not tonumber(source) then
source = source:gsub('Hotdog:','')
source = source:gsub('Burger:','')
source = source:gsub('Taco:','')
GetPlayerFromIdentifier(source).addAccountMoney('money',count)
end
return
end
Player.addMoney(count)
else
local added = exports['qb-inventory']:AddItem(source, item, count, slot, metadata)
if not added then
if not slot then
local stash = exports['qb-inventory']:GetStashItems(source)
slot = exports['qb-inventory']:GetFirstSlotByItem(stash, item, info)
end
exports['qb-inventory']:AddToStash(source, slot, otherslot, item, count, metadata)
end
end
end
end

Inventory.RemoveItem = function(source,item,count,metadata,slot)
if shared.inventory == 'ox_inventory' then
return exports.ox_inventory:RemoveItem(source, item, count, metadata, slot)
else
if item == 'money' then
local Player = GetPlayerFromId(source)
if not tonumber(source) then
source = source:gsub('Hotdog:','')
source = source:gsub('Burger:','')
source = source:gsub('Taco:','')
GetPlayerFromIdentifier(source).removeMoney('money',count)
end
Player.removeMoney(count)
else
local removed = exports['qb-inventory']:RemoveItem(source, item, count, slot, metadata)
if not removed then
if not slot then
local stash = exports['qb-inventory']:GetStashItems(source)
slot = exports['qb-inventory']:GetFirstSlotByItem(stash, item, info)
end
exports['qb-inventory']:RemoveFromStash(source, slot, item, count, metadata)
end
end
return selfcore.data
end
end
154 changes: 95 additions & 59 deletions server/main.lua
Expand Up @@ -3,6 +3,7 @@ GlobalState.Stores = json.decode(GetResourceKvpString('renzu_stores') or '[]') o
GlobalState.MovableShops = json.decode(GetResourceKvpString('movableshops') or '[]') or {}
GlobalState.FinanceData = json.decode(GetResourceKvpString('financedata') or '[]') or {}
GlobalState.JobShop = {}
Inventory = {}
local Items = {}
local purchaseorders = {}
vehicletable = 'owned_vehicles'
Expand Down Expand Up @@ -49,7 +50,7 @@ CreateThread(function()
end
end
end
else -- if above condition is not possible , we will override ox_inventory shops
elseif shared.inventory == 'ox_inventory' then -- if above condition is not possible , we will override ox_inventory shops
for k,v in pairs(shared.Shops) do -- overide default ox inventory shops. temporary logic
exports.ox_inventory:RegisterShop(k, {
name = k,
Expand All @@ -62,7 +63,7 @@ CreateThread(function()
})
end
end
local items = exports.ox_inventory:Items()
local items = Inventory.GetItems()
for k,v in pairs(items) do
Items[v.name] = v.label
end
Expand All @@ -82,6 +83,49 @@ CreateThread(function()
end)
end)

Inventory.SearchItems = function(source, method, item)
if shared.inventory == 'ox_inventory' then
return exports.ox_inventory:Search(source, method, item)
else
local Player = QBCore.Functions.GetPlayer(source)
local items = {}
if not Player then
items = exports['qb-inventory']:GetStashItems(source)
if not items then return {} end
else
items = Player.PlayerData.items
end
local count = 0
if method == 'count' then
for k,v in pairs(items) do
if item == v.name then
count += 1
end
end
return count
else
local data = {}
for k,v in pairs(items) do
if item == v.name then
v.count = v.amount
v.metadata = v.info
v.slot = k
data[k] = v
end
end
return data
end
end
end

Inventory.GetItems = function()
if GetResourceState('ox_inventory') ~= 'started' then
return QBCore.Shared.Items
else
return exports.ox_inventory:Items()
end
end

getShopDataByLabel = function(id)
local stores = GlobalState.Stores
local shop = false
Expand Down Expand Up @@ -124,7 +168,7 @@ CheckItemData = function(data)
return false
end

if not shared.oxShops then
if not shared.oxShops and shared.inventory == 'ox_inventory' then
lib.callback.register('ox_inventory:openShop', function(source, data)
TriggerClientEvent('renzu_shop:OpenShops',source, {type = data.type, id = data.id})
SetTimeout(1,function()
Expand All @@ -134,28 +178,31 @@ if not shared.oxShops then
end)
end

exports.ox_inventory:registerHook('buyItem', function(payload)
if not shared.oxShops then return end
local data = payload
local conf = shared.OwnedShops[data.ShopName]
local stores = GlobalState.Stores
data.ShopIndex = tonumber(data.ShopIndex)
if conf then
local store = conf[data.ShopIndex] and conf[data.ShopIndex].label
local name = data.metadata and data.metadata.name or data.item
if stores[store] then
RemoveStockFromStore({shop = data.ShopName, metadata = data.metadata, index = data.ShopIndex, item = data.item, amount = tonumber(data.count), price = data.price, money = data.currency})
if shared.inventory == 'ox_inventory' then
exports.ox_inventory:registerHook('buyItem', function(payload)
if not shared.oxShops then return end
local data = payload
local conf = shared.OwnedShops[data.ShopName]
local stores = GlobalState.Stores
data.ShopIndex = tonumber(data.ShopIndex)
if conf then
local store = conf[data.ShopIndex] and conf[data.ShopIndex].label
local name = data.metadata and data.metadata.name or data.item
if stores[store] then
RemoveStockFromStore({shop = data.ShopName, metadata = data.metadata, index = data.ShopIndex, item = data.item, amount = tonumber(data.count), price = data.price, money = data.currency})
end
end
end
end)
end)
end

ModifyFromBankOffline = function(id,amount,minus)
ModifyFromBankOffline = function(id,amount,minus,type)
if type == nil then type = 'bank' end
local result = SqlFunc('oxmysql','fetchAll','SELECT '..playeraccounts..' FROM '..playertable..' WHERE '..playeridentifier..' = ?', { id })
local accounts = json.decode(result[1][playeraccounts])
if not minus then
accounts.bank += amount
accounts[type] += amount
else
accounts.bank -= amount
accounts[type] -= amount
end
SqlFunc('oxmysql','execute','UPDATE '..playertable..' SET '..playeraccounts..' = ? WHERE '..playeridentifier..' = ?', {json.encode(accounts), id})
end
Expand Down Expand Up @@ -228,9 +275,9 @@ RemoveStockFromStash = function(data)
data.items = items
local stash = GetStashData(data)
if stash[data.metadata and data.metadata.name or data.item] >= data.amount then
exports.ox_inventory:RemoveItem(data.identifier, data.item, data.amount, data.metadata) -- remove item from stash inventory
Inventory.RemoveItem(data.identifier, data.item, data.amount, data.metadata) -- remove item from stash inventory
if data.addmoney then
exports.ox_inventory:AddItem(data.identifier, data.money, data.price * data.amount) -- add money directly to stash inventory
Inventory.AddItem(data.identifier, data.money, data.price * data.amount) -- add money directly to stash inventory
end
return true
end
Expand Down Expand Up @@ -395,7 +442,7 @@ lib.callback.register('renzu_shops:removestock', function(source,data)
if storeowned then
local removed = RemoveStockFromStore({shop = data.type, metadata = data.metadata, index = data.index, item = data.name, amount = tonumber(data.count), price = data.price, money = data.money:lower()})
if removed and data.citizen then
exports.ox_inventory:AddItem(data.citizen, data.name, data.count, data.metadata) -- add money directly to stash inventory
Inventory.AddItem(data.citizen, data.name, data.count, data.metadata) -- add money directly to stash inventory
return true
elseif removed then
return true
Expand Down Expand Up @@ -514,7 +561,7 @@ lib.callback.register('renzu_shops:buyitem', function(source,data)
RemoveStockFromStash({addmoney = true, identifier = data.shop, metadata = v.data.metadata, item = v.data.name, amount = tonumber(v.count), price = data.data[v.data.name].price, type = data.index, money = moneytype:lower()})
end
if data.shop ~= 'VehicleShop' then -- add new item if its not a vehicle type
exports.ox_inventory:AddItem(source,v.data.name,v.count,v.data.metadata, false)
Inventory.AddItem(source,v.data.name,v.count,v.data.metadata, false)
else -- else if vehicle type add it to player vehicles table
for i = 1, tonumber(v.count) do
callback = GenPlate()
Expand All @@ -533,7 +580,6 @@ lib.callback.register('renzu_shops:buyitem', function(source,data)
end
local stores = GlobalState.Stores
if storeowned and data.finance and stores[storeowned] then
print(data.finance.daily,data.finance.days)
local daily = data.finance.daily
local days = data.finance.days
local finance = {
Expand Down Expand Up @@ -567,7 +613,6 @@ RegisterFinance = function(data)
days = data.days
}
finance[data.identifier].max -= data.total
print(financedata,data.total,data.daily,data.shop,data.owner,data.days)
table.insert(finance[data.identifier].financed,financedata)
GlobalState.FinanceData = finance
SetResourceKvp('financedata', json.encode(finance))
Expand Down Expand Up @@ -771,12 +816,12 @@ lib.callback.register("renzu_shops:robstore", function(source,data)
local stores = GlobalState.Stores
if not stores[data.store] then -- if store is not owned
local amount = math.random(15000,30000)
exports.ox_inventory:AddItem(source, data.item, amount)
Inventory.AddItem(source, data.item, amount)
return true
else -- if store is owned by player
local money = stores[data.store].cashier[data.item] or 0
stores[data.store].cashier[data.item] = 0
exports.ox_inventory:AddItem(source, data.item, money)
Inventory.AddItem(source, data.item, money)
GlobalState.Stores = stores
return true
end
Expand All @@ -799,7 +844,7 @@ GetStashData = function(data)
item = v.metadata.name
metadata = true
end
local data = exports.ox_inventory:Search(data.identifier, 'slots', v.name)
local data = Inventory.SearchItems(data.identifier, 'slots', v.name)
result[item] = 0
if data then
for k,v in pairs(data) do
Expand All @@ -824,7 +869,7 @@ lib.callback.register("renzu_shops:getStashData", function(source,data)
end)

GetItemCountSingle = function(item,source)
return exports.ox_inventory:Search(source,'count', item)
return Inventory.SearchItems(source,'count', item)
end

lib.callback.register("renzu_shops:craftitem", function(source,data)
Expand All @@ -843,10 +888,10 @@ lib.callback.register("renzu_shops:craftitem", function(source,data)
end
if haverequired then
for k,v in pairs(v.ingredients or {}) do
exports.ox_inventory:RemoveItem(inventoryid, k, v, nil)
Inventory.RemoveItem(inventoryid, k, v, nil)
end
if not data.dontreceive then
exports.ox_inventory:AddItem(inventoryid, v.name, 1, v.metadata or {})
Inventory.AddItem(inventoryid, v.name, 1, v.metadata or {})
end
end
elseif v.metadata and not v.metadata.name and v.name == data.item or not v.metadata and v.name == data.item then
Expand All @@ -858,10 +903,10 @@ lib.callback.register("renzu_shops:craftitem", function(source,data)
end
if haverequired then
for k,v in pairs(v.ingredients) do
exports.ox_inventory:RemoveItem(inventoryid, k, v, nil)
Inventory.RemoveItem(inventoryid, k, v, nil)
end
if not data.dontreceive then
exports.ox_inventory:AddItem(inventoryid, v.name, 1, nil)
Inventory.AddItem(inventoryid, v.name, 1, nil)
end
end
end
Expand All @@ -872,7 +917,11 @@ lib.callback.register("renzu_shops:getmovableshopdata", function(source,data)
local source = source
local xPlayer = GetPlayerFromId(source)
local identifier = data.type..':'..xPlayer.identifier
exports.ox_inventory:RegisterStash(identifier, data.type, 40, 40000, false)
if shared.inventory == 'ox_inventory' then
exports.ox_inventory:RegisterStash(identifier, data.type, 40, 40000, false)
elseif shared.inventory == 'qb-inventory' then
exports['qb-inventory']:RegisterStash(identifier)
end
return GlobalState.MovableShops[identifier]
end)

Expand Down Expand Up @@ -926,7 +975,11 @@ AddEventHandler('entityCreated', function(entity)
Wait(1)
ent:set('movableshop', {identifier = identifier, type = v.shopname, selling = true}, true)
ent:set('movableshopspawned', {identifier = v.identifier, type = v.shopname}, true)
exports.ox_inventory:RegisterStash(identifier, v.shopname, 40, 40000, false)
if shared.inventory == 'ox_inventory' then
exports.ox_inventory:RegisterStash(identifier, v.shopname, 40, 40000, false)
elseif shared.inventory == 'qb-inventory' then
exports['qb-inventory']:RegisterStash(identifier)
end
end
end
end
Expand Down Expand Up @@ -1111,7 +1164,7 @@ AddStockstoStore = function(data)
end

GetItemCount = function(item,metadata,source) -- temporary until ox search functions works correctly as i am having issues getting correct results with search with the metadata table or strings, bite me
local data = exports.ox_inventory:Search(source, 'slots', item)
local data = Inventory.SearchItems(source, 'slots', item)
local count = 0
for k,v in pairs(data) do
if v.metadata and v.metadata.name == metadata then -- our identifier to identify custom items
Expand Down Expand Up @@ -1147,10 +1200,10 @@ lib.callback.register('renzu_shops:editstore', function(source,data)
if data.metadata and data.metadata.name then
count = GetItemCount(data.item,data.metadata.name,source)
else
count = exports.ox_inventory:Search(source, 'count', data.item)
count = Inventory.SearchItems(source, 'count', data.item)
end
if tonumber(data.value) and count >= data.value and data.value > 0 then
exports.ox_inventory:RemoveItem(source, data.item, data.value, data.metadata and data.metadata.name and data.metadata or nil, slot)
Inventory.RemoveItem(source, data.item, data.value, data.metadata and data.metadata.name and data.metadata or nil, slot)
if stores[data.store].items[itemtype][itemname] == nil then stores[data.store].items[itemtype][itemname] = {} end
local stock = stores[data.store].items[itemtype][itemname].stock
if not stock then stores[data.store].items[itemtype][itemname].stock = 0 end
Expand All @@ -1172,7 +1225,7 @@ lib.callback.register('renzu_shops:editstore', function(source,data)
stores[data.store].items[itemtype][itemname].stock = tonumber(stores[data.store].items[itemtype][itemname].stock) - data.value
SetResourceKvp('renzu_stores', json.encode(stores))
GlobalState.Stores = stores
exports.ox_inventory:AddItem(source, data.item, data.value, data.metadata or {})
Inventory.AddItem(source, data.item, data.value, data.metadata or {})
if canregister and shared.oxShops then
local name, index, storedata = getShopDataByLabel(data.store)
SetOxInvShopStock({name = name, index = index, item = itemname, value = -data.value})
Expand Down Expand Up @@ -1243,13 +1296,12 @@ lib.callback.register('renzu_shops:ondemandpay', function(source,data)
end
if total > 0 then
purchaseorders[source] = nil
exports.ox_inventory:AddItem(source, 'money', total)
Inventory.AddItem(source, 'money', total)
end
end
end)

local movableentity = {}

lib.callback.register('renzu_shops:playerStateBags', function(source,value)
local entity = NetworkGetEntityFromNetworkId(value.entity)
local state = Entity(entity).state
Expand All @@ -1264,27 +1316,11 @@ lib.callback.register('renzu_shops:playerStateBags', function(source,value)
end
end)

-- AddStateBagChangeHandler('renzu_shops:playerStateBags' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated) -- replicate Client State
-- Wait(0)
-- local net = tonumber(bagName:gsub('player:', ''), 10)
-- local entity = NetworkGetEntityFromNetworkId(value.entity)
-- local state = Entity(entity).state
-- value.data.ts = os.time()
-- if value.data.bagname == 'player:' then
-- state = Player(tonumber(value.entity)).state
-- end
-- state:set(value.name, value.data, true)
-- if value.data.remove then
-- Wait(2000)
-- state:set(value.name, nil, true)
-- end
-- end)

AddStateBagChangeHandler('movableentity' --[[key filter]], nil --[[bag filter]], function(bagName, key, value, _unused, replicated) -- saves entities from client
Wait(0)
local net = tonumber(bagName:gsub('player:', ''), 10)
if not movableentity[net] then movableentity[net] = {} end
table.insert(movableentity[net],value)
table.insert(movableentity[net],value.nets)
end)

RegisterCommand('delmov', function(source, args)
Expand All @@ -1296,7 +1332,7 @@ AddStateBagChangeHandler('createpurchaseorder' --[[key filter]], nil --[[bag fil
Wait(0)
local net = tonumber(bagName:gsub('player:', ''), 10)
if not value then return end
purchaseorders[net] = value
purchaseorders[net] = value.purchase
end)

DeletePlayerMovableEntity = function(src, all) -- Delete Entities owned by player
Expand Down