-- client.lua
ESX = exports['es_extended']:getSharedObject()
local shopItems = {
{ name = 'water', label = 'Water Bottle', price = 5 },
{ name = 'bread', label = 'Bread', price = 8 },
{ name = 'bandage', label = 'Bandage', price = 15 }
}
CreateThread(function()
while true do
local sleep = 1000
local coords = GetEntityCoords(PlayerPedId())
local dist = #(coords - vector3(25.7, -1347.3, 29.49))
if dist < 15 then
sleep = 0
if dist < 1.5 then
ESX.ShowHelpNotification('Press ~INPUT_CONTEXT~ to open the shop')
if IsControlJustReleased(0, 38) then
openShop()
end
end
end
Wait(sleep)
end
end)
function openShop()
local options = {}
for i, item in ipairs(shopItems) do
options[i] = {
title = item.label .. ' - #x27; .. item.price,
onSelect = function()
TriggerServerEvent('shop:server:BuyItem', item.name)
end
}
end
lib.registerContext({ id = 'shop_menu', title = '24/7 Shop', options = options })
lib.showContext('shop_menu')
end
-- server.lua
ESX = exports['es_extended']:getSharedObject()
local PRICES = { water = 5, bread = 8, bandage = 15 }
RegisterNetEvent('shop:server:BuyItem', function(itemName)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local price = PRICES[itemName]
if not price or not xPlayer then return end
if xPlayer.getMoney() >= price then
xPlayer.removeMoney(price)
xPlayer.addInventoryItem(itemName, 1)
TriggerClientEvent('esx:showNotification', src, ('Bought for $%s'):format(price))
else
TriggerClientEvent('esx:showNotification', src, 'Not enough money')
end
end)