diff --git a/README.md b/README.md
index 3e851a93..e3b90b2a 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/client/main.lua b/client/main.lua
index 63b85064..aac235c5 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -47,12 +47,12 @@ function OpenBuyLicenseMenu(zone)
{ label = _U('yes', ('%s'):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 - %s'):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
diff --git a/esx_weashops.sql b/esx_weashops.sql
index ca1f2bc9..28e5744e 100644
--- a/esx_weashops.sql
+++ b/esx_weashops.sql
@@ -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),
diff --git a/localization/fi_esx_weashops.sql b/localization/fi_esx_weashops.sql
deleted file mode 100644
index f6e7cb68..00000000
--- a/localization/fi_esx_weashops.sql
+++ /dev/null
@@ -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)
-;
diff --git a/server/main.lua b/server/main.lua
index 7412e593..ba6e5ba8 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -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