feat(license): add license support

This commit is contained in:
Romain Lanz
2017-10-14 23:55:24 +02:00
parent 4803dac2f5
commit 29d96bf1af
5 changed files with 85 additions and 10 deletions
+42 -3
View File
@@ -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
+8 -7
View File
@@ -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 = {
+3
View File
@@ -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',
+3
View File
@@ -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',
+29
View File
@@ -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(