diff --git a/[esx_addons]/esx_weaponshop/README.md b/[esx_addons]/esx_weaponshop/README.md index 827916e4..b6e29da8 100644 --- a/[esx_addons]/esx_weaponshop/README.md +++ b/[esx_addons]/esx_weaponshop/README.md @@ -2,33 +2,7 @@ ESX Weapon Shop adds.. well you guessed it - weapon shops to the already existing shops in the world. -## Download & Installation - -### Using [fvm](https://github.com/qlaffont/fvm-installer) -``` -fvm install --save --folder=esx esx-org/esx_weaponshop -``` - -### Using Git -``` -cd resources -git clone https://github.com/ESX-Org/esx_weaponshop.git [esx]/esx_weaponshop -``` - -### Manually -- Download https://github.com/ESX-Org/esx_weaponshop/archive/master.zip -- Put it in the `[esx]` directory - -## Installation -- Import `esx_weaponshop.sql` in your database -- Add this to your `server.cfg`: - -``` -start esx_weaponshop -``` - # Legal -### License esx_weaponshop - Legal and illegal weapon shops Copyright (C) 2015-2022 Jérémie N'gadi diff --git a/[esx_addons]/esx_weaponshop/client/main.lua b/[esx_addons]/esx_weaponshop/client/main.lua index d494ba0f..5b7f9d95 100644 --- a/[esx_addons]/esx_weaponshop/client/main.lua +++ b/[esx_addons]/esx_weaponshop/client/main.lua @@ -5,19 +5,6 @@ local CurrentActionMsg = '' local CurrentActionData = {} local ShopOpen = false -ESX.TriggerServerCallback('esx_weaponshop:getShop', function(shopItems) - for k,v in pairs(shopItems) do - Config.Zones[k].Items = v - end -end) - -RegisterNetEvent('esx_weaponshop:sendShop') -AddEventHandler('esx_weaponshop:sendShop', function(shopItems) - for k,v in pairs(shopItems) do - Config.Zones[k].Items = v - end -end) - function OpenBuyLicenseMenu(zone) ESX.UI.Menu.CloseAll() @@ -48,11 +35,12 @@ function OpenShopMenu(zone) for i=1, #Config.Zones[zone].Items, 1 do local item = Config.Zones[zone].Items[i] + item.label = ESX.GetWeaponLabel(item.name) table.insert(elements, { label = ('%s - %s'):format(item.label, _U('shop_menu_item', ESX.Math.GroupDigits(item.price))), price = item.price, - weaponName = item.item + weaponName = item.name }) end @@ -140,7 +128,7 @@ CreateThread(function() SetBlipSprite (blip, 110) SetBlipDisplay(blip, 4) - SetBlipScale (blip, 1.0) + SetBlipScale (blip, 0.8) SetBlipColour (blip, 81) SetBlipAsShortRange(blip, true) @@ -202,11 +190,8 @@ end) -- Key Controls CreateThread(function() - while true do - local Sleep = 1500 - - if CurrentAction ~= nil then - Sleep = 0 + while CurrentAction do + Wait(0) ESX.ShowHelpNotification(CurrentActionMsg) if IsControlJustReleased(0, 38) then @@ -227,7 +212,5 @@ CreateThread(function() CurrentAction = nil end - end - Wait(Sleep) end end) diff --git a/[esx_addons]/esx_weaponshop/config.lua b/[esx_addons]/esx_weaponshop/config.lua index 63a3b425..33da63f4 100644 --- a/[esx_addons]/esx_weaponshop/config.lua +++ b/[esx_addons]/esx_weaponshop/config.lua @@ -1,6 +1,6 @@ Config = {} -Config.DrawDistance = 10 +Config.DrawDistance = 10.0 Config.Size = { x = 1.5, y = 1.5, z = 0.5 } Config.Color = { r = 0, g = 128, b = 255 } Config.Type = 1 @@ -16,7 +16,76 @@ Config.Zones = { GunShop = { Legal = true, - Items = {}, + Items = { + { + name = "WEAPON_PISTOL", + price = 500 + }, + { + name = "WEAPON_FLASHLIGHT", + price = 70 + }, + { + name = "WEAPON_MACHETE", + price = 110 + }, + { + name = "WEAPON_NIGHTSTICK", + price = 150 + }, + { + name = "WEAPON_BAT", + price = 50 + }, + { + name = "WEAPON_STUNGUN", + price = 60 + }, + { + name = "WEAPON_MICROSMG", + price = 1700 + }, + { + name = "WEAPON_ASSAULTRIFLE", + price = 11000 + }, + { + name = "WEAPON_STUNGUN", + price = 60 + }, + { + name = "WEAPON_SPECIALCARBINE", + price = 15000 + }, + { + name = "WEAPON_SNIPERRIFLE", + price = 24000 + }, + { + name = "WEAPON_FIREWORK", + price = 21000 + }, + { + name = "WEAPON_GRENADE", + price = 700 + }, + { + name = "WEAPON_BZGAS", + price = 200 + }, + { + name = "WEAPON_FIREEXTINGUISHER", + price = 100 + }, + { + name = "WEAPON_BALL", + price = 30 + }, + { + name = "WEAPON_SMOKEGRENADE", + price = 100 + }, + }, Locations = { vector3(-662.1, -935.3, 20.8), vector3(810.2, -2157.3, 28.6), @@ -32,10 +101,78 @@ Config.Zones = { BlackWeashop = { Legal = false, - Items = {}, + Items = { + { + name = "WEAPON_PISTOL", + price = 500 + }, + { + name = "WEAPON_FLASHLIGHT", + price = 70 + }, + { + name = "WEAPON_MACHETE", + price = 110 + }, + { + name = "WEAPON_NIGHTSTICK", + price = 150 + }, + { + name = "WEAPON_BAT", + price = 50 + }, + { + name = "WEAPON_STUNGUN", + price = 60 + }, + { + name = "WEAPON_MICROSMG", + price = 1700 + }, + { + name = "WEAPON_ASSAULTRIFLE", + price = 11000 + }, + { + name = "WEAPON_STUNGUN", + price = 60 + }, + { + name = "WEAPON_SPECIALCARBINE", + price = 15000 + }, + { + name = "WEAPON_SNIPERRIFLE", + price = 24000 + }, + { + name = "WEAPON_FIREWORK", + price = 21000 + }, + { + name = "WEAPON_GRENADE", + price = 700 + }, + { + name = "WEAPON_BZGAS", + price = 200 + }, + { + name = "WEAPON_FIREEXTINGUISHER", + price = 100 + }, + { + name = "WEAPON_BALL", + price = 30 + }, + { + name = "WEAPON_SMOKEGRENADE", + price = 100 + }, + }, Locations = { vector3(-1306.2, -394.0, 35.6) } } - } diff --git a/[esx_addons]/esx_weaponshop/esx_weaponshop.sql b/[esx_addons]/esx_weaponshop/esx_weaponshop.sql index 9f866ec5..7f46bb4f 100644 --- a/[esx_addons]/esx_weaponshop/esx_weaponshop.sql +++ b/[esx_addons]/esx_weaponshop/esx_weaponshop.sql @@ -1,58 +1,5 @@ USE `es_extended`; -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, - - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - - INSERT INTO `licenses` (`type`, `label`) VALUES - ('weapon', "Permis de port d'arme") -; - -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), - ('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) + ('weapon', "Weapon licence") ; diff --git a/[esx_addons]/esx_weaponshop/fxmanifest.lua b/[esx_addons]/esx_weaponshop/fxmanifest.lua index 64296bf3..3e038edc 100644 --- a/[esx_addons]/esx_weaponshop/fxmanifest.lua +++ b/[esx_addons]/esx_weaponshop/fxmanifest.lua @@ -14,7 +14,6 @@ shared_scripts { } server_scripts { - '@oxmysql/lib/MySQL.lua', 'server/main.lua' } diff --git a/[esx_addons]/esx_weaponshop/server/main.lua b/[esx_addons]/esx_weaponshop/server/main.lua index 2f19e15b..75a7d5ca 100644 --- a/[esx_addons]/esx_weaponshop/server/main.lua +++ b/[esx_addons]/esx_weaponshop/server/main.lua @@ -1,28 +1,3 @@ -local shopItems = {} - -MySQL.ready(function() - - MySQL.query('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_weaponshop:sendShop', -1, shopItems) - end) - -end) - -ESX.RegisterServerCallback('esx_weaponshop:getShop', function(source, cb) - cb(shopItems) -end) ESX.RegisterServerCallback('esx_weaponshop:buyLicense', function(source, cb) local xPlayer = ESX.GetPlayerFromId(source) @@ -77,13 +52,16 @@ ESX.RegisterServerCallback('esx_weaponshop:buyWeapon', function(source, cb, weap end) function GetPrice(weaponName, zone) - local price = MySQL.scalar.await('SELECT price FROM weashops WHERE zone = @zone AND item = @item', { - ['@zone'] = zone, - ['@item'] = weaponName - }) + local weapon = nil + for k,v in pairs(Config.Zones[zone].items) + if v.name == weaponName then + weapon = v + break + end + end - if price then - return price + if weapon then + return v.price else return 0 end