diff --git a/[esx_addons]/esx_joblisting/README.md b/[esx_addons]/esx_joblisting/README.md index 3af12895..ab7707a6 100644 --- a/[esx_addons]/esx_joblisting/README.md +++ b/[esx_addons]/esx_joblisting/README.md @@ -1,34 +1,11 @@ # esx_joblisting -Simple job listing script, you can specify what jobs you want to be whitelisted in db. +Simple job listing/Job Centre script, you can specify what jobs you want to be whitelisted in db. -## Download & Installation +## Legal -### Using [fvm](https://github.com/qlaffont/fvm-installer) -``` -fvm install --save --folder=esx esx-org/esx_joblisting -``` - -### Using Git -``` -cd resources -git clone https://github.com/ESX-Org/esx_joblisting [esx]/esx_joblisting -``` - -### Manually -- Download https://github.com/ESX-Org/esx_joblisting/archive/master.zip -- Put it in the `[esx]` directory - -## Installation -- Import `esx_joblisting.sql` in your database -- Add this in your `server.cfg`: - -``` -start esx_joblisting -``` - -# Legal ### License + esx_joblisting - job listing script Copyright (C) 2015-2022 Jérémie N'gadi diff --git a/[esx_addons]/esx_joblisting/client/main.lua b/[esx_addons]/esx_joblisting/client/main.lua index 811eac57..d21c5a1d 100644 --- a/[esx_addons]/esx_joblisting/client/main.lua +++ b/[esx_addons]/esx_joblisting/client/main.lua @@ -1,13 +1,14 @@ -local menuIsShowed, hasAlreadyEnteredMarker, isInMarker = false, false, false +local menuIsShowed = false function ShowJobListingMenu() + menuIsShowed = true ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(jobs) local elements = {} - for i=1, #jobs, 1 do + for k,v in pairs(jobs) do table.insert(elements, { - label = jobs[i].label, - job = jobs[i].job + label = v.label, + job = k }) end @@ -18,8 +19,10 @@ function ShowJobListingMenu() }, function(data, menu) TriggerServerEvent('esx_joblisting:setJob', data.current.job) ESX.ShowNotification(_U('new_job')) + menuIsShowed = false menu.close() end, function(data, menu) + menuIsShowed = false menu.close() end) @@ -33,7 +36,7 @@ end) -- Activate menu when player is inside marker, and draw markers CreateThread(function() while true do - Wait(0) + local Sleep = 1500 local coords = GetEntityCoords(PlayerPedId()) isInMarker = false @@ -42,23 +45,24 @@ CreateThread(function() local distance = #(coords - Config.Zones[i]) if distance < Config.DrawDistance then + Sleep = 0 DrawMarker(Config.MarkerType, Config.Zones[i], 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) + else + if menuIsShowed then + ESX.UI.Menu.CloseAll() + menuIsShowed = false + end end if distance < (Config.ZoneSize.x / 2) then - isInMarker = true ESX.ShowHelpNotification(_U('access_job_center')) + if IsControlJustReleased(0, 38) and not menuIsShowed then + ESX.UI.Menu.CloseAll() + ShowJobListingMenu() + end end end - - if isInMarker and not hasAlreadyEnteredMarker then - hasAlreadyEnteredMarker = true - end - - if not isInMarker and hasAlreadyEnteredMarker then - hasAlreadyEnteredMarker = false - TriggerEvent('esx_joblisting:hasExitedMarker') - end + Wait(Sleep) end end) @@ -67,26 +71,14 @@ CreateThread(function() for i=1, #Config.Zones, 1 do local blip = AddBlipForCoord(Config.Zones[i]) - SetBlipSprite (blip, 407) - SetBlipDisplay(blip, 4) - SetBlipScale (blip, 1.2) - SetBlipColour (blip, 27) - SetBlipAsShortRange(blip, true) + SetBlipSprite (blip, Config.Blip.Sprite) + SetBlipDisplay(blip, Config.Blip.Display) + SetBlipScale (blip, Config.Blip.Scale) + SetBlipColour (blip, Config.Blip.Colour) + SetBlipAsShortRange(blip, Config.Blip.ShortRange) BeginTextCommandSetBlipName("STRING") AddTextComponentSubstringPlayerName(_U('job_center')) EndTextCommandSetBlipName(blip) end end) - --- Menu Controls -CreateThread(function() - while true do - Wait(0) - - if IsControlJustReleased(0, 38) and isInMarker and not menuIsShowed then - ESX.UI.Menu.CloseAll() - ShowJobListingMenu() - end - end -end) diff --git a/[esx_addons]/esx_joblisting/config.lua b/[esx_addons]/esx_joblisting/config.lua index 72dbdcb9..a053d362 100644 --- a/[esx_addons]/esx_joblisting/config.lua +++ b/[esx_addons]/esx_joblisting/config.lua @@ -1,12 +1,20 @@ Config = {} Config.DrawDistance = 10.0 -Config.ZoneSize = {x = 3.0, y = 3.0, z = 0.5} -Config.MarkerColor = {r = 100, g = 100, b = 204} -Config.MarkerType = 1 +Config.ZoneSize = {x = 2.7, y = 2.7, z = 0.5} +Config.MarkerColor = {r = 100, g = 200, b = 104} +Config.MarkerType = 27 Config.Locale = 'en' Config.Zones = { - vector3(-265.0, -963.6, 30.2) + vector3(-265.08, -964.1, 30.3) } + +Config.Blip = { + Sprite = 407, + Display = 4, + Scale = 0.9, + Colour = 27, + ShortRange = true +} \ No newline at end of file diff --git a/[esx_addons]/esx_joblisting/fxmanifest.lua b/[esx_addons]/esx_joblisting/fxmanifest.lua index c5e4bd50..16c15c27 100644 --- a/[esx_addons]/esx_joblisting/fxmanifest.lua +++ b/[esx_addons]/esx_joblisting/fxmanifest.lua @@ -6,36 +6,19 @@ description 'ESX Job Listing' version '1.6.5' -shared_script '@es_extended/imports.lua' - +shared_scripts { + '@es_extended/imports.lua', + '@es_extended/locale.lua', + 'config.lua' +} server_scripts { '@oxmysql/lib/MySQL.lua', - '@es_extended/locale.lua', - 'config.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fi.lua', - 'locales/fr.lua', - 'locales/es.lua', - 'locales/sv.lua', - 'locales/pl.lua', - 'locales/cs.lua', + 'locales/*.lua', 'server/main.lua' } client_scripts { - '@es_extended/locale.lua', - 'config.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fi.lua', - 'locales/fr.lua', - 'locales/es.lua', - 'locales/sv.lua', - 'locales/pl.lua', - 'locales/cs.lua', + 'locales/*.lua', 'client/main.lua' } diff --git a/[esx_addons]/esx_joblisting/server/main.lua b/[esx_addons]/esx_joblisting/server/main.lua index 732010e5..823f10b3 100644 --- a/[esx_addons]/esx_joblisting/server/main.lua +++ b/[esx_addons]/esx_joblisting/server/main.lua @@ -1,32 +1,37 @@ local availableJobs = {} -MySQL.ready(function() - MySQL.query('SELECT name, label FROM jobs WHERE whitelisted = @whitelisted', { - ['@whitelisted'] = false - }, function(result) - for i=1, #result, 1 do - table.insert(availableJobs, { - job = result[i].name, - label = result[i].label - }) - end - end) -end) +for k,v in pairs(ESX.Jobs) do + print(v.whitelisted) + if v.whitelisted == false then + availableJobs[k] = {label = v.label} + end +end ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb) cb(availableJobs) end) +function IsNearCentre(player) + local Ped = GetPlayerPed(player) + local PedCoords = GetEntityCoords(Ped) + local Zones = Config.Zones + + for i=1, #Config.Zones, 1 do + local distance = #(PedCoords - Config.Zones[i]) + + if distance < Config.DrawDistance then + return true + end + end +end + RegisterServerEvent('esx_joblisting:setJob') AddEventHandler('esx_joblisting:setJob', function(job) local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer then - for k,v in ipairs(availableJobs) do - if v.job == job then - xPlayer.setJob(job, 0) - break - end + if xPlayer and IsNearCentre(source) then + if availableJobs[job] then + xPlayer.setJob(job, 0) end end end)