Skip to content

Commit

Permalink
Merge pull request #37 from gimicze/qbcore
Browse files Browse the repository at this point in the history
QB Core implementation
  • Loading branch information
gimicze authored Apr 16, 2024
2 parents 86c7ed7 + 8b39226 commit e7f25ee
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 50 deletions.
9 changes: 6 additions & 3 deletions config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--================================--
-- FIRE SCRIPT v1.8.0 --
-- FIRE SCRIPT v2.0.0 --
-- by GIMI (+ foregz, Albo1125) --
-- License: GNU GPL 3.0 --
--================================--
Expand All @@ -15,7 +15,7 @@ Config.Fire = {
interval = 1800000, -- Random fire spawn interval (set to nil or false if you don't want to spawn random fires) in ms
chance = 50, -- Fire spawn chance (out of 100 chances, how many lead to spawning a fire?); Set to values between 1-100
players = 3, -- Sets the minimum number of players subscribed to dispatch for the spawner to spawn fires.
firefighterJobs = { -- If using ESX (Config.Dispatch.enableESX), you can specify which players will count as firefighters in Config.Fire.spawner.players above; If not using ESX you can set this to nil
firefighterJobs = { -- If using a framework (Config.Dispatch.enableFramework), you can specify which players will count as firefighters in Config.Fire.spawner.players above; If set to nil, all jobs specified in Config.Dispatch.jobs will count as firefighters
["fd"] = true -- Always set the job name in the key, value has to be true
}
}
Expand All @@ -28,7 +28,10 @@ Config.Dispatch = {
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,
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
enableFramework = 1, -- Set to nil if you don't want to use any framework implementation. Set to 1 for ESX, 2 for QB-Core.
jobs = { -- 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
"fd"
},
toneSources = { -- Here you can set coordinates of sound sources for the fire tones to go off at; Set to nil if you wish to disable this function.
-- Fire Station 7
vector3(1207.11, -1463.37, 36),
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ games {
}

author 'GIMI, foregz, Albo1125'
version '1.8.0'
version '2.0.0'
description 'Fire Script'

client_scripts {
Expand Down
116 changes: 72 additions & 44 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--================================--
-- FIRE SCRIPT v1.8.0 --
-- FIRE SCRIPT v2.0.0 --
-- by GIMI (+ foregz, Albo1125) --
-- License: GNU GPL 3.0 --
--================================--
Expand Down Expand Up @@ -247,7 +247,7 @@ RegisterCommand(
sendMessage(source, "Insufficient permissions.")
return
end
local _source = source

local scenarioID = tonumber(args[1])
local triggerDispatch = args[2] == "true"

Expand Down Expand Up @@ -304,7 +304,6 @@ RegisterCommand(
RegisterCommand(
'firewl',
function(source, args, rawCommand)
local _source = source
local action = args[1]
local serverId = tonumber(args[2])

Expand Down Expand Up @@ -353,7 +352,6 @@ RegisterCommand(
RegisterCommand(
'firedispatch',
function(source, args, rawCommand)
local _source = source
local action = args[1]
local serverId = tonumber(args[2])

Expand Down Expand Up @@ -579,44 +577,74 @@ AddEventHandler(
-- AUTO-SUBSCRIBE --
--================================--

if Config.Dispatch.enabled and Config.Dispatch.enableESX then
ESX = exports["es_extended"]:getSharedObject()

local allowedJobs = {}
local firefighterJobs = Config.Fire.spawner.firefighterJobs or {}

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
firefighterJobs[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:subscribe(source, firefighterJobs[xPlayer.job.name])
else
Dispatch:unsubscribe(source)
end
end
)

RegisterNetEvent("esx:playerLoaded")
AddEventHandler(
"esx:playerLoaded",
function(source, xPlayer)
if allowedJobs[xPlayer.job.name] then
Dispatch:subscribe(source, firefighterJobs[xPlayer.job.name])
else
Dispatch:unsubscribe(source)
end
end
)
if Config.Dispatch.enabled then
local allowedJobs = {}
local firefighterJobs = {}

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

firefighterJobs = Config.Fire.spawner.firefighterJobs or allowedJobs
end

if Config.Dispatch.enableFramework == 1 then
ESX = exports["es_extended"]:getSharedObject()

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

if allowedJobs[xPlayer.job.name] then
Dispatch:subscribe(source, firefighterJobs[xPlayer.job.name])
else
Dispatch:unsubscribe(source)
end
end
)

AddEventHandler(
"esx:playerLoaded",
function(source, xPlayer)
if allowedJobs[xPlayer.job.name] then
Dispatch:subscribe(source, firefighterJobs[xPlayer.job.name])
else
Dispatch:unsubscribe(source)
end
end
)
elseif Config.Dispatch.enableFramework == 2 then
AddEventHandler(
'QBCore:Server:PlayerLoaded',
function(Player)
if Player.PlayerData.job.onduty and allowedJobs[Player.PlayerData.job.name] then
Dispatch:subscribe(Player.PlayerData.source, firefighterJobs[Player.PlayerData.job.name])
end
end
)

AddEventHandler(
'QBCore:Server:OnJobUpdate',
function(source, job)
if allowedJobs[job.name] and job.onduty then
Dispatch:subscribe(source, firefighterJobs[job.name])
else
Dispatch:unsubscribe(source)
end
end
)

AddEventHandler(
'QBCore:Server:OnPlayerUnload',
function(source)
Dispatch:unsubscribe(source)
end
)
end
end
4 changes: 2 additions & 2 deletions server/whitelist.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--================================--
-- FIRE SCRIPT v1.6.10 --
-- FIRE SCRIPT v2.0.0 --
-- by GIMI (+ foregz, Albo1125) --
-- License: GNU GPL 3.0 --
--================================--
Expand Down Expand Up @@ -28,7 +28,7 @@ end

function Whitelist:isWhitelisted(serverId, ace)
ace = tostring(ace)
return (serverId > 0 and (self.players[serverId] == true or (ace and IsPlayerAceAllowed(serverId, ace))))
return (serverId < 1 or (self.players[serverId] == true or (ace and IsPlayerAceAllowed(serverId, ace))))
end

function Whitelist:addPlayer(serverId, steamId)
Expand Down

0 comments on commit e7f25ee

Please sign in to comment.