mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 17:58:54 +00:00
70 lines
1.3 KiB
Lua
70 lines
1.3 KiB
Lua
ESX = nil
|
|
local ItemsLabels = {}
|
|
|
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|
|
|
AddEventHandler('onMySQLReady', function()
|
|
|
|
MySQL.Async.fetchAll(
|
|
'SELECT * FROM items',
|
|
{},
|
|
function(result)
|
|
|
|
for i=1, #result, 1 do
|
|
ItemsLabels[result[i].name] = result[i].label
|
|
end--
|
|
|
|
end
|
|
)
|
|
|
|
end)
|
|
|
|
ESX.RegisterServerCallback('esx_shop:requestDBItems', function(source, cb)
|
|
|
|
MySQL.Async.fetchAll(
|
|
'SELECT * FROM shops',
|
|
{},
|
|
function(result)
|
|
|
|
local shopItems = {}
|
|
|
|
for i=1, #result, 1 do
|
|
|
|
if shopItems[result[i].name] == nil then
|
|
shopItems[result[i].name] = {}
|
|
end
|
|
|
|
table.insert(shopItems[result[i].name], {
|
|
name = result[i].item,
|
|
price = result[i].price,
|
|
label = ItemsLabels[result[i].item]
|
|
})
|
|
|
|
end
|
|
|
|
cb(shopItems)
|
|
|
|
end
|
|
)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_shop:buyItem')
|
|
AddEventHandler('esx_shop:buyItem', function(itemName, price)
|
|
|
|
local _source = source
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
if xPlayer.get('money') >= price then
|
|
|
|
xPlayer.removeMoney(price)
|
|
xPlayer.addInventoryItem(itemName, 1)
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, 'Vous avez acheté ~b~1x ' .. ItemsLabels[itemName])
|
|
|
|
else
|
|
TriggerClientEvent('esx:showNotification', _source, 'Vous n\'avez ~r~pas assez~s~ d\'argent.')
|
|
end
|
|
|
|
end)
|