mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-01 21:01:49 +00:00
feat(license): add license support
This commit is contained in:
+42
-3
@@ -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
@@ -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 = {
|
||||
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user