Custom Shop
Build an NPC shop using IInventory and IEconomy.
What You'll Build
- A 24/7 convenience store NPC
- Pedshop UI listing items with prices
- Purchase deducts from bank, adds item to inventory
- Configurable stock and prices
Step 1 — Scaffold
bash
shiva make module my-shopStep 2 — Config
lua
Config.shops = {
convenience_store = {
label = 'Convenience Store',
ped = { model = 'mp_m_shopkeep_01', coords = { x = 24.4, y = -1346.4, z = 29.5, heading = 272.0 } },
items = {
{ item = 'water', label = 'Water', price = 2, account = 'cash' },
{ item = 'sandwich', label = 'Sandwich', price = 5, account = 'cash' },
{ item = 'bandage', label = 'Bandage', price = 15, account = 'cash' },
},
},
}Step 3 — Server Handler
lua
RegisterNetEvent('my-shop:buy', function(shopId, itemId)
local source = source
local shop = Config.shops[shopId]
local item = findItem(shop.items, itemId)
if not item then return end
local economy = container:make('IEconomy')
local inventory = container:make('IInventory')
local ok = economy:removeMoney(source, item.account, item.price)
if not ok then
notify(source, 'error', "You can't afford that.")
return
end
inventory:addItem(source, item.item, 1)
notify(source, 'success', ('Bought %s for $%d'):format(item.label, item.price))
end)Step 4 — Client Interaction
lua
-- Spawn the NPC and show the shop UI when the player presses E nearby
CreateThread(function()
for shopId, shop in pairs(Config.shops) do
-- Spawn ped
-- Draw interaction marker
-- On E key press: TriggerServerEvent('my-shop:open', shopId)
end
end)