Muzze77

SortingMEOriginal

May 11th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2. shell.run("clear")
  3.  
  4. sides = {"top","left","right","bottom","front","back"}
  5. for side = 1, #sides, 1 do
  6.     if peripheral.isPresent(sides[side]) then
  7.  
  8.     na = peripheral.getType(sides[side])
  9.  
  10.         if na == "monitor" then
  11.     print("Monitor wrapped")
  12.     mon = peripheral.wrap(sides[side])
  13.         elseif na == "sensor" then
  14.     print("Sensor wrapped")
  15.     sen = sensor.wrap(sides[side])
  16.         end
  17.     end
  18. end
  19. Wireless = 0
  20. globX, globY = mon.getSize()
  21.  
  22.  
  23. targs = sen.getTargets()
  24. if targs == nil or targs == "" then
  25. error("Kein ME WIRELESS ACCES POINT IN RANGE")
  26. end
  27. for v, k in pairs(targs) do
  28.     if k.Name == "ME Wireless Access Point" then
  29.     locale = v
  30.     Wireless = Wireless + 1
  31.     end
  32.  
  33. end
  34. if Wireless < 1 then
  35. error("Kein ME WIRELESS ACCES POINT IN RANGE")
  36. end
  37.  
  38.  
  39. function tableSortSize(a,b)
  40.   return(a.ItemSize > b.ItemSize)
  41. end
  42.  
  43. function cbut(cx,cy,tcol,itemName, itemSize)
  44. if tcol == nil or tcol == "" then
  45.   tcol = colors.white
  46. end
  47. mon.setTextColor(tcol)
  48. mon.setCursorPos(cx,cy)
  49. mon.clearLine(cy)
  50. mon.write(itemName .. ": " .. itemSize)
  51. mon.setTextColor(colors.white)
  52. end
  53.  
  54.  
  55.  
  56.  
  57.  
  58. function itemClaim(itemName1, itemSize1,posX,posY,color)
  59.   table.insert(items,{ItemName = itemName1,ItemSize = itemSize1,locationX = posX, locationY = posY, colorID = color})  
  60. end
  61.  
  62.  
  63.  
  64. mon.clear()
  65.  
  66. while true do
  67.   items = {}
  68.   mon.setCursorPos(globX/2-9,1)
  69.   mon.clearLine(1)
  70.   mon.write("ME Inventar")
  71.   s = sen.getTargetDetails(locale)
  72.  
  73.   for v, k in pairs(s.Items) do
  74.     if k.Name == "UU-Matter" then
  75.     itemClaim(k.Name,k.Size,2,0,colors.pink)
  76.     elseif k.Name == "Iron Ingot" then
  77.     itemClaim(k.Name,k.Size,2,0,colors.gray)
  78.     end
  79.   end
  80.  
  81.   table.sort(items,tableSortSize)
  82.  
  83.   for itemK=1, #items do
  84.     cbut(items[itemK].locationX, itemK + 1, items[itemK].colorID, items[itemK].ItemName,items[itemK].ItemSize)
  85.   end
  86.  
  87.  
  88.   items = nil
  89.   sleep(10)
  90.  
  91. end
Add Comment
Please, Sign In to add comment