Cleanup, fixed #6

This commit is contained in:
ElPumpo
2018-11-10 23:47:14 +01:00
parent ad356352dd
commit 5c49d02433
10 changed files with 111 additions and 159 deletions
+22 -20
View File
@@ -1,30 +1,32 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX BarberShop'
description 'ESX Barber Shop'
version '1.0.1'
server_scripts {
'@mysql-async/lib/MySQL.lua',
'@es_extended/locale.lua',
'locales/br.lua',
'locales/de.lua',
'locales/en.lua',
'locales/fi.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'server/main.lua'
'@mysql-async/lib/MySQL.lua',
'@es_extended/locale.lua',
'locales/br.lua',
'locales/de.lua',
'locales/en.lua',
'locales/fi.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'server/main.lua'
}
client_scripts {
'@es_extended/locale.lua',
'locales/br.lua',
'locales/de.lua',
'locales/en.lua',
'locales/fi.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'client/main.lua'
'@es_extended/locale.lua',
'locales/br.lua',
'locales/de.lua',
'locales/en.lua',
'locales/fi.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'client/main.lua'
}
dependency 'es_extended'
+26 -59
View File
@@ -18,20 +18,18 @@ local LastZone = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local CurrentActionData = {}
local HasPayed = false
local HasPaid = false
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function OpenShopMenu()
HasPayed = false
HasPaid = false
TriggerEvent('esx_skin:openRestrictedMenu', function(data, menu)
@@ -43,45 +41,37 @@ function OpenShopMenu()
title = _U('valid_purchase'),
align = 'top-left',
elements = {
{label = _U('yes'), value = 'yes'},
{label = _U('no'), value = 'no'},
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
},
function(data, menu)
menu.close()
if data.current.value == 'yes' then
ESX.TriggerServerCallback('esx_barbershop:checkMoney', function(hasEnoughMoney)
if hasEnoughMoney then
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent('esx_skin:save', skin)
end)
TriggerServerEvent('esx_barbershop:pay')
HasPayed = true
HasPaid = true
else
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
ESX.ShowNotification(_U('not_enough_money'))
end
end)
end
elseif data.current.value == 'no' then
if data.current.value == 'no' then
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
end
@@ -89,27 +79,20 @@ function OpenShopMenu()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_access')
CurrentActionData = {}
end,
function(data, menu)
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_access')
CurrentActionData = {}
end
)
end)
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_access')
CurrentActionData = {}
end, {
'beard_1',
'beard_2',
@@ -144,25 +127,20 @@ AddEventHandler('esx_barbershop:hasEnteredMarker', function(zone)
end)
AddEventHandler('esx_barbershop:hasExitedMarker', function(zone)
ESX.UI.Menu.CloseAll()
CurrentAction = nil
if not HasPayed then
if not HasPaid then
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
end
end)
-- Create Blips
Citizen.CreateThread(function()
for i=1, #Config.Shops, 1 do
local blip = AddBlipForCoord(Config.Shops[i].x, Config.Shops[i].y, Config.Shops[i].z)
SetBlipSprite (blip, 71)
@@ -174,39 +152,36 @@ Citizen.CreateThread(function()
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('barber_blip'))
EndTextCommandSetBlipName(blip)
end
end
end)
-- Display markers
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
Citizen.Wait(0)
local coords = GetEntityCoords(PlayerPedId())
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
if GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x then
isInMarker = true
currentZone = k
end
@@ -222,34 +197,26 @@ Citizen.CreateThread(function()
HasAlreadyEnteredMarker = false
TriggerEvent('esx_barbershop:hasExitedMarker', LastZone)
end
end
end)
-- Key controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
ESX.ShowHelpNotification(CurrentActionMsg)
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 300 then
if IsControlJustReleased(0, Keys['E']) then
if CurrentAction == 'shop_menu' then
OpenShopMenu()
end
CurrentAction = nil
GUI.Time = GetGameTimer()
end
else
Citizen.Wait(500)
end
end
end)
+13 -14
View File
@@ -6,27 +6,26 @@ Config.DrawDistance = 100.0
Config.MarkerSize = {x = 1.5, y = 1.5, z = 1.0}
Config.MarkerColor = {r = 102, g = 102, b = 204}
Config.MarkerType = 1
Config.Locale = 'fr'
Config.Zones = {}
Config.Shops = {
{x = -814.308, y = -183.823, z = 36.568},
{x = 136.826, y = -1708.373, z = 28.291},
{x = -1282.604, y = -1116.757, z = 5.990},
{x = 1931.513, y = 3729.671, z = 31.844},
{x = 1212.840, y = -472.921, z = 65.208},
{x = -32.885, y = -152.319, z = 56.076},
{x = -278.077, y = 6228.463, z = 30.695},
{x = -814.308, y = -183.823, z = 36.568},
{x = 136.826, y = -1708.373, z = 28.291},
{x = -1282.604, y = -1116.757, z = 5.990},
{x = 1931.513, y = 3729.671, z = 31.844},
{x = 1212.840, y = -472.921, z = 65.208},
{x = -32.885, y = -152.319, z = 56.076},
{x = -278.077, y = 6228.463, z = 30.695}
}
for i=1, #Config.Shops, 1 do
Config.Zones['Shop_' .. i] = {
Pos = Config.Shops[i],
Size = Config.MarkerSize,
Color = Config.MarkerColor,
Type = Config.MarkerType
}
Pos = Config.Shops[i],
Size = Config.MarkerSize,
Color = Config.MarkerColor,
Type = Config.MarkerType
}
end
+8 -9
View File
@@ -1,10 +1,9 @@
Locales['br'] = {
['valid_purchase'] = 'validar esta compra?',
['yes'] = 'sim',
['no'] = 'não',
['not_enough_money'] = 'você não tem dinheiro suficiente',
['press_access'] = 'pressione ~INPUT_CONTEXT~ para acessar o menu',
['barber_blip'] = 'Barbearia',
['you_paid'] = 'você pagou ',
}
['valid_purchase'] = 'validar esta compra?',
['yes'] = 'sim',
['no'] = 'não',
['not_enough_money'] = 'você não tem dinheiro suficiente',
['press_access'] = 'pressione ~INPUT_CONTEXT~ para acessar o menu',
['barber_blip'] = 'Barbearia',
['you_paid'] = 'você pagou $%s',
}
+7 -8
View File
@@ -1,10 +1,9 @@
Locales['de'] = {
['valid_purchase'] = 'Einkauf bestätigen?',
['yes'] = 'ja',
['no'] = 'nein',
['not_enough_money'] = 'du hast nicht genug Geld',
['press_access'] = 'Drücke ~INPUT_CONTEXT~ um das Menü zu öffnen',
['barber_blip'] = 'Friseur',
['you_paid'] = 'du bezahlst ',
['valid_purchase'] = 'Einkauf bestätigen?',
['yes'] = 'ja',
['no'] = 'nein',
['not_enough_money'] = 'du hast nicht genug Geld',
['press_access'] = 'Drücke ~INPUT_CONTEXT~ um das Menü zu öffnen',
['barber_blip'] = 'Friseur',
['you_paid'] = 'du bezahlst $%s',
}
+8 -9
View File
@@ -1,10 +1,9 @@
Locales['en'] = {
['valid_purchase'] = 'validate this purchase?',
['yes'] = 'yes',
['no'] = 'no',
['not_enough_money'] = 'you do not have enough money',
['press_access'] = 'press ~INPUT_CONTEXT~ to access the menu',
['barber_blip'] = 'barber shop',
['you_paid'] = 'you paid ',
}
['valid_purchase'] = 'validate this purchase?',
['yes'] = 'yes',
['no'] = 'no',
['not_enough_money'] = 'you do not have enough money',
['press_access'] = 'press ~INPUT_CONTEXT~ to access the menu',
['barber_blip'] = 'barber shop',
['you_paid'] = 'you paid $%s',
}
+7 -8
View File
@@ -1,10 +1,9 @@
Locales['es'] = {
['valid_purchase'] = '¿validar esta compra?',
['yes'] = 'Si',
['no'] = 'No',
['not_enough_money'] = 'No tienes suficente dinero',
['press_access'] = 'Presiona ~INPUT_CONTEXT~ para acceder al menú',
['barber_blip'] = 'Barbero',
['you_paid'] = 'Has pagado ',
['valid_purchase'] = '¿validar esta compra?',
['yes'] = 'si',
['no'] = 'no',
['not_enough_money'] = 'no tienes suficente dinero',
['press_access'] = 'presiona ~INPUT_CONTEXT~ para acceder al menú',
['barber_blip'] = 'barbero',
['you_paid'] = 'has pagado $%s',
}
+8 -9
View File
@@ -1,10 +1,9 @@
Locales['fi'] = {
['valid_purchase'] = 'varmista tämä ostos?',
['yes'] = 'kyllä',
['no'] = 'ei',
['not_enough_money'] = 'sinulla ei ole tarpeeksi rahaa',
['press_access'] = 'paina ~INPUT_CONTEXT~ avataksesi menu',
['barber_blip'] = 'Kampaamo',
['you_paid'] = 'sinä maksoit ',
}
['valid_purchase'] = 'varmista tämä ostos?',
['yes'] = 'kyllä',
['no'] = 'ei',
['not_enough_money'] = 'sinulla ei ole tarpeeksi rahaa',
['press_access'] = 'paina ~INPUT_CONTEXT~ avataksesi menu',
['barber_blip'] = 'Kampaamo',
['you_paid'] = 'sinä maksoit $%s',
}
+8 -9
View File
@@ -1,10 +1,9 @@
Locales['fr'] = {
['valid_purchase'] = 'valider cet achat ?',
['yes'] = 'oui',
['no'] = 'non',
['not_enough_money'] = 'vous n\'avez pas assez d\'argent',
['press_access'] = 'appuez sur ~INPUT_CONTEXT~ pour accéder au menu',
['barber_blip'] = 'barbier',
['you_paid'] = 'vous avez payé ',
}
['valid_purchase'] = 'valider cet achat ?',
['yes'] = 'oui',
['no'] = 'non',
['not_enough_money'] = 'vous n\'avez pas assez d\'argent',
['press_access'] = 'appuez sur ~INPUT_CONTEXT~ pour accéder au menu',
['barber_blip'] = 'barbier',
['you_paid'] = 'vous avez payé $%s',
}
+4 -14
View File
@@ -4,25 +4,15 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('esx_barbershop:pay')
AddEventHandler('esx_barbershop:pay', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeMoney(Config.Price)
TriggerClientEvent('esx:showNotification', source, _U('you_paid') .. '$' .. Config.Price)
TriggerClientEvent('esx:showNotification', source, _U('you_paid', ESX.Math.GroupDigits(Config.Price)))
end)
ESX.RegisterServerCallback('esx_barbershop:checkMoney', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer.get('money') >= Config.Price then
cb(true)
else
cb(false)
end
cb(xPlayer.get('money') >= Config.Price)
end)