Advertisement
ZottelvonUrvieh

receiverMonitor

Jul 23rd, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local serverID = 58 -- change to the id of the computer that sends the message
  2. local sSide = "right" -- change to the side of the monitor
  3. local w = rednet.open("top")
  4.  
  5. local mon = peripheral.wrap(sSide)
  6. if not mon then
  7.   print("No monitor on ", sSide)
  8.   return
  9. end
  10.  
  11. local printcentred =
  12. function(text, line)
  13.   local maxw, maxh = mon.getSize()
  14.   local curx, cury = mon.getCursorPos()
  15.   if line == nil then
  16.     line = cury
  17.   else
  18.     cury = line
  19.   end
  20.   mon.setCursorPos((maxw-#text+3)/2,cury)
  21.   mon.write(text)
  22.   mon.setCursorPos(curx,cury+1)
  23. end
  24.  
  25. function endswith(s, send)
  26.   if s == nil or send == nil then return false end
  27.   return #s >= #send and s:find(send, #s-#send+1, true) and true or false
  28. end
  29.  
  30. term.redirect(mon)
  31. while true do
  32.   local id, msg = rednet.receive()
  33.   if id == serverID then
  34.     if (endswith(msg, "at:")) then
  35.       mon.clear()
  36.       mon.setCursorPos(1, 3)
  37.     else
  38.       if (endswith(msg, "%")) then
  39.     mon.setCursorPos(1, 4)
  40.       else
  41.     if (endswith(msg, "mated:") or endswith(msg, "ges...") or endswith(msg, " in:") or endswith "%.") then
  42.       mon.setCursorPos(1,6)
  43.     else
  44.           mon.setCursorPos(1, 7)
  45.     end
  46.       end
  47.     end      
  48.       printcentred(msg)
  49.   end
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement