Advertisement
thatparadox

StargateMon

Dec 23rd, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. for k,v in pairs(rs.getSides()) do
  2.   if peripheral.getType(v)=='monitor' then
  3.    side = v
  4.    mon = peripheral.wrap(side)
  5.    break
  6.   end
  7. end
  8. for k,v in pairs(rs.getSides()) do
  9.   if peripheral.getType(v)=='modem' then
  10.    rednet.open(v)
  11.    break
  12.   end
  13. end
  14. monX, monY = mon.getSize()
  15.  
  16. detect =
  17.  
  18. while true do
  19.     rednet.receive()
  20.     if id == detect and message == "new" then
  21.         rednet.send(detect, "true")
  22.         id, name = rednet.receive()
  23.         rednet.send(detect, true)
  24.         id, address = rednet.receive()
  25.         table = {name = name, address = address}
  26.         table = textutils.serialize(table)
  27.         for i = 1, monY do
  28.             if fs.exists(tostring(i)) == false then
  29.                 file = fs.open(tostring(i), "w")
  30.                 file.write(table)
  31.                 file.close()
  32.                 break
  33.             end
  34.         end
  35.     elseif id == detect and message == "true" then
  36.         mon.clear()
  37.         for i = 1, monY do
  38.         if fs.exists(i) then
  39.             file = fs.open(i)
  40.             data = file.readAll()
  41.             file.close()
  42.             data = textutils.unserialize(data)
  43.             for key,value in pairs(data) do
  44.                 mon.setCursorPos(monX/2-string.len(tostring(key..": "..value))/2, i)
  45.                 mon.write(tostring(key..": "..value))
  46.             end
  47.         end
  48.     end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement