Skip to content

Commit

Permalink
[qb-mdt] - Multiple Fixes/Updates
Browse files Browse the repository at this point in the history
- Remove Players from MDT when going offline, logging out or toggling duty.
- Add firefighter support
  • Loading branch information
trapw0w authored May 4, 2022
1 parent 385ec45 commit ada1bca
Showing 1 changed file with 52 additions and 11 deletions.
63 changes: 52 additions & 11 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,47 @@ AddEventHandler("onResourceStart", function(resourceName)
end
end)

RegisterNetEvent("qb-mdt:server:OnPlayerUnload", function()
--// Delete player from the MDT on logout
local src = source
local player = QBCore.Functions.GetPlayer(src)
if activeUnits[player.PlayerData.citizenid] ~= nil then
activeUnits[player.PlayerData.citizenid] = nil
end
end)

RegisterServerEvent("playerDropped")
AddEventHandler("playerDropped", function(reason)
--// Delete player from the MDT on logout
local src = source
local player = QBCore.Functions.GetPlayer(src)
if player ~= nil then
if activeUnits[player.PlayerData.citizenid] ~= nil then
activeUnits[player.PlayerData.citizenid] = nil
end
else
local license = QBCore.Functions.GetIdentifier(src, "license")
local citizenids = GetCitizenID(license)

for _, v in pairs(citizenids) do
if activeUnits[v.citizenid] ~= nil then
activeUnits[v.citizenid] = nil
end
end
end
end)

RegisterNetEvent("qb-mdt:server:ToggleDuty", function()
local src = source
local player = QBCore.Functions.GetPlayer(src)
if not player.PlayerData.job.onduty then
--// Remove from MDT
if activeUnits[player.PlayerData.citizenid] ~= nil then
activeUnits[player.PlayerData.citizenid] = nil
end
end
end)

RegisterNetEvent('mdt:server:openMDT', function()
local src = source
local PlayerData = GetPlayerData(src)
Expand All @@ -50,7 +91,7 @@ RegisterNetEvent('mdt:server:openMDT', function()
local calls = exports['qb-dispatch']:GetDispatchCalls()

--TriggerClientEvent('mdt:client:dashboardbulletin', src, bulletin)
TriggerClientEvent('mdt:client:open', src, bulletin, activeUnits, calls)
TriggerClientEvent('mdt:client:open', src, bulletin, activeUnits, calls, PlayerData.citizenid)
--TriggerClientEvent('mdt:client:GetActiveUnits', src, activeUnits)
end)

Expand Down Expand Up @@ -510,7 +551,7 @@ RegisterNetEvent('mdt:server:getAllReports', function()
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' or JobType == 'firefighter' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE jobtype = :jobtype ORDER BY `id` DESC LIMIT 30", {
jobtype = JobType
Expand All @@ -526,7 +567,7 @@ RegisterNetEvent('mdt:server:getReportData', function(sentId)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' or JobType == 'firefighter' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE `id` = :id AND `jobtype` = :jobtype LIMIT 1", {
id = sentId,
Expand All @@ -549,7 +590,7 @@ RegisterNetEvent('mdt:server:searchReports', function(sentSearch)
local Player = QBCore.Functions.GetPlayer(src)
if Player then
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'doj' or JobType == 'ambulance' or JobType == 'firefighter' then
if JobType == 'doj' then JobType = 'police' end
local matches = MySQL.query.await("SELECT * FROM `mdt_reports` WHERE `id` LIKE :query OR LOWER(`author`) LIKE :query OR LOWER(`title`) LIKE :query OR LOWER(`type`) LIKE :query OR LOWER(`details`) LIKE :query OR LOWER(`tags`) LIKE :query AND `jobtype` = :jobtype ORDER BY `id` DESC LIMIT 50", {
query = string.lower('%'..sentSearch..'%'), -- % wildcard, needed to search for all alike results
Expand Down Expand Up @@ -969,7 +1010,7 @@ RegisterNetEvent('mdt:server:setWaypoint', function(callid)
local src = source
local Player = QBCore.Functions.GetPlayer(source)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
local calls = exports['qb-dispatch']:GetDispatchCalls()
TriggerClientEvent('mdt:client:setWaypoint', src, calls[callid])
Expand All @@ -987,7 +1028,7 @@ RegisterNetEvent('mdt:server:callDetach', function(callid)
callsign = Player.PlayerData.metadata.callsign
}
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
TriggerEvent('dispatch:removeUnit', callid, playerdata, function(newNum)
TriggerClientEvent('mdt:client:callDetach', -1, callid, newNum)
Expand All @@ -1006,7 +1047,7 @@ RegisterNetEvent('mdt:server:callAttach', function(callid)
callsign = Player.PlayerData.metadata.callsign
}
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
TriggerEvent('dispatch:addUnit', callid, playerdata, function(newNum)
TriggerClientEvent('mdt:client:callAttach', -1, callid, newNum)
Expand All @@ -1020,7 +1061,7 @@ RegisterNetEvent('mdt:server:attachedUnits', function(callid)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
local calls = exports['qb-dispatch']:GetDispatchCalls()
TriggerClientEvent('mdt:client:attachedUnits', src, calls[callid]['units'], callid)
Expand All @@ -1039,7 +1080,7 @@ RegisterNetEvent('mdt:server:callDispatchDetach', function(callid, cid)
}
local callid = tonumber(callid)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
TriggerEvent('dispatch:removeUnit', callid, playerdata, function(newNum)
TriggerClientEvent('mdt:client:callDetach', -1, callid, newNum)
Expand All @@ -1053,7 +1094,7 @@ RegisterNetEvent('mdt:server:setDispatchWaypoint', function(callid, cid)
local Player = QBCore.Functions.GetPlayer(src)
local callid = tonumber(callid)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
local calls = exports['qb-dispatch']:GetDispatchCalls()
TriggerClientEvent('mdt:client:setWaypoint', src, calls[callid])
Expand All @@ -1073,7 +1114,7 @@ RegisterNetEvent('mdt:server:callDragAttach', function(callid, cid)
}
local callid = tonumber(callid)
local JobType = GetJobType(Player.PlayerData.job.name)
if JobType == 'police' or JobType == 'ambulance' then
if JobType == 'police' or JobType == 'ambulance' or JobType == 'firefighter' then
if callid then
TriggerEvent('dispatch:addUnit', callid, playerdata, function(newNum)
TriggerClientEvent('mdt:client:callAttach', -1, callid, newNum)
Expand Down

0 comments on commit ada1bca

Please sign in to comment.