Advertisement
Oleshe

Image Dungen Master

Feb 11th, 2023 (edited)
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. local event = require('event')
  2. local modem = require('component').modem
  3. modem.open(1)
  4. local image = require('image')
  5. local function get(address,CT)
  6.   for c in require('component').list(CT,true) do
  7.     if c:sub(1,address:len()) == address then
  8.        return c
  9.     end
  10.   end
  11. end
  12. local mon = {}
  13.  
  14. local raid = '/Mounts/'..get('RAID ADDRESS')..'/'
  15. local sr = require('serialization')
  16.  
  17. local function pack(data)
  18.   return sr.serializate(data)
  19. end
  20. local function unpack(data)
  21.   return sr.unserializate(data)
  22. end
  23.  
  24. while true do
  25.   local _, _, _, _, _, e1, e2, e3 = event.pull('modem_message')
  26.   if e1 == 'image' then
  27.     local img = image.load(raid..e2)
  28.     for x =1,6 do
  29.       mon[x] = {}
  30.       for y = 1,5 do
  31.         mon[x][y] = {}
  32.       end
  33.     end
  34.     local w = img[1]
  35.     local h = img[2]
  36.     for x = 1,w do
  37.       for y = 1,h do
  38.       local bg,fg,_,symbol = image.get(img,x,y)
  39.       local x = x + x1 - 1
  40.       local y = y + y1 -1
  41.       local xx = math.ceil(x / 126)
  42.       local yy = math.ceil(y / 63)
  43.       local localX = x - (xx - 1) * 126
  44.       local localY = y - (yy - 1) * 63
  45.       table.insert(mon[xx][yy],{localX,localY,bg,fg,symbol})
  46.       end
  47.     end
  48.     for x = 1,6
  49.       for y=1,5 do
  50.         modem.broadcast(1,x,y,'mon = '..pack(mon[x][y]))
  51.       end
  52.     end
  53.   end
  54. end
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement