Skip to content

Commit

Permalink
Added optional ESX integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gimicze committed Feb 7, 2021
1 parent 2beb308 commit a32c5bc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Config.Dispatch = {
storeLast = 5, -- The client will store the last five dispatch coordinates for use with /remindme <dispatchNumber>
clearGpsRadius = 20.0, -- If you don't want to automatically clear the route upon arrival, leave this to false
removeBlipTimeout = 400000, -- The amount of time in ms after which the dispatch call blip will be automatically removed
playSound = true
playSound = true,
enableESX = "fd" -- Set to a ESX job / jobs you want to be automatically subscribed to dispatch; Set to nil or false if you don't want to use this
}
48 changes: 47 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,50 @@ AddEventHandler(

Whitelist:check(source)
end
)
)

--================================--
-- AUTO-SUBSCRIBE --
--================================--

if Config.Dispatch.enabled and Config.Dispatch.enableESX then
ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

local allowedJobs = {}

if type(Config.Dispatch.enableESX) == "table" then
for k, v in pairs(Config.Dispatch.enableESX) do
allowedJobs[v] = true
end
else
allowedJobs[Config.Dispatch.enableESX] = true
end

RegisterNetEvent("esx:setJob")
AddEventHandler(
"esx:setJob",
function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if allowedJobs[xPlayer.job.name] then
Dispatch:addPlayer(source)
else
Dispatch:removePlayer(source)
end
end
)

RegisterNetEvent("esx:playerLoaded")
AddEventHandler(
"esx:playerLoaded",
function(source, xPlayer)
if allowedJobs[xPlayer.job.name] then
Dispatch:addPlayer(source)
else
Dispatch:removePlayer(source)
end
end
)
end

0 comments on commit a32c5bc

Please sign in to comment.