Tried and removed esx_shops and checked again. I also tried to change the name of the table under items from âlimitâ to âweightâ. Also edited the sql to implement but everything seems finde. Maybe there is issue here?
Serverside main.lua:
ESX = nil
local ShopItems = {}
TriggerEvent(âesx:getSharedObjectâ, function(obj) ESX = obj end)
MySQL.ready(function()
MySQL.Async.fetchAll(âSELECT * FROM shops LEFT JOIN items ON items.name = shops.itemâ, {}, function(shopResult)
for i=1, #shopResult, 1 do
if shopResult[i].name then
if ShopItems[shopResult[i].store] == nil then
ShopItems[shopResult[i].store] = {}
end
table.insert(ShopItems[shopResult[i].store], {
label = shopResult[i].label,
item = shopResult[i].item,
price = shopResult[i].price,
})
else
print(('esx_shops: invalid item "%s" found!'):format(shopResult[i].item))
end
end
end)
end)
ESX.RegisterServerCallback(âesx_shops:requestDBItemsâ, function(source, cb)
cb(ShopItems)
end)
RegisterServerEvent(âesx_shops:buyItemâ)
AddEventHandler(âesx_shops:buyItemâ, function(itemName, amount, zone)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
amount = ESX.Math.Round(amount)
-- is the player trying to exploit?
if amount < 0 then
print('esx_shops: ' .. xPlayer.identifier .. ' attempted to exploit the shop!')
return
end
-- get price
local price = 0
local itemLabel = ''
for i=1, #ShopItems[zone], 1 do
if ShopItems[zone][i].item == itemName then
price = ShopItems[zone][i].price
itemLabel = ShopItems[zone][i].label
break
end
end
price = price * amount
-- can the player afford this item?
if xPlayer.getMoney() >= price then
-- can the player carry the said amount of x item?
if xPlayer.canCarryItem(itemName, amount) then
xPlayer.removeMoney(price)
xPlayer.addInventoryItem(itemName, amount)
xPlayer.showNotification(_U('bought', amount, itemLabel, ESX.Math.GroupDigits(price)))
else
xPlayer.showNotification(_U('player_cannot_hold'))
end
else
local missingMoney = price - xPlayer.getMoney()
xPlayer.showNotification(_U('not_enough', ESX.Math.GroupDigits(missingMoney)))
end
end)
clientside main.lua:
ESX = nil
local hasAlreadyEnteredMarker, lastZone
local currentAction, currentActionMsg, currentActionData = nil, nil, {}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent(âesx:getSharedObjectâ, function(obj) ESX = obj end)
Citizen.Wait(0)
end
Citizen.Wait(5000)
ESX.TriggerServerCallback('esx_shops:requestDBItems', function(ShopItems)
for k,v in pairs(ShopItems) do
Config.Zones[k].Items = v
end
end)
end)
function OpenShopMenu(zone)
local elements = {}
for i=1, #Config.Zones[zone].Items, 1 do
local item = Config.Zones[zone].Items[i]
table.insert(elements, {
label = ('%s - <span style="color:green;">%s</span>'):format(item.label, _U('shop_item', ESX.Math.GroupDigits(item.price))),
itemLabel = item.label,
item = item.item,
price = item.price,
-- menu properties
value = 1,
type = 'slider',
min = 1,
max = 100
})
end
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop', {
title = _U('shop'),
align = 'bottom-right',
elements = elements
}, function(data, menu)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
title = _U('shop_confirm', data.current.value, data.current.itemLabel, ESX.Math.GroupDigits(data.current.price * data.current.value)),
align = 'bottom-right',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}}, function(data2, menu2)
if data2.current.value == 'yes' then
TriggerServerEvent('esx_shops:buyItem', data.current.item, data.current.value, zone)
end
menu2.close()
end, function(data2, menu2)
menu2.close()
end)
end, function(data, menu)
menu.close()
currentAction = 'shop_menu'
currentActionMsg = _U('press_menu')
currentActionData = {zone = zone}
end)
end
AddEventHandler(âesx_shops:hasEnteredMarkerâ, function(zone)
currentAction = âshop_menuâ
currentActionMsg = _U(âpress_menuâ)
currentActionData = {zone = zone}
end)
AddEventHandler(âesx_shops:hasExitedMarkerâ, function(zone)
currentAction = nil
ESX.UI.Menu.CloseAll()
end)
â Create Blips
Citizen.CreateThread(function()
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
SetBlipSprite (blip, 52)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 2)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(_U('shops'))
EndTextCommandSetBlipName(blip)
end
end
end)
â Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerCoords = GetEntityCoords(PlayerPedId())
local isInMarker, letSleep, currentZone = false, false
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
local distance = GetDistanceBetweenCoords(playerCoords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true)
if distance < Config.DrawDistance then
DrawMarker(Config.Type, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, nil, nil, false)
letSleep = false
if distance < Config.Size.x then
isInMarker = true
currentZone = k
lastZone = k
end
end
end
end
if isInMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true
TriggerEvent('esx_shops:hasEnteredMarker', currentZone)
end
if not isInMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
TriggerEvent('esx_shops:hasExitedMarker', lastZone)
end
if letSleep then
Citizen.Wait(500)
end
end
end)
â Key Controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if currentAction then
ESX.ShowHelpNotification(currentActionMsg)
if IsControlJustReleased(0, 38) then
if currentAction == 'shop_menu' then
OpenShopMenu(currentActionData.zone)
end
currentAction = nil
end
else
Citizen.Wait(500)
end
end
end)
And the used SQL File:
USE essentialmode
;
CREATE TABLE shops
(
id
int(11) NOT NULL AUTO_INCREMENT,
store
varchar(100) NOT NULL,
item
varchar(100) NOT NULL,
price
int(11) NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO shops
(store, item, price) VALUES
(âTwentyFourSevenâ,âbreadâ,30),
(âTwentyFourSevenâ,âwaterâ,15),
(âRobsLiquorâ,âbreadâ,30),
(âRobsLiquorâ,âwaterâ,15),
(âLTDgasolineâ,âbreadâ,30),
(âLTDgasolineâ,âwaterâ,15)
;
maybe someone notices a mistake. I did not change a thing in those files.
And the server.cfg. Might be an issue of the current load order? But basically from the docs just status and es extended are needed.
You probably donât want to change these!
Only change them if youâre using a server with multiple network interfaces.
These resources will start by default.
start mapmanager
start chat
start spawnmanager
start sessionmanager
start fivem
start hardcap
exec resources/vMenu/config/permissions.cfg
add_ace group.admin âvMenu.Everythingâ allow
setr vmenu_bans_database_filepath âresources/vMenu/â
start vMenu
start â â â â â â â
start RPDeath
start scoreboard
start baseevents
start bob74_ipl
start trafficadjuster
start PvP
MYSQL ASYNC
start async
start mysql-async
start essentialmode
start esplugin_mysql
start es_admin2
start es_ui
add_ace resource.essentialmode command.add_principal allow
add_ace resource.essentialmode command.add_ace allow
start ghmattimysql
ESSENTIAL MODS
start es_extended
ESX REQUIRED MODS
start instance
start cron
start skinchanger
start esx_skin
start esx_menu_default
start esx_menu_list
start esx_menu_dialog
start esx_addonaccount
start esx_addoninventory
start esx_datastore
start esx_society
start esx_service
start esx_billing
start esx_kashacters
start esx_voice
start esx_phone
start pNotify
#ESX JOBS
start esx_jobs
start esx_joblisting
start esx_mechanicjob
start esx_policejob
start esx_criminalrecords
start esx_property
start esx_realestateagentjob
start esx_bankerjob
start esx_ambulancejob
start esx_vehicleshop
#start esx_truckshop
start esx_taxijob
#ESX ANY OTHER MODS
start esx_garage
start esx_license
start esx_weaponshop
start esx_drugs
start esx_identity
start esx_dmvschool
start esx_lscustom
start esx_clotheshop
start esx_camera
start esx_holdup
start esx_atm
start esx_barbershop
start esx_animations
start esx_jb_eden_garage2
start esx_accessories
start esx_boat
start esx_boilerplate
start esx_cruisecontrol
start esx_migrate
start esx_rpchat
start esx_sit
start esx_status
start esx_basicneeds
#ESX SHOPS
start esx_tattoosShops
start esx_shops
OTHER
start mapaddons
start ft_libs
#start Advanced911
start fivem-seatbelt