first commit

This commit is contained in:
2026-03-29 21:41:17 +03:00
commit f1a0200a88
32514 changed files with 2129132 additions and 0 deletions
@@ -0,0 +1,162 @@
local dispatches = {}
local frameworkCallbacks = {}
local securityKey = nil
Core = nil
CreateThread(function()
local coreObject, frameworkName = GetCore()
Config.Framework = frameworkName
Core = coreObject
securityKey = "CodeM" .. math.random(10000, 999999999) .. "Magni" .. math.random(10000, 999999999)
RegisterCallback("codem-dispatch:getKey", function()
return securityKey
end)
RegisterCallback("codem-dispatch:getDispatches", function(source, args)
return dispatches
end)
RegisterCallback("codem-dispatch:server:getPlayerName", function(source, args)
return GetCharacterName(source)
end)
frameworkCallbacks.RegisterCallback("codem-dispatch:getDispatchs", function(source, cb)
cb(dispatches)
end)
end)
function ValidateDispatchType(alertType)
if not Config.DispatchTypes[alertType] then
return "ShootsFire"
end
return alertType
end
RegisterNetEvent("codem-dispatch:server:SendAlert", function(alertData, key)
if key ~= securityKey then return end
alertData.time = os.time() * 1000
alertData.units = {}
alertData.type = ValidateDispatchType(alertData.type)
alertData.id = math.random(100, 999999)
if #dispatches >= Config.MaxDispatch then
table.remove(dispatches, 1)
end
dispatches[#dispatches + 1] = alertData
TriggerClientEvent("codem-dispatch:SendAlert", -1, alertData)
end)
RegisterNetEvent("codem-dispatch:server:takeCall", function(dispatchId, unitData)
local src = source
local updatedDispatch = nil
for _, dispatch in ipairs(dispatches) do
if dispatch.id == dispatchId then
if not isInArray(dispatch.units, unitData.id) then
table.insert(dispatch.units, unitData.id)
updatedDispatch = dispatch
end
break
end
end
if updatedDispatch then
TriggerClientEvent("codem-dispatch:client:updateDispatch", -1, updatedDispatch)
TriggerEvent("mMdt:server:takeCall", src, updatedDispatch)
debugPrint("Dispatch Taken", updatedDispatch)
end
end)
RegisterNetEvent("codem-dispatch:RemoveDispatch", function(dispatchId, unitData)
local src = source
local updatedDispatch = nil
for _, dispatch in ipairs(dispatches) do
if dispatch.id == dispatchId then
for unitIndex, unitId in ipairs(dispatch.units) do
if unitId == unitData.id then
table.remove(dispatch.units, unitIndex)
updatedDispatch = dispatch
break
end
end
break
end
end
if updatedDispatch then
TriggerClientEvent("codem-dispatch:client:updateDispatch", -1, updatedDispatch)
TriggerEvent("mMdt:server:removeCall", src, updatedDispatch)
debugPrint("Dispatch Removed", updatedDispatch)
end
end)
function isInArray(array, value)
for _, item in ipairs(array) do
if item == value then
return true
end
end
return false
end
function ForwardDispatchToEMS(dispatchData)
local players = GetPlayers()
for _, playerId in pairs(players) do
local player = GetPlayer(tonumber(playerId))
local playerJob = GetPlayerJob(player)
if player and playerJob then
if Config.EmsJobs[playerJob] then
notifyEMS(tonumber(playerId), dispatchData)
end
end
end
end
RegisterNetEvent("codem-dispatch:ForwardDispatch", function(dispatchData, key)
if key ~= securityKey then return end
ForwardDispatchToEMS(dispatchData)
end)
function GetIdentifier(source)
local player = GetPlayer(source)
if not player then return end
if Config.Framework == "esx" or Config.Framework == "oldesx" then
return player.identifier
else
return player.PlayerData.citizenid
end
end
function RegisterCallback(eventName, handler)
RegisterNetEvent(eventName, function(callbackId, args)
local src = source
local responseEvent = "codem-dispatch:triggerCallback:" .. callbackId
CreateThread(function()
local result = handler(src, table.unpack(args))
TriggerClientEvent(responseEvent, src, result)
end)
end)
end
frameworkCallbacks.RegisterCallback = function(eventName, handler)
local framework = Config.Framework
if framework == "esx" or framework == "oldesx" then
Core.RegisterServerCallback(eventName, function(source, cb, extra)
handler(source, cb, extra)
end)
else
Core.Functions.CreateCallback(eventName, function(source, cb, extra)
handler(source, cb, extra)
end)
end
end