Skip to content

Commit

Permalink
creted a Function to check if the player is in table.
Browse files Browse the repository at this point in the history
  • Loading branch information
JericoFX authored Jul 14, 2022
1 parent 49f8827 commit b2c7ad9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ local function IsPolice(job)
return false
end

local function GetActiveData(cid)
local player = type(cid) == "string" and cid or tostring(cid)
if player then
return activeUnits[player]
end
return false
end

AddEventHandler("onResourceStart", function(resourceName)
if (resourceName == 'ps-mdt') then
activeUnits = {}
Expand All @@ -40,7 +48,7 @@ RegisterNetEvent("ps-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
if GetActiveData(player.PlayerData.citizenid) then
activeUnits[player.PlayerData.citizenid] = nil
end
end)
Expand All @@ -50,15 +58,15 @@ AddEventHandler("playerDropped", function(reason)
local src = source
local player = QBCore.Functions.GetPlayer(src)
if player ~= nil then
if activeUnits[player.PlayerData.citizenid] ~= nil then
if GetActiveData(player.PlayerData.citizenid) 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
if GetActiveData(v.citizenid) nil then
activeUnits[v.citizenid] = nil
end
end
Expand All @@ -70,7 +78,7 @@ RegisterNetEvent("ps-mdt:server:ToggleDuty", function()
local player = QBCore.Functions.GetPlayer(src)
if not player.PlayerData.job.onduty then
--// Remove from MDT
if activeUnits[player.PlayerData.citizenid] ~= nil then
if GetActiveData(player.PlayerData.citizenid) then
activeUnits[player.PlayerData.citizenid] = nil
end
end
Expand Down

0 comments on commit b2c7ad9

Please sign in to comment.