Minor cleanup

This commit is contained in:
ElPumpo
2018-12-04 19:43:58 +01:00
parent 5bd0bb1895
commit c915b1b5e3
2 changed files with 22 additions and 19 deletions
+20 -17
View File
@@ -16,24 +16,23 @@ Citizen.CreateThread(function()
end end
end) end)
function ShowJobListingMenu(data) function ShowJobListingMenu()
ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(data) ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(data)
local elements = {} local elements = {}
for i = 1, #data, 1 do for i = 1, #data, 1 do
table.insert(elements, {label = data[i].label, value = data[i].value}) table.insert(elements, {
label = data[i].label,
job = data[i].job
})
end end
ESX.UI.Menu.CloseAll() ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'joblisting', {
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'joblisting',
{
title = _U('job_center'), title = _U('job_center'),
align = 'top-left', align = 'top-left',
elements = elements elements = elements
}, function(data, menu) }, function(data, menu)
TriggerServerEvent('esx_joblisting:setJob', data.current.value) TriggerServerEvent('esx_joblisting:setJob', data.current.job)
ESX.ShowNotification(_U('new_job')) ESX.ShowNotification(_U('new_job'))
menu.close() menu.close()
end, function(data, menu) end, function(data, menu)
@@ -51,9 +50,9 @@ end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(1) Citizen.Wait(1)
local coords = GetEntityCoords(GetPlayerPed(-1)) local coords = GetEntityCoords(PlayerPedId())
for i=1, #Config.Zones, 1 do for i=1, #Config.Zones, 1 do
if(GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < Config.DrawDistance) then if GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < Config.DrawDistance then
DrawMarker(Config.MarkerType, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false) DrawMarker(Config.MarkerType, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
end end
end end
@@ -64,20 +63,20 @@ end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(1) Citizen.Wait(1)
local coords = GetEntityCoords(GetPlayerPed(-1))
isInJoblistingMarker = false local coords, isInJoblistingMarker, currentZone = GetEntityCoords(PlayerPedId()), false, nil
local currentZone = nil
for i=1, #Config.Zones, 1 do for i=1, #Config.Zones, 1 do
if(GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < Config.ZoneSize.x / 2) then if GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < (Config.ZoneSize.x / 2) then
isInJoblistingMarker = true isInJoblistingMarker = true
SetTextComponentFormat('STRING') ESX.ShowHelpNotification(_U('access_job_center'))
AddTextComponentString(_U('access_job_center'))
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end end
end end
if isInJoblistingMarker and not hasAlreadyEnteredMarker then if isInJoblistingMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true hasAlreadyEnteredMarker = true
end end
if not isInJoblistingMarker and hasAlreadyEnteredMarker then if not isInJoblistingMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false hasAlreadyEnteredMarker = false
TriggerEvent('esx_joblisting:hasExitedMarker') TriggerEvent('esx_joblisting:hasExitedMarker')
@@ -89,11 +88,13 @@ end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
for i=1, #Config.Zones, 1 do for i=1, #Config.Zones, 1 do
local blip = AddBlipForCoord(Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z) local blip = AddBlipForCoord(Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z)
SetBlipSprite (blip, 407) SetBlipSprite (blip, 407)
SetBlipDisplay(blip, 4) SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.2) SetBlipScale (blip, 1.2)
SetBlipColour (blip, 27) SetBlipColour (blip, 27)
SetBlipAsShortRange(blip, true) SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING") BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('job_center')) AddTextComponentString(_U('job_center'))
EndTextCommandSetBlipName(blip) EndTextCommandSetBlipName(blip)
@@ -104,7 +105,9 @@ end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(10) Citizen.Wait(10)
if IsControlJustReleased(0, Keys['E']) and isInJoblistingMarker and not menuIsShowed then if IsControlJustReleased(0, Keys['E']) and isInJoblistingMarker and not menuIsShowed then
ESX.UI.Menu.CloseAll()
ShowJobListingMenu() ShowJobListingMenu()
end end
end end
+2 -2
View File
@@ -9,8 +9,8 @@ ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb)
for i=1, #result, 1 do for i=1, #result, 1 do
table.insert(data, { table.insert(data, {
value = result[i].name, job = result[i].name,
label = result[i].label label = result[i].label
}) })
end end