Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/bridge/nd/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,22 @@ end
function server.getOwnedVehicleId(entityId)
return NDCore.getVehicle(entityId)?.id
end

function server.removeBusinessMoney(businessName, amount)
if GetResourceState("ND_Businesses") ~= "started" then
return false, false
end

local business = exports["ND_Businesses"]:getBusiness(businessName)
local complete = business.removeMoney(amount)
return false, complete
end

function server.getBusinessMoney(businessName, amount)
if GetResourceState("ND_Businesses") ~= "started" then
return false
end

local business = exports["ND_Businesses"]:getBusiness(businessName)
return business?.money
end
20 changes: 14 additions & 6 deletions modules/shops/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ local function registerShopType(shopType, properties)
groups = properties.groups or properties.jobs,
items = properties.inventory,
slots = #properties.inventory,
business = properties.business,
type = 'shop',
}

Expand Down Expand Up @@ -98,6 +99,7 @@ local function createShop(shopType, id)
groups = groups,
items = table.clone(shop.inventory),
slots = #shop.inventory,
business = shop.business,
type = 'shop',
coords = coords,
distance = shared.target and shop.targets?[id]?.distance,
Expand Down Expand Up @@ -169,17 +171,23 @@ lib.callback.register('ox_inventory:openShop', function(source, data)
return { label = playerInv.label, type = playerInv.type, slots = playerInv.slots, weight = playerInv.weight, maxWeight = playerInv.maxWeight }, shop
end)

local function canAffordItem(inv, currency, price)
local canAfford = price >= 0 and Inventory.GetItemCount(inv, currency) >= price
local function canAffordItem(inv, currency, price, business)
local money = business and server.getBusinessMoney and server.getBusinessMoney(business, price) or Inventory.GetItem(inv, currency, false, true)
local canAfford = price >= 0 and money >= price

return canAfford or {
type = 'error',
description = locale('cannot_afford', ('%s%s'):format((currency == 'money' and locale('$') or math.groupdigits(price)), (currency == 'money' and math.groupdigits(price) or ' '..Items(currency).label)))
}
end

local function removeCurrency(inv, currency, price)
Inventory.RemoveItem(inv, currency, price)
local function removeCurrency(inv, currency, price, business)
local useBusiness = business and server.removeBusinessMoney
if useBusiness then
server.removeBusinessMoney(business, price)
else
Inventory.RemoveItem(inv, currency, price)
end
end

local function isRequiredGrade(grade, rank)
Expand Down Expand Up @@ -251,7 +259,7 @@ lib.callback.register('ox_inventory:buyItem', function(source, data)
return false, false, { type = 'error', description = locale('cannot_carry') }
end

local canAfford = canAffordItem(playerInv, currency, price)
local canAfford = canAffordItem(playerInv, currency, price, shop.business)

if canAfford ~= true then
return false, false, canAfford
Expand All @@ -274,7 +282,7 @@ lib.callback.register('ox_inventory:buyItem', function(source, data)

Inventory.SetSlot(playerInv, fromItem, count, metadata, data.toSlot)
playerInv.weight = newWeight
removeCurrency(playerInv, currency, price)
removeCurrency(playerInv, currency, price, shop.business)

if fromData.count then
shop.items[data.fromSlot].count = fromData.count - count
Expand Down