Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SupportBOTName = "[CIT]Support BOT"
- local SupportBOT = {
- ['ping'] = 'Pong',
- ['i need help'] = 'Hey, please state your issue so I can assist you.',
- ['help me'] = 'Hey, please state your issue so I can assist you.',
- ['how to earn money?'] = 'Hey, please press F1 > press the "help" tab and search for "How to make Money".',
- ['i need money'] = 'Hey, press F1 > press the "help" tab and search for "How to make Money".',
- ['how to get my vehicle back?'] = 'Press F2 > select the vehicle and click "Recover".',
- ['what is vip?'] = 'Press F1 > Click the "Help" tab and search for "what is VIP".',
- }
- --Permission Stuff
- function OpenSupGUI(client, commandName)
- if (isGuestAccount(getPlayerAccount(client))) then
- return false
- end
- triggerClientEvent(client, "OnPlayerOpenGUI", client)
- end
- addCommandHandler("openticket", OpenSupGUI)
- function OpenAIGUI(client, commandName)
- if (isGuestAccount(getPlayerAccount(client)) or not hasObjectPermissionTo(client, "command.staff", false)) then
- return false
- end
- triggerClientEvent(client, "OnPlayerOpenAIGUI", client)
- end
- addCommandHandler("aipanel", OpenAIGUI)
- --Ticket Stuff
- local tickets = {} --Server side storage
- local messages = {} --Server side storage
- --Returns list of all tickets
- function GetTickets()
- triggerClientEvent(client, "loadTickets", source, tickets)
- end
- addEvent("getTickets", true)
- addEventHandler("getTickets", resourceRoot, GetTickets)
- --Returns messages of one ticket
- function GetTicket(ticketId)
- if (not ticketId or not messages[ticketId]) then
- return false
- end
- triggerClientEvent(client, "loadTicket", source, messages[ticketId])
- end
- addEvent("getTicket", true)
- addEventHandler("getTicket", resourceRoot, GetTicket)
- --Creates a new ticket, stores it in tickets list and it's messages
- function AddTicket(ticket)
- if (not ticket) then
- return false
- end
- local ticketId = ticket[1]
- local ticketinfo = {ticket[1], ticket[2], ticket[3], getTickCount(), 0}
- tickets[ticketId] = ticketinfo
- messages[ticketId] = ticket[4]
- --Support BOT
- CallSupportBot(ticketId, ticket[4][1][3])
- GetTickets()
- for i, player in ipairs(getElementsByType("player")) do
- if (getTeamName(getPlayerTeam(player)) == "Staff") then
- outputChatBox("#B266FF(Support) #FFFFFFA new help ticket is created. Press J to view the ticket.", player, 255, 255, 255, true)
- end
- end
- end
- addEvent("addTicket", true)
- addEventHandler("addTicket", resourceRoot, AddTicket)
- --Delete player ticket
- function DelTicket(ticket)
- if (not ticket or not tickets[ticket[1]] or not hasObjectPermissionTo(client, "command.staff", false)) then
- return false
- end
- tickets[ticket[1]] = nil
- messages[ticket[1]] = nil
- GetTickets()
- end
- addEvent("delTicket", true)
- addEventHandler("delTicket", resourceRoot, DelTicket)
- --Save a new message inside a ticket
- function SendMessage(message)
- if (not message) then
- return false
- end
- local plrName = getPlayerName(client)
- local ticketId = message[1]
- if (not tickets[ticketId] or not messages[ticketId] or not hasObjectPermissionTo(client, "command.staff", false) or plrName ~= tickets[ticketId][3]) then
- return false
- end
- table.insert(messages[ticketId], message[2])
- --Support BOT
- CallSupportBot(ticketId, message[2][3])
- GetTicket(ticketId)
- end
- addEvent("sendMessage", true)
- addEventHandler("sendMessage", resourceRoot, SendMessage)
- --AI Function
- function CallSupportBot(ticketId, message)
- if (not message or not tickets[ticketId] or not messages[ticketId]) then
- return false
- end
- --Support BOT
- local text = string.lower(message)
- if (SupportBOT[text]) then
- local aiMessage = {getTickCount(), SupportBOTName, SupportBOT[text]}
- table.insert(messages[ticketId], aiMessage)
- outputChatBox("#B266FF(Support) #FFFFFF"..SupportBOTName..": "..SupportBOT[text], client, 255, 255, 255, true)
- end
- end
- function SolveTicket(ticketId)
- if (getElementType(client) ~= "player") then
- return false
- end
- local plrName = getPlayerName(client)
- if (not ticketId or not tickets[ticketId] or not hasObjectPermissionTo(client, "command.staff", false) or plrName ~= tickets[ticketId][3]) then
- return false
- end
- tickets[ticketId][5] = 1 --1 means the ticket is solved, esle not solved.
- GetTickets()
- end
- addEvent("solveTicket", true)
- addEventHandler("solveTicket", resourceRoot, SolveTicket)
- --AI Database Input
- function AddSupQ(text, msg)
- if (SupportBOT[text]) then
- outputChatBox("#FF0000[CIT]Support: #FFFFFFI already have that in my database.", client, 255, 255, 255, true)
- return false
- end
- SupportBOT[text] = msg
- end
- addEvent("AIconfig", true)
- addEventHandler("AIconfig", resourceRoot, AddSupQ)
- --Database Table
- function SaveAIDatabase(thePlayer, commandName, backup)
- if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
- return false
- end
- local createfile = fileCreate('backup.json')
- if (not fileExists('backup.json')) then
- return false
- end
- backup = fileOpen('backup.json')
- fileWrite(backup, toJSON(SupportBOT))
- fileClose(backup)
- outputChatBox("AI Table Added To Database.", thePlayer, 50, 255, 50, true)
- end
- addCommandHandler("SaveDB", SaveAIDatabase)
- function LoadAIDatabase(thePlayer, commandName, backup)
- if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
- return false
- end
- if (not fileExists('backup.json')) then
- outputChatBox("Database Does not exists.", thePlayer, 255, 50, 50, true)
- return false
- end
- local file = fileOpen('backup.json')
- local size = fileGetSize(file)
- local buffer = fileRead(file, size)
- SupportBOT = fromJSON(buffer)
- fileClose(file)
- outputChatBox("AI Database Successfully Loaded.", thePlayer, 50, 255, 50, true)
- end
- addCommandHandler("LoadDB", LoadAIDatabase)
- function DeleteAIDatabase(thePlayer, commandName, backup)
- if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
- return false
- end
- if (fileExists('backup.json')) then
- backup = fileOpen('backup.json')
- fileClose(backup)
- fileDelete('backup.json')
- end
- if (not fileExists('backup.json')) then
- outputChatBox("AI Database Successfully Deleted.", thePlayer, 50, 255, 50, true)
- else
- outputChatBox("Ops, something went wrong.. Please restart the resource then use this command again.", thePlayer, 255, 50, 50, true)
- end
- end
- addCommandHandler("DeleteDB", DeleteAIDatabase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement