forked from Simnation/Main
114 lines
4.4 KiB
Lua
114 lines
4.4 KiB
Lua
![]() |
local QBCore = exports['qb-core']:GetCoreObject()
|
||
|
local activeTickets = {}
|
||
|
|
||
|
function CreateTicket(playerId, reason)
|
||
|
local uniqueId = generateRandomNumber(16)
|
||
|
local playerPed = GetPlayerPed(playerId)
|
||
|
local playerCoords = playerPed and GetEntityCoords(playerPed) or vector3(0, 0, 0)
|
||
|
local playerName = GetPlayerName(playerId) or 'Unknown'
|
||
|
local time = os.date('%H:%M')
|
||
|
|
||
|
local ticketContent = {
|
||
|
uniqueId = uniqueId,
|
||
|
claimedBy = Translation['ticket_open'],
|
||
|
reason = reason,
|
||
|
time = time,
|
||
|
playerId = playerId,
|
||
|
playerName = playerName,
|
||
|
playerCoords = playerCoords,
|
||
|
}
|
||
|
|
||
|
activeTickets[uniqueId] = ticketContent
|
||
|
|
||
|
local players = QBCore.Functions.GetPlayers()
|
||
|
for _, id in pairs(players) do
|
||
|
local Player = QBCore.Functions.GetPlayer(tonumber(id))
|
||
|
if Player and (QBCore.Functions.HasPermission(tonumber(id), 'admin') or QBCore.Functions.HasPermission(tonumber(id), 'god')) then
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:syncRequest', tonumber(id), activeTickets, uniqueId)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
QBCore.Functions.CreateCallback('rlo_ticketpanel:callback:getTargetCoords', function(source, cb, playerId)
|
||
|
local targetPlayer = QBCore.Functions.GetPlayer(tonumber(playerId))
|
||
|
if targetPlayer then
|
||
|
local targetPed = GetPlayerPed(tonumber(playerId))
|
||
|
local playerCoords = GetEntityCoords(targetPed)
|
||
|
cb(playerCoords)
|
||
|
else
|
||
|
cb(vector3(0, 0, 0))
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
QBCore.Functions.CreateCallback('rlo_ticketpanel:callback:isAdmin', function(source, cb)
|
||
|
if QBCore.Functions.HasPermission(source, 'admin') or QBCore.Functions.HasPermission(source, 'god') then
|
||
|
print("^2Player " .. GetPlayerName(source) .. " is recognized as admin^7")
|
||
|
cb(true)
|
||
|
else
|
||
|
print("^1Player " .. GetPlayerName(source) .. " is NOT recognized as admin^7")
|
||
|
cb(false)
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
RegisterCommand(Config.TicketCommand or 'support', function(source, args)
|
||
|
local Player = QBCore.Functions.GetPlayer(source)
|
||
|
if not Player then return end
|
||
|
|
||
|
local message = table.concat(args, ' '):match("^%s*(.-)%s*$") or ""
|
||
|
|
||
|
if Config.RequiresReason and message == "" then
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:showNotification', source, Translation['requires_reason'])
|
||
|
return
|
||
|
end
|
||
|
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:showNotification', source, Translation['ticket_created'])
|
||
|
CreateTicket(source, message ~= '' and message or Translation['no_message_provided'])
|
||
|
SendWebhook(source, message)
|
||
|
end, false)
|
||
|
|
||
|
RegisterNetEvent('rlo_ticketpanel:server:syncDelete', function(uniqueId)
|
||
|
for id, ticketContent in pairs(activeTickets) do
|
||
|
if ticketContent.uniqueId == uniqueId then
|
||
|
activeTickets[id] = nil
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local players = QBCore.Functions.GetPlayers()
|
||
|
for _, id in pairs(players) do
|
||
|
local Player = QBCore.Functions.GetPlayer(tonumber(id))
|
||
|
if Player and (QBCore.Functions.HasPermission(tonumber(id), 'admin') or QBCore.Functions.HasPermission(tonumber(id), 'god')) then
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:syncDelete', tonumber(id), uniqueId)
|
||
|
end
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
RegisterNetEvent('rlo_ticketpanel:server:syncState', function(ticketContent)
|
||
|
local adminPlayer = QBCore.Functions.GetPlayer(source)
|
||
|
local adminName = adminPlayer.PlayerData.charinfo.firstname .. ' ' .. adminPlayer.PlayerData.charinfo.lastname
|
||
|
local packedTicket = nil
|
||
|
|
||
|
for id, requestContent in pairs(activeTickets) do
|
||
|
if requestContent.uniqueId == ticketContent.uniqueId then
|
||
|
activeTickets[id].claimedBy = adminName
|
||
|
packedTicket = activeTickets[id]
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local players = QBCore.Functions.GetPlayers()
|
||
|
for _, id in pairs(players) do
|
||
|
local Player = QBCore.Functions.GetPlayer(tonumber(id))
|
||
|
if Player and (QBCore.Functions.HasPermission(tonumber(id), 'admin') or QBCore.Functions.HasPermission(tonumber(id), 'god')) then
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:syncState', tonumber(id), packedTicket)
|
||
|
end
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
-- QBCore player loaded event
|
||
|
RegisterNetEvent('QBCore:Server:PlayerLoaded', function(Player)
|
||
|
local src = Player.PlayerData.source
|
||
|
|
||
|
if QBCore.Functions.HasPermission(src, 'admin') or QBCore.Functions.HasPermission(src, 'god') then
|
||
|
TriggerClientEvent('rlo_ticketpanel:client:syncOnJoin', src, activeTickets)
|
||
|
end
|
||
|
end)
|