mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
Get price server side
This commit is contained in:
+28
-15
@@ -1,22 +1,21 @@
|
||||
ESX = nil
|
||||
local ItemsLabels = {}
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
function LoadLicenses(source)
|
||||
TriggerEvent('esx_license:getLicenses', source, function (licenses)
|
||||
TriggerEvent('esx_license:getLicenses', source, function(licenses)
|
||||
TriggerClientEvent('esx_weashop:loadLicenses', source, licenses)
|
||||
end)
|
||||
end
|
||||
|
||||
if Config.EnableLicense == true then
|
||||
AddEventHandler('esx:playerLoaded', function (source)
|
||||
if Config.LicenseEnable then
|
||||
AddEventHandler('esx:playerLoaded', function(source)
|
||||
LoadLicenses(source)
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterServerEvent('esx_weashop:buyLicense')
|
||||
AddEventHandler('esx_weashop:buyLicense', function ()
|
||||
AddEventHandler('esx_weashop:buyLicense', function()
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
@@ -54,25 +53,39 @@ ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_weashop:buyItem')
|
||||
AddEventHandler('esx_weashop:buyItem', function(itemName, price, zone)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local account = xPlayer.getAccount('black_money')
|
||||
AddEventHandler('esx_weashop:buyItem', function(weaponName, zone)
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local price = GetPrice(weaponName, zone)
|
||||
|
||||
if zone == "BlackWeashop" then
|
||||
if account.money >= price then
|
||||
|
||||
if xPlayer.getAccount('black_money').money >= price then
|
||||
xPlayer.removeAccountMoney('black_money', price)
|
||||
xPlayer.addWeapon(itemName, 42)
|
||||
TriggerClientEvent('esx:showNotification', source, _U('buy', ESX.GetWeaponLabel(itemName)))
|
||||
xPlayer.addWeapon(weaponName, 42)
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('buy', ESX.GetWeaponLabel(weaponName)))
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', source, _U('not_enough_black'))
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black'))
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if xPlayer.getMoney() >= price then
|
||||
xPlayer.removeMoney(price)
|
||||
xPlayer.addWeapon(itemName, 42)
|
||||
TriggerClientEvent('esx:showNotification', source, _U('buy', ESX.GetWeaponLabel(itemName)))
|
||||
xPlayer.addWeapon(weaponName, 42)
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('buy', ESX.GetWeaponLabel(weaponName)))
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', source, _U('not_enough'))
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
function GetPrice(weaponName, zone)
|
||||
local result = MySQL.Sync.fetchAll('SELECT 1 FROM weashops WHERE zone = @zone AND item = @item', {
|
||||
['@zone'] = zone,
|
||||
['@item'] = weaponName
|
||||
})
|
||||
|
||||
return result[1].price
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user