Revert "Merge pull request #17 from vecchiotom/master"

This reverts commit 1630375a58, reversing
changes made to 63b75486a1.
This commit is contained in:
ElPumpo
2018-05-08 20:53:23 +02:00
parent 1630375a58
commit 9b6ccb8358
+54 -62
View File
@@ -5,85 +5,77 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
function LoadLicenses (source) function LoadLicenses (source)
TriggerEvent('esx_license:getLicenses', source, function (licenses) TriggerEvent('esx_license:getLicenses', source, function (licenses)
TriggerClientEvent('esx_weashop:loadLicenses', source, licenses) TriggerClientEvent('esx_weashop:loadLicenses', source, licenses)
end) end)
end end
if Config.EnableLicense == true then if Config.EnableLicense == true then
AddEventHandler('esx:playerLoaded', function (source) AddEventHandler('esx:playerLoaded', function (source)
LoadLicenses(source) LoadLicenses(source)
end)
end
function LoadShopItems(cb)
MySQL.Async.fetchAll('SELECT * FROM weashops',
{}, 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 = ESX.GetWeaponLabel(result[i].item)
})
cb(shopItems)
end
end) end)
end end
RegisterServerEvent('esx_weashop:buyLicense') RegisterServerEvent('esx_weashop:buyLicense')
AddEventHandler('esx_weashop:buyLicense', function () AddEventHandler('esx_weashop:buyLicense', function ()
local _source = source local _source = source
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.get('money') >= Config.LicensePrice then if xPlayer.get('money') >= Config.LicensePrice then
xPlayer.removeMoney(Config.LicensePrice) xPlayer.removeMoney(Config.LicensePrice)
TriggerEvent('esx_license:addLicense', _source, 'weapon', function () TriggerEvent('esx_license:addLicense', _source, 'weapon', function ()
LoadLicenses(_source) LoadLicenses(_source)
end) end)
else else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough')) TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end end
end) end)
ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb) ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb)
LoadShopItems(cb) MySQL.Async.fetchAll('SELECT * FROM weashops',
{}, 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 = ESX.GetWeaponLabel(result[i].item)
})
end
cb(shopItems)
end
)
end) end)
RegisterServerEvent('esx_weashop:buyItem') RegisterServerEvent('esx_weashop:buyItem')
AddEventHandler('esx_weashop:buyItem', function(itemName, price, zone) AddEventHandler('esx_weashop:buyItem', function(itemName, price, zone)
LoadShopItems(function(shopItems) local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
local _source = source local account = xPlayer.getAccount('black_money')
local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount('black_money') if zone=="BlackWeashop" then
if price == shopItems[itemName].price then if account.money >= price then
if zone=="BlackWeashop" then xPlayer.removeAccountMoney('black_money', price)
if account.money >= price then xPlayer.addWeapon(itemName, 42)
xPlayer.removeAccountMoney('black_money', price) TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
xPlayer.addWeapon(itemName, 42) else
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black'))
else end
TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black')) else
end if xPlayer.get('money') >= price then
else xPlayer.removeMoney(price)
if xPlayer.get('money') >= price then xPlayer.addWeapon(itemName, 42)
xPlayer.removeMoney(price) TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
xPlayer.addWeapon(itemName, 42) else
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName)) TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
else end
TriggerClientEvent('esx:showNotification', _source, _U('not_enough')) end
end
end
end
end)
end) end)