diff --git a/__resource.lua b/__resource.lua index f6487c62..a31bfb4d 100644 --- a/__resource.lua +++ b/__resource.lua @@ -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' \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index 188840d1..ccc1c905 100644 --- a/client/main.lua +++ b/client/main.lua @@ -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) \ No newline at end of file diff --git a/config.lua b/config.lua index e9f30d60..4ec366dc 100644 --- a/config.lua +++ b/config.lua @@ -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 diff --git a/locales/br.lua b/locales/br.lua index 0cc4e13a..06aca5b7 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -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 ', -} \ No newline at end of file + ['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', +} diff --git a/locales/de.lua b/locales/de.lua index e5c26ff2..6053408c 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -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', } \ No newline at end of file diff --git a/locales/en.lua b/locales/en.lua index 6534c364..0dc26ab0 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -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 ', -} \ No newline at end of file + ['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', +} diff --git a/locales/es.lua b/locales/es.lua index 0abd39b3..befb6ef9 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -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', } diff --git a/locales/fi.lua b/locales/fi.lua index 953735ee..3486fce0 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -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 ', -} \ No newline at end of file + ['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', +} diff --git a/locales/fr.lua b/locales/fr.lua index ac1683a6..bfe267db 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -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é ', -} \ No newline at end of file + ['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', +} diff --git a/server/main.lua b/server/main.lua index 49d8b2b4..b6fbf525 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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)