diff --git a/client/main.lua b/client/main.lua index ef34d62f..74017497 100644 --- a/client/main.lua +++ b/client/main.lua @@ -4,6 +4,7 @@ local LastZone = nil local CurrentAction = nil local CurrentActionMsg = '' local CurrentActionData = {} +local Licenses = {} Citizen.CreateThread(function() while ESX == nil do @@ -12,16 +13,46 @@ Citizen.CreateThread(function() end end) -AddEventHandler('onClientMapStart', function() +RegisterNetEvent('esx_weashop:loadLicenses') +AddEventHandler('esx_weashop:loadLicenses', function (licenses) + for i = 0, #licenses, 1 do + Licenses[licenses[i].type] = true + end +end) +AddEventHandler('onClientMapStart', function() ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems) for k,v in pairs(ShopItems) do Config.Zones[k].Items = v end end) - end) +function OpenBuyLicenseMenu (zone) + ESX.UI.Menu.CloseAll() + + ESX.UI.Menu.Open( + 'default', GetCurrentResourceName(), 'shop_license', + { + title = _U('buy_license'), + elements = { + { label = _U('yes') .. ' ($' .. Config.LicensePrice .. ')', value = 'yes' }, + { label = _U('no'), value = 'no' }, + } + }, + function (data, menu) + if data.current.value == 'yes' then + TriggerServerEvent('esx_weashop:buyLicense') + end + + menu.close() + end, + function (data, menu) + menu.close() + end + ) +end + function OpenShopMenu(zone) local elements = {} @@ -153,7 +184,15 @@ Citizen.CreateThread(function() if IsControlJustReleased(0, 38) then if CurrentAction == 'shop_menu' then - OpenShopMenu(CurrentActionData.zone) + if Config.EnableLicense == true then + if Licenses['weapon'] ~= nil or Config.Zones[CurrentActionData.zone].legal == 1 then + OpenShopMenu(CurrentActionData.zone) + else + OpenBuyLicenseMenu() + end + else + OpenShopMenu(CurrentActionData.zone) + end end CurrentAction = nil diff --git a/config.lua b/config.lua index 00e32e1d..b7d0b9ef 100644 --- a/config.lua +++ b/config.lua @@ -1,10 +1,11 @@ -Config = {} - -Config.DrawDistance = 100 -Config.Size = { x = 1.5, y = 1.5, z = 1.5 } -Config.Color = { r = 0, g = 128, b = 255 } -Config.Type = 1 -Config.Locale = 'fr' +Config = {} +Config.DrawDistance = 100 +Config.Size = { x = 1.5, y = 1.5, z = 1.5 } +Config.Color = { r = 0, g = 128, b = 255 } +Config.Type = 1 +Config.Locale = 'fr' +Config.EnableLicense = true +Config.LicensePrice = 5000 Config.Zones = { diff --git a/locales/en.lua b/locales/en.lua index ff62d147..e0fab708 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,5 +1,8 @@ Locales ['en'] = { + ['buy_license'] = 'buy a license?', + ['yes'] = 'yes', + ['no'] = 'no', ['buy'] = 'you bought', ['not_enough_black'] = 'you do not have enough dirty money', ['not_enough'] = 'you do not have enough money', diff --git a/locales/fr.lua b/locales/fr.lua index 91eb81d5..8f9b2862 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,5 +1,8 @@ Locales ['fr'] = { + ['buy_license'] = 'acheter une license ?', + ['yes'] = 'oui', + ['no'] = 'non', ['buy'] = 'vous avez acheté ~b~1x ', ['not_enough_black'] = 'Vous n\'avez ~r~pas assez~s~ d\'argent sale', ['not_enough'] = 'vous n\'avez ~r~pas assez~s~ d\'argent', diff --git a/server/main.lua b/server/main.lua index e8822f8b..ff9b2c29 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,6 +3,35 @@ local ItemsLabels = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +function LoadLicenses (source) + 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) + LoadLicenses(source) + end) +end + +RegisterServerEvent('esx_weashop:buyLicense') +AddEventHandler('esx_weashop:buyLicense', function () + local _source = source + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.get('money') >= Config.LicensePrice then + xPlayer.removeMoney(Config.LicensePrice) + + TriggerEvent('esx_license:addLicense', _source, 'weapon', function () + LoadLicenses(_source) + end) + else + TriggerClientEvent('esx:showNotification', _source, _U('not_enough')) + end +end) + + ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb) MySQL.Async.fetchAll(