mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-30 17:58:54 +00:00
Refactor: JobListing - Optimisations and security patches
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user