mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-01 18:58:54 +00:00
Further cleanup
This commit is contained in:
+78
-128
@@ -1,24 +1,5 @@
|
||||
local Keys = {
|
||||
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
|
||||
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
|
||||
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
|
||||
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
|
||||
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
|
||||
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
|
||||
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
|
||||
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
|
||||
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
|
||||
}
|
||||
|
||||
ESX = nil
|
||||
local GUI = {}
|
||||
GUI.Time = 0
|
||||
local HasAlreadyEnteredMarker = false
|
||||
local LastZone = nil
|
||||
local CurrentAction = nil
|
||||
local CurrentActionMsg = ''
|
||||
local CurrentActionData = {}
|
||||
local HasPaid = false
|
||||
ESX = nil
|
||||
local hasAlreadyEnteredMarker, lastZone, currentAction, currentActionMsg, hasPaid
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
@@ -28,71 +9,55 @@ Citizen.CreateThread(function()
|
||||
end)
|
||||
|
||||
function OpenShopMenu()
|
||||
|
||||
HasPaid = false
|
||||
hasPaid = false
|
||||
|
||||
TriggerEvent('esx_skin:openRestrictedMenu', function(data, menu)
|
||||
|
||||
menu.close()
|
||||
|
||||
ESX.UI.Menu.Open(
|
||||
'default', GetCurrentResourceName(), 'shop_confirm',
|
||||
{
|
||||
title = _U('valid_purchase'),
|
||||
align = 'top-left',
|
||||
elements = {
|
||||
{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')
|
||||
|
||||
HasPaid = true
|
||||
else
|
||||
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
|
||||
TriggerEvent('skinchanger:loadSkin', skin)
|
||||
end)
|
||||
|
||||
ESX.ShowNotification(_U('not_enough_money'))
|
||||
end
|
||||
end)
|
||||
|
||||
elseif data.current.value == 'no' then
|
||||
|
||||
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
|
||||
TriggerEvent('skinchanger:loadSkin', skin)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
CurrentAction = 'shop_menu'
|
||||
CurrentActionMsg = _U('press_access')
|
||||
CurrentActionData = {}
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
|
||||
CurrentAction = 'shop_menu'
|
||||
CurrentActionMsg = _U('press_access')
|
||||
CurrentActionData = {}
|
||||
end)
|
||||
|
||||
end, function(data, menu)
|
||||
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
|
||||
title = _U('valid_purchase'),
|
||||
align = 'top-left',
|
||||
elements = {
|
||||
{label = _U('no'), value = 'no'},
|
||||
{label = _U('yes'), value = 'yes'}
|
||||
}}, function(data, menu)
|
||||
menu.close()
|
||||
|
||||
CurrentAction = 'shop_menu'
|
||||
CurrentActionMsg = _U('press_access')
|
||||
CurrentActionData = {}
|
||||
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')
|
||||
hasPaid = true
|
||||
else
|
||||
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
|
||||
TriggerEvent('skinchanger:loadSkin', skin)
|
||||
end)
|
||||
|
||||
ESX.ShowNotification(_U('not_enough_money'))
|
||||
end
|
||||
end)
|
||||
elseif data.current.value == 'no' then
|
||||
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
|
||||
TriggerEvent('skinchanger:loadSkin', skin)
|
||||
end)
|
||||
end
|
||||
|
||||
currentAction = 'shop_menu'
|
||||
currentActionMsg = _U('press_access')
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
currentAction = 'shop_menu'
|
||||
currentActionMsg = _U('press_access')
|
||||
end)
|
||||
end, function(data, menu)
|
||||
menu.close()
|
||||
|
||||
currentAction = 'shop_menu'
|
||||
currentActionMsg = _U('press_access')
|
||||
end, {
|
||||
'beard_1',
|
||||
'beard_2',
|
||||
@@ -117,85 +82,70 @@ function OpenShopMenu()
|
||||
'ears_1',
|
||||
'ears_2',
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
AddEventHandler('esx_barbershop:hasEnteredMarker', function(zone)
|
||||
CurrentAction = 'shop_menu'
|
||||
CurrentActionMsg = _U('press_access')
|
||||
CurrentActionData = {}
|
||||
currentAction = 'shop_menu'
|
||||
currentActionMsg = _U('press_access')
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_barbershop:hasExitedMarker', function(zone)
|
||||
ESX.UI.Menu.CloseAll()
|
||||
CurrentAction = nil
|
||||
currentAction = nil
|
||||
|
||||
if not HasPaid then
|
||||
if not hasPaid then
|
||||
ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
|
||||
TriggerEvent('skinchanger:loadSkin', 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)
|
||||
for k,v in ipairs(Config.Shops) do
|
||||
local blip = AddBlipForCoord(v)
|
||||
|
||||
SetBlipSprite (blip, 71)
|
||||
SetBlipDisplay(blip, 4)
|
||||
SetBlipScale (blip, 1.0)
|
||||
SetBlipColour (blip, 51)
|
||||
SetBlipAsShortRange(blip, true)
|
||||
|
||||
BeginTextCommandSetBlipName("STRING")
|
||||
AddTextComponentString(_U('barber_blip'))
|
||||
BeginTextCommandSetBlipName('STRING')
|
||||
AddTextComponentSubstringPlayerName(_U('barber_blip'))
|
||||
EndTextCommandSetBlipName(blip)
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
-- Display markers
|
||||
-- Enter / Exit marker events and draw marker
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
local playerCoords, isInMarker, currentZone, letSleep = GetEntityCoords(PlayerPedId()), nil, nil, true
|
||||
|
||||
local coords = GetEntityCoords(PlayerPedId())
|
||||
for k,v in ipairs(Config.Shops) do
|
||||
local distnace = #(playerCoords - v)
|
||||
|
||||
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)
|
||||
if distance < Config.DrawDistance then
|
||||
letSleep = false
|
||||
DrawMarker(Config.MarkerType, v, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false)
|
||||
|
||||
-- Enter / Exit marker events
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(200)
|
||||
|
||||
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
|
||||
isInMarker = true
|
||||
currentZone = k
|
||||
if distnace < 1.5 then
|
||||
isInMarker, currentZone = true, k
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
|
||||
HasAlreadyEnteredMarker = true
|
||||
LastZone = currentZone
|
||||
if (isInMarker and not hasAlreadyEnteredMarker) or (isInMarker and lastZone ~= currentZone) then
|
||||
hasAlreadyEnteredMarker, lastZone = true, currentZone
|
||||
TriggerEvent('esx_barbershop:hasEnteredMarker', currentZone)
|
||||
end
|
||||
|
||||
if not isInMarker and HasAlreadyEnteredMarker then
|
||||
HasAlreadyEnteredMarker = false
|
||||
TriggerEvent('esx_barbershop:hasExitedMarker', LastZone)
|
||||
if not isInMarker and hasAlreadyEnteredMarker then
|
||||
hasAlreadyEnteredMarker = false
|
||||
TriggerEvent('esx_barbershop:hasExitedMarker', lastZone)
|
||||
end
|
||||
|
||||
if letSleep then
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -205,15 +155,15 @@ Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
if CurrentAction ~= nil then
|
||||
ESX.ShowHelpNotification(CurrentActionMsg)
|
||||
if currentAction then
|
||||
ESX.ShowHelpNotification(currentActionMsg)
|
||||
|
||||
if IsControlJustReleased(0, Keys['E']) then
|
||||
if CurrentAction == 'shop_menu' then
|
||||
if IsControlJustReleased(0, 38) then
|
||||
if currentAction == 'shop_menu' then
|
||||
OpenShopMenu()
|
||||
end
|
||||
|
||||
CurrentAction = nil
|
||||
currentAction = nil
|
||||
end
|
||||
else
|
||||
Citizen.Wait(500)
|
||||
|
||||
+9
-20
@@ -3,29 +3,18 @@ Config = {}
|
||||
Config.Price = 100
|
||||
|
||||
Config.DrawDistance = 100.0
|
||||
Config.MarkerSize = {x = 1.5, y = 1.5, z = 1.0}
|
||||
Config.MarkerSize = vector3(1.5, 1.5, 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}
|
||||
}
|
||||
|
||||
for i=1, #Config.Shops, 1 do
|
||||
Config.Zones['Shop_' .. i] = {
|
||||
Pos = Config.Shops[i],
|
||||
Size = Config.MarkerSize,
|
||||
Color = Config.MarkerColor,
|
||||
Type = Config.MarkerType
|
||||
}
|
||||
end
|
||||
vector3(-814.3, -183.8, 36.6),
|
||||
vector3(136.8, -1708.4, 28.3),
|
||||
vector3(-1282.6, -1116.8, 6.0),
|
||||
vector3(1931.5, 3729.7, 31.8),
|
||||
vector3(1212.8, -472.9, 65.2),
|
||||
vector3(-32.9, -152.3, 56.1),
|
||||
vector3(-278.1, 6228.5, 30.7)
|
||||
}
|
||||
+3
-3
@@ -3,7 +3,7 @@ Locales['en'] = {
|
||||
['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',
|
||||
['press_access'] = 'press ~INPUT_CONTEXT~ to access the ~y~Barber Shop~s~.',
|
||||
['barber_blip'] = 'barber Shop',
|
||||
['you_paid'] = 'you paid ~g~$%s~s~',
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ end)
|
||||
ESX.RegisterServerCallback('esx_barbershop:checkMoney', function(source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
cb(xPlayer.get('money') >= Config.Price)
|
||||
cb(xPlayer.getMoney() >= Config.Price)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user