Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local data = {
- messages = {},
- admins = {Nuncaplagiei = true}, -- Adicione seu nick dentro da tabela, formato: SeuNick = true
- players = {}
- }
- function chatDisplay(name, update)
- local chatmessages = ''
- if (#data.messages > 0) then
- table.sort(data.messages, function(a, b) return a[2] > b[2] end)
- for i = 1, #data.messages do
- chatmessages = chatmessages .. data.messages[i][1] .. '\n'
- end
- end
- if (update) then
- if (data.players[name].openchat) then
- ui.updateTextArea(0, '\n\n\n' .. chatmessages, name)
- ui.updateTextArea(1, "<p align='center'><font size=\"23\"><B><R>Chat", name)
- ui.updateTextArea(2, "<a href='event:close_chat'><R><B><font size='15'>X", name)
- else
- data.players[name].unreadmessages = data.players[name].unreadmessages + 1
- if (data.players[name].unreadmessages > 0) then
- ui.updateTextArea(4, "<p align='center'><B><a href='event:open_chat'>Chat <b><j>(" .. data.players[name].unreadmessages .. ")", name)
- end
- end
- else
- ui.addTextArea(0, '\n\n\n' .. chatmessages, name, 172, 48, 454, 252, 0x324650, 0x324650, 1, true)
- ui.addTextArea(1, "<p align='center'><font size=\"23\"><B><R>Chat", name, 173, 48, 454, 35, 0x142b36, 0x142b36, 1, true)
- ui.addTextArea(2, "<a href='event:close_chat'><R><B><font size='15'>X", name, 610, 53, 14, 23, 0x324650, 0x000000, 0, true)
- ui.addPopup(0, 2, "", name, 171, 309, 456, true)
- end
- end
- function eventNewPlayer(name)
- chatDisplay(name, false)
- data.players[name] = {
- lastmessage = '',
- openchat = true,
- unreadmessages = 0
- }
- end
- table.foreach(tfm.get.room.playerList, eventNewPlayer)
- function eventPopupAnswer(id, name, answer)
- if (id == 0) then
- if (answer ~= '') then
- answer = answer:gsub('<', '<')
- answer = answer:gsub('%s+', ' ')
- answer = answer:gsub('^%s', '')
- if (answer ~= '' and data.players[name].lastmessage ~= answer and answer:sub(1, 1) ~= '/') then
- local msg = "<V>["..name.."] <N>"..answer:gsub('<.->', '')
- local i = (#data.messages + 1)
- data.messages[i] = {msg, i}
- data.players[name].lastmessage = answer
- for k in next, tfm.get.room.playerList do
- chatDisplay(k, true)
- end
- ui.addPopup(0, 2, "", name, 171, 309, 456, true)
- else
- ui.addPopup(0, 2, "", name, 171, 309, 456, true)
- end
- else
- ui.addPopup(0, 2, "", name, 171, 309, 456, true)
- end
- if (answer:sub(1, 1) == '/' and data.admins[name]) then
- local command = answer:sub(2)
- if (command == 'clear') then
- data.messages = {}
- for k in next, tfm.get.room.playerList do
- chatDisplay(k, true)
- end
- end
- end
- end
- end
- function eventTextAreaCallback(id, name, link)
- if (link == 'close_chat') then
- for id = 0, 2 do
- ui.removeTextArea(id, name)
- end
- data.players[name].openchat = false
- ui.addTextArea(4, "<p align='center'><B><a href='event:open_chat'>Chat", name, 696, 378, 100, 21, 0x324650, 0x000000, 1, true)
- ui.addPopup(0, 0, "", name, 5000, 5000)
- elseif (link == 'open_chat') then
- data.players[name].openchat = true
- data.players[name].unreadmessages = 0
- ui.removeTextArea(4, name)
- chatDisplay(name, false)
- end
- end
Add Comment
Please, Sign In to add comment