Guest User

[Script] Chat

a guest
Oct 16th, 2017
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. local data = {
  2.     messages = {},
  3.     admins = {Nuncaplagiei = true}, -- Adicione seu nick dentro da tabela, formato: SeuNick = true
  4.     players = {}
  5. }
  6.  
  7. function chatDisplay(name, update)
  8.     local chatmessages = ''
  9.     if (#data.messages > 0) then
  10.         table.sort(data.messages, function(a, b) return a[2] > b[2] end)
  11.        
  12.         for i = 1, #data.messages do
  13.             chatmessages = chatmessages .. data.messages[i][1] .. '\n'
  14.         end
  15.     end
  16.    
  17.     if (update) then
  18.         if (data.players[name].openchat) then
  19.             ui.updateTextArea(0, '\n\n\n' .. chatmessages, name)
  20.             ui.updateTextArea(1, "<p align='center'><font size=\"23\"><B><R>Chat", name)
  21.             ui.updateTextArea(2, "<a href='event:close_chat'><R><B><font size='15'>X", name)
  22.         else
  23.             data.players[name].unreadmessages = data.players[name].unreadmessages + 1
  24.  
  25.             if (data.players[name].unreadmessages > 0) then
  26.                 ui.updateTextArea(4, "<p align='center'><B><a href='event:open_chat'>Chat <b><j>(" .. data.players[name].unreadmessages .. ")", name)
  27.             end
  28.         end
  29.     else
  30.         ui.addTextArea(0, '\n\n\n' .. chatmessages, name, 172, 48, 454, 252, 0x324650, 0x324650, 1, true)
  31.         ui.addTextArea(1, "<p align='center'><font size=\"23\"><B><R>Chat", name, 173, 48, 454, 35, 0x142b36, 0x142b36, 1, true)
  32.         ui.addTextArea(2, "<a href='event:close_chat'><R><B><font size='15'>X", name, 610, 53, 14, 23, 0x324650, 0x000000, 0, true)
  33.         ui.addPopup(0, 2, "", name, 171, 309, 456, true)
  34.     end
  35. end
  36.  
  37. function eventNewPlayer(name)
  38.     chatDisplay(name, false)
  39.    
  40.     data.players[name] = {
  41.         lastmessage = '',
  42.         openchat = true,
  43.         unreadmessages = 0
  44.     }
  45. end
  46. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  47.  
  48. function eventPopupAnswer(id, name, answer)
  49.     if (id == 0) then
  50.         if (answer ~= '') then
  51.             answer = answer:gsub('<', '&lt;')
  52.             answer = answer:gsub('%s+', ' ')
  53.             answer = answer:gsub('^%s', '')
  54.             if (answer ~= '' and data.players[name].lastmessage ~= answer and answer:sub(1, 1) ~= '/') then
  55.                 local msg = "<V>["..name.."] <N>"..answer:gsub('<.->', '')
  56.                 local i = (#data.messages + 1)
  57.                 data.messages[i] = {msg, i}
  58.                 data.players[name].lastmessage = answer
  59.                
  60.                 for k in next, tfm.get.room.playerList do
  61.                     chatDisplay(k, true)
  62.                 end
  63.                 ui.addPopup(0, 2, "", name, 171, 309, 456, true)
  64.             else
  65.                 ui.addPopup(0, 2, "", name, 171, 309, 456, true)
  66.             end
  67.         else
  68.             ui.addPopup(0, 2, "", name, 171, 309, 456, true)
  69.         end
  70.        
  71.         if (answer:sub(1, 1) == '/' and data.admins[name]) then
  72.             local command = answer:sub(2)
  73.             if (command == 'clear') then
  74.                 data.messages = {}
  75.        
  76.                 for k in next, tfm.get.room.playerList do
  77.                     chatDisplay(k, true)
  78.                 end
  79.             end
  80.         end
  81.     end
  82. end
  83.  
  84. function eventTextAreaCallback(id, name, link)
  85.     if (link == 'close_chat') then
  86.         for id = 0, 2 do
  87.             ui.removeTextArea(id, name)
  88.         end
  89.         data.players[name].openchat = false
  90.  
  91.         ui.addTextArea(4, "<p align='center'><B><a href='event:open_chat'>Chat", name, 696, 378, 100, 21, 0x324650, 0x000000, 1, true)
  92.         ui.addPopup(0, 0, "", name, 5000, 5000)
  93.     elseif (link == 'open_chat') then
  94.         data.players[name].openchat = true
  95.         data.players[name].unreadmessages = 0
  96.        
  97.         ui.removeTextArea(4, name)
  98.         chatDisplay(name, false)
  99.     end
  100. end
Add Comment
Please, Sign In to add comment