mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Get price server side
This commit is contained in:
@@ -27,7 +27,7 @@ start esx_weashops
|
||||
|
||||
# Legal
|
||||
### License
|
||||
esx_weashops - Legal or illegal gun shop
|
||||
esx_weashops - Legal and illegal weapon shop
|
||||
|
||||
Copyright (C) 2015-2018 Jérémie N'gadi
|
||||
|
||||
|
||||
+6
-7
@@ -47,12 +47,12 @@ function OpenBuyLicenseMenu(zone)
|
||||
{ label = _U('yes', ('<span style="color: green;">%s</span>'):format(ESX.Math.GroupDigits(_U('shop_menu_item', Config.LicensePrice)))), value = 'yes' },
|
||||
{ label = _U('no'), value = 'no' }
|
||||
}
|
||||
}, function (data, menu)
|
||||
}, function(data, menu)
|
||||
if data.current.value == 'yes' then
|
||||
TriggerServerEvent('esx_weashop:buyLicense')
|
||||
end
|
||||
menu.close()
|
||||
end, function (data, menu)
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
end)
|
||||
end
|
||||
@@ -65,8 +65,7 @@ function OpenShopMenu(zone)
|
||||
|
||||
table.insert(elements, {
|
||||
label = ('%s - <span style="color: green;">%s</span>'):format(item.label, ESX.Math.GroupDigits(_U('shop_menu_item', item.price))),
|
||||
weaponName = item.item,
|
||||
price = item.price
|
||||
weaponName = item.item
|
||||
})
|
||||
end
|
||||
|
||||
@@ -76,7 +75,7 @@ function OpenShopMenu(zone)
|
||||
title = _U('shop'),
|
||||
elements = elements
|
||||
}, function(data, menu)
|
||||
TriggerServerEvent('esx_weashop:buyItem', data.current.weaponName, data.current.price, zone)
|
||||
TriggerServerEvent('esx_weashop:buyItem', data.current.weaponName, zone)
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
|
||||
@@ -145,7 +144,7 @@ Citizen.CreateThread(function()
|
||||
local currentZone = nil
|
||||
|
||||
for k,v in pairs(Config.Zones) do
|
||||
for i = 1, #v.Pos, 1 do
|
||||
for i=1, #v.Pos, 1 do
|
||||
if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then
|
||||
isInMarker = true
|
||||
ShopItems = v.Items
|
||||
@@ -176,7 +175,7 @@ Citizen.CreateThread(function()
|
||||
|
||||
if IsControlJustReleased(0, Keys['E']) then
|
||||
if CurrentAction == 'shop_menu' then
|
||||
if Config.EnableLicense then
|
||||
if Config.LicenseEnable then
|
||||
if Licenses['weapon'] ~= nil or Config.Zones[CurrentActionData.zone].legal == 1 then
|
||||
OpenShopMenu(CurrentActionData.zone)
|
||||
else
|
||||
|
||||
+10
-11
@@ -1,22 +1,21 @@
|
||||
USE `essentialmode`;
|
||||
|
||||
CREATE TABLE `weashops` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`zone` varchar(255) NOT NULL,
|
||||
`item` varchar(255) NOT NULL,
|
||||
`price` int(11) NOT NULL,
|
||||
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`item` varchar(255) NOT NULL,
|
||||
`price` int(11) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
INSERT INTO `licenses` (type, label) VALUES
|
||||
('weapon', "Permis de port d'arme")
|
||||
INSERT INTO `licenses` (`type`, `label`) VALUES
|
||||
('weapon', "Permis de port d'arme")
|
||||
;
|
||||
|
||||
INSERT INTO `weashops` (name, item, price) VALUES
|
||||
('GunShop','WEAPON_PISTOL',300),
|
||||
('BlackWeashop','WEAPON_PISTOL',500),
|
||||
INSERT INTO `weashops` (`zone` `item`, `price`) VALUES
|
||||
('GunShop','WEAPON_PISTOL', 300),
|
||||
('BlackWeashop','WEAPON_PISTOL', 500),
|
||||
('GunShop', 'WEAPON_FLASHLIGHT', 60),
|
||||
('BlackWeashop', 'WEAPON_FLASHLIGHT', 70),
|
||||
('GunShop', 'WEAPON_MACHETE', 90),
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
USE `essentialmode`;
|
||||
|
||||
CREATE TABLE `weashops` (
|
||||
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`item` varchar(255) NOT NULL,
|
||||
`price` int(11) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
INSERT INTO `licenses` (type, label) VALUES
|
||||
('weapon', "Aselupa")
|
||||
;
|
||||
|
||||
INSERT INTO `weashops` (name, item, price) VALUES
|
||||
('GunShop','WEAPON_PISTOL',300),
|
||||
('BlackWeashop','WEAPON_PISTOL',500),
|
||||
('GunShop', 'WEAPON_FLASHLIGHT', 60),
|
||||
('BlackWeashop', 'WEAPON_FLASHLIGHT', 70),
|
||||
('GunShop', 'WEAPON_MACHETE', 90),
|
||||
('BlackWeashop', 'WEAPON_MACHETE', 110),
|
||||
('GunShop', 'WEAPON_NIGHTSTICK', 150),
|
||||
('BlackWeashop', 'WEAPON_NIGHTSTICK', 150),
|
||||
('GunShop', 'WEAPON_BAT', 100),
|
||||
('BlackWeashop', 'WEAPON_BAT', 100),
|
||||
('GunShop', 'WEAPON_STUNGUN', 50),
|
||||
('BlackWeashop', 'WEAPON_STUNGUN', 50),
|
||||
('GunShop', 'WEAPON_MICROSMG', 1400),
|
||||
('BlackWeashop', 'WEAPON_MICROSMG', 1700),
|
||||
('GunShop', 'WEAPON_PUMPSHOTGUN', 3400),
|
||||
('BlackWeashop', 'WEAPON_PUMPSHOTGUN', 3500),
|
||||
('GunShop', 'WEAPON_ASSAULTRIFLE', 10000),
|
||||
('BlackWeashop', 'WEAPON_ASSAULTRIFLE', 11000),
|
||||
('GunShop', 'WEAPON_SPECIALCARBINE', 15000),
|
||||
('BlackWeashop', 'WEAPON_SPECIALCARBINE', 16500),
|
||||
('GunShop', 'WEAPON_SNIPERRIFLE', 22000),
|
||||
('BlackWeashop', 'WEAPON_SNIPERRIFLE', 24000),
|
||||
('GunShop', 'WEAPON_FIREWORK', 18000),
|
||||
('BlackWeashop', 'WEAPON_FIREWORK', 20000),
|
||||
('GunShop', 'WEAPON_GRENADE', 500),
|
||||
('BlackWeashop', 'WEAPON_GRENADE', 650),
|
||||
('GunShop', 'WEAPON_BZGAS', 200),
|
||||
('BlackWeashop', 'WEAPON_BZGAS', 350),
|
||||
('GunShop', 'WEAPON_FIREEXTINGUISHER', 100),
|
||||
('BlackWeashop', 'WEAPON_FIREEXTINGUISHER', 100),
|
||||
('GunShop', 'WEAPON_BALL', 50),
|
||||
('BlackWeashop', 'WEAPON_BALL', 50),
|
||||
('GunShop', 'WEAPON_SMOKEGRENADE', 100),
|
||||
('BlackWeashop', 'WEAPON_SMOKEGRENADE', 100),
|
||||
('BlackWeashop', 'WEAPON_APPISTOL', 1100),
|
||||
('BlackWeashop', 'WEAPON_CARBINERIFLE', 12000),
|
||||
('BlackWeashop', 'WEAPON_HEAVYSNIPER', 30000),
|
||||
('BlackWeashop', 'WEAPON_MINIGUN', 45000),
|
||||
('BlackWeashop', 'WEAPON_RAILGUN', 50000),
|
||||
('BlackWeashop', 'WEAPON_STICKYBOMB', 500)
|
||||
;
|
||||
+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