mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Optimized getting shop items, open menu after license bought
This commit is contained in:
+16
-5
@@ -24,13 +24,20 @@ Citizen.CreateThread(function()
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
|
||||
ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems)
|
||||
for k,v in pairs(ShopItems) do
|
||||
ESX.TriggerServerCallback('esx_weashop:getShop', function(shopItems)
|
||||
for k,v in pairs(shopItems) do
|
||||
Config.Zones[k].Items = v
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_weashop:sendShop')
|
||||
AddEventHandler('esx_weashop:sendShop', function(shopItems)
|
||||
for k,v in pairs(shopItems) do
|
||||
Config.Zones[k].Items = v
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_weashop:loadLicenses')
|
||||
AddEventHandler('esx_weashop:loadLicenses', function(licenses)
|
||||
for i = 1, #licenses, 1 do
|
||||
@@ -49,9 +56,13 @@ function OpenBuyLicenseMenu(zone)
|
||||
}
|
||||
}, function(data, menu)
|
||||
if data.current.value == 'yes' then
|
||||
TriggerServerEvent('esx_weashop:buyLicense')
|
||||
ESX.TriggerServerCallback('esx_weashop:buyLicense', function(bought)
|
||||
if bought then
|
||||
menu.close()
|
||||
OpenShopMenu(zone)
|
||||
end
|
||||
end)
|
||||
end
|
||||
menu.close()
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
end)
|
||||
@@ -179,7 +190,7 @@ Citizen.CreateThread(function()
|
||||
if Licenses['weapon'] ~= nil or Config.Zones[CurrentActionData.zone].legal == 1 then
|
||||
OpenShopMenu(CurrentActionData.zone)
|
||||
else
|
||||
OpenBuyLicenseMenu()
|
||||
OpenBuyLicenseMenu(CurrentActionData.zone)
|
||||
end
|
||||
else
|
||||
OpenShopMenu(CurrentActionData.zone)
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ Config.Zones = {
|
||||
{ x = 22.09, y = -1107.28, z = 28.80 },
|
||||
{ x = 2567.69, y = 294.38, z = 107.73 },
|
||||
{ x = -1117.58, y = 2698.61, z = 17.55 },
|
||||
{ x = 842.44, y = -1033.42, z = 27.19 },
|
||||
{ x = 842.44, y = -1033.42, z = 27.19 }
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
+33
-29
@@ -1,7 +1,32 @@
|
||||
ESX = nil
|
||||
local shopItems = {}
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
MySQL.ready(function()
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM weashops', {}, function(result)
|
||||
for i=1, #result, 1 do
|
||||
if shopItems[result[i].zone] == nil then
|
||||
shopItems[result[i].zone] = {}
|
||||
end
|
||||
|
||||
table.insert(shopItems[result[i].zone], {
|
||||
item = result[i].item,
|
||||
price = result[i].price,
|
||||
label = ESX.GetWeaponLabel(result[i].item)
|
||||
})
|
||||
end
|
||||
|
||||
TriggerClientEvent('esx_weashop:sendShop', -1, shopItems)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_weashop:getShop', function(source, cb)
|
||||
cb(shopItems)
|
||||
end)
|
||||
|
||||
function LoadLicenses(source)
|
||||
TriggerEvent('esx_license:getLicenses', source, function(licenses)
|
||||
TriggerClientEvent('esx_weashop:loadLicenses', source, licenses)
|
||||
@@ -14,44 +39,23 @@ if Config.LicenseEnable then
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterServerEvent('esx_weashop:buyLicense')
|
||||
AddEventHandler('esx_weashop:buyLicense', function()
|
||||
local _source = source
|
||||
ESX.RegisterServerCallback('esx_weashop:buyLicense', function(source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if xPlayer.getMoney() >= Config.LicensePrice then
|
||||
xPlayer.removeMoney(Config.LicensePrice)
|
||||
|
||||
TriggerEvent('esx_license:addLicense', _source, 'weapon', function()
|
||||
LoadLicenses(_source)
|
||||
TriggerEvent('esx_license:addLicense', source, 'weapon', function()
|
||||
LoadLicenses(source)
|
||||
end)
|
||||
|
||||
cb(true)
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
|
||||
cb(false)
|
||||
TriggerClientEvent('esx:showNotification', source, _U('not_enough'))
|
||||
end
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb)
|
||||
MySQL.Async.fetchAll('SELECT * FROM weashops', {}, function(result)
|
||||
local shopItems = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
if shopItems[result[i].zone] == nil then
|
||||
shopItems[result[i].zone] = {}
|
||||
end
|
||||
|
||||
table.insert(shopItems[result[i].zone], {
|
||||
item = result[i].item,
|
||||
price = result[i].price,
|
||||
label = ESX.GetWeaponLabel(result[i].item)
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
cb(shopItems)
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_weashop:buyItem')
|
||||
AddEventHandler('esx_weashop:buyItem', function(weaponName, zone)
|
||||
local _source = source
|
||||
@@ -63,7 +67,7 @@ AddEventHandler('esx_weashop:buyItem', function(weaponName, zone)
|
||||
return
|
||||
end
|
||||
|
||||
if zone == "BlackWeashop" then
|
||||
if zone == 'BlackWeashop' then
|
||||
|
||||
if xPlayer.getAccount('black_money').money >= price then
|
||||
xPlayer.removeAccountMoney('black_money', price)
|
||||
|
||||
Reference in New Issue
Block a user