From b52e9a48d23e49c305ccac3095d087a1473b945f Mon Sep 17 00:00:00 2001 From: renaiku Date: Wed, 9 Aug 2017 00:42:51 +0200 Subject: [PATCH] Add files --- README.md | 3 +- __resource.lua | 9 +++ client/esx_joblisting_cl.lua | 115 +++++++++++++++++++++++++++++++++++ config.lua | 9 +++ server/esx_joblisting_sv.lua | 26 ++++++++ 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 __resource.lua create mode 100644 client/esx_joblisting_cl.lua create mode 100644 config.lua create mode 100644 server/esx_joblisting_sv.lua diff --git a/README.md b/README.md index 69c5506c..64d5b689 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# fxserver-esx_joblisting \ No newline at end of file +# fxserver-esx_joblisting +FR - Pôle Emploi \ No newline at end of file diff --git a/__resource.lua b/__resource.lua new file mode 100644 index 00000000..7993f10f --- /dev/null +++ b/__resource.lua @@ -0,0 +1,9 @@ +server_scripts { + '@mysql-async/lib/MySQL.lua', + 'server/esx_joblisting_sv.lua' +} + +client_scripts { + 'config.lua', + 'client/esx_joblisting_cl.lua' +} \ No newline at end of file diff --git a/client/esx_joblisting_cl.lua b/client/esx_joblisting_cl.lua new file mode 100644 index 00000000..e782aa7e --- /dev/null +++ b/client/esx_joblisting_cl.lua @@ -0,0 +1,115 @@ +local Keys = { + ["ESC"] = 322, ["BACKSPACE"] = 177, ["E"] = 38, ["ENTER"] = 18, ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173 +} + +local menuIsShowed = false +local hasAlreadyEnteredMarker = false +local lastZone = nil +local isInJoblistingMarker = false + +ESX = nil + +Citizen.CreateThread(function() + while ESX == nil do + TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + Citizen.Wait(0) + end +end) + +function ShowJobListingMenu(data) + ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(data) + local elements = {} + for i = 1, #data, 1 do + table.insert( + elements, + {label = data[i].label, value = data[i].value} + ) + end + + ESX.UI.Menu.CloseAll() + + ESX.UI.Menu.Open( + 'default', GetCurrentResourceName(), 'joblisting', + { + title = 'POLE EMPLOI', + elements = elements + }, + function(data, menu) + TriggerServerEvent('esx_joblisting:setJob', data.current.value) + ESX.ShowNotification('Vous avez un nouveau job !') + menu.close() + end, + function(data, menu) + menu.close() + end + ) + + end) +end + +AddEventHandler('esx_joblisting:hasExitedMarker', function(zone) + ESX.UI.Menu.CloseAll() +end) + +-- Display markers +Citizen.CreateThread(function() + while true do + Wait(0) + local coords = GetEntityCoords(GetPlayerPed(-1)) + 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 + 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) + +-- Activate menu when player is inside marker +Citizen.CreateThread(function() + while true do + Wait(0) + local coords = GetEntityCoords(GetPlayerPed(-1)) + isInJoblistingMarker = false + local currentZone = nil + 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 + isInJoblistingMarker = true + SetTextComponentFormat('STRING') + AddTextComponentString('Appuyez sur ~INPUT_PICKUP~ pour \naccéder au ~b~Pôle Emploi~s~.') + DisplayHelpTextFromStringLabel(0, 0, 1, -1) + end + end + if isInJoblistingMarker and not hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = true + end + if not isInJoblistingMarker and hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = false + TriggerEvent('esx_joblisting:hasExitedMarker') + end + end +end) + +-- Create blips +Citizen.CreateThread(function() + for i=1, #Config.Zones, 1 do + local blip = AddBlipForCoord(Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z) + SetBlipSprite (blip, 407) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 1.2) + SetBlipColour (blip, 27) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Pôle-Emploi") + EndTextCommandSetBlipName(blip) + end +end) + +-- Menu Controls +Citizen.CreateThread(function() + while true do + Wait(0) + if IsControlJustReleased(0, Keys['E']) and isInJoblistingMarker and not menuIsShowed then + ShowJobListingMenu() + end + end +end) \ No newline at end of file diff --git a/config.lua b/config.lua new file mode 100644 index 00000000..876c8df9 --- /dev/null +++ b/config.lua @@ -0,0 +1,9 @@ +Config = {} +Config.DrawDistance = 100.0 +Config.ZoneSize = {x = 3.0, y = 3.0, z = 2.0} +Config.MarkerColor = {r = 100, g = 100, b = 204} +Config.MarkerType = 1 + +Config.Zones = { + {x = -265.036, y = -963.630, z = 30.223} +} diff --git a/server/esx_joblisting_sv.lua b/server/esx_joblisting_sv.lua new file mode 100644 index 00000000..79533e40 --- /dev/null +++ b/server/esx_joblisting_sv.lua @@ -0,0 +1,26 @@ +ESX = nil +TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + +ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb) + MySQL.Async.fetchAll( + 'SELECT * FROM jobs', + {}, + function(result) + local data = {} + for i=1, #result, 1 do + table.insert(data, { + value = result[i].name, + label = result[i].label + }) + end + cb(data) + end + ) +end) + +RegisterServerEvent('esx_joblisting:setJob') +AddEventHandler('esx_joblisting:setJob', function(job) + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + xPlayer.setJob(job, 0) +end) \ No newline at end of file