Advertisement
Chaos_Cash

messageSender.lua

Mar 15th, 2025 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. function sendWithThisBox(boxKey)
  2.  
  3.     for k,v in pairs(sendTheseMessages) do
  4.     curMessageKey = k
  5.     curMessage = v["message"]
  6.     curPlayer = v["player"]
  7.     curColor = v["color"]
  8.     break
  9.     end
  10.  
  11. local chatBox = chatBoxes[boxKey]["peripheral"]
  12.  
  13.  
  14.     if type(curMessage) ~= "table" then
  15.     local json = textutils.serialiseJSON({text = curMessage, color = curColor})
  16.     chatBox.sendFormattedMessageToPlayer(json, curPlayer, systemName)
  17.     table.remove(sendTheseMessages, curMessageKey)
  18.     chatBoxes[boxKey]["cooldownTime"] = os.epoch("local")
  19.     return
  20.     end
  21.  
  22.  
  23.     for k,v in pairs(curMessage) do
  24.         if type(v) == "table" then
  25.             if not v["color"] then
  26.             curMessage[k]["color"] = curColor
  27.             end
  28.         else
  29.         curMessage[k] = {text = v, color = curColor}
  30.         end
  31.     end
  32.    
  33. local json = textutils.serialiseJSON(curMessage)
  34. chatBox.sendFormattedMessageToPlayer(json, curPlayer, systemName)
  35.  
  36.  
  37. table.remove(sendTheseMessages, curMessageKey)
  38. chatBoxes[boxKey]["cooldownTime"] = os.epoch("local")
  39. end
  40.  
  41.  
  42.  
  43.    
  44. function mainSender()
  45.     while true do
  46.         if table.maxn(sendTheseMessages) < 1 then
  47.         os.pullEvent("sendMessage")
  48.         else
  49.         sleep(0.05)
  50.         end
  51.  
  52.  
  53.         for chatBoxKey,chatBox in pairs(chatBoxes) do
  54.             if os.epoch("local") - chatBox["cooldownTime"] > 999 then
  55.             sendWithThisBox(chatBoxKey)
  56.             end
  57.            
  58.             if table.maxn(sendTheseMessages) < 1 then
  59.             break
  60.             end
  61.         end
  62.  
  63.     end
  64. end
  65.  
  66.  
  67.  
  68.     while true do
  69.     sleep(1)
  70.     mainSender()
  71.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement