abuklao84

ThaumRoom

May 4th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. ps = peripheral.getNames()
  2. aspects = {}
  3. pers = {}
  4. aspectsC = {}
  5. ex_Aspects = {"ira", "infernus", "gula", "invidia", "desidia", "superbia", "luxuria", "tempus"}
  6. m = peripheral.wrap("left")
  7. w,h = m.getSize()
  8. cols = 3
  9. colS = w/cols
  10. h = h-2
  11. --aspects[num][1] = peripheral.call(per, "getAspects")[1]
  12.  
  13. function getA() -- function gets aspects and its values
  14.     for num, per in pairs(ps) do
  15.     type = peripheral.getType(per)
  16.         if type == "tt_aspectContainer" then
  17.             aspect = peripheral.call(per, "getAspects")[1]
  18.             ifNil(aspect,per)
  19.         elseif type== "tilejarvoid" then
  20.             aspect = peripheral.call(per, "getAspects")[1][2]
  21.             ifNil(aspectper)
  22.         end
  23.        
  24.     end
  25.    
  26. end
  27.  
  28. function order(arr)
  29.     table.sort(arr)
  30.     for e,l in pairs(arr) do
  31.         ass, pers = l:match("([^,]+),([^,]+)")
  32.         quantity = peripheral.call(pers,"getAspectCount",ass)
  33.         table.insert(aspectsC,{["a"] = ass,["q"] = quantity})
  34.     end
  35. end
  36.  
  37. function ifNil(aspectation,peripheral)
  38.     if aspectation ~= nil then
  39.             table.insert(aspects,aspectation..","..peripheral)
  40.         end
  41. end
  42.  
  43. function fixNumber(number)
  44.     number = tostring(number)
  45.     if(string.len(number) < 2) then
  46.     number = "0"..number
  47.     end
  48. return number
  49. end
  50.  
  51. function setColor(aspectCount)
  52.     if(aspectCount == 0) then
  53.     m.setTextColor(colors.red)
  54.     elseif((aspectCount < 17) and (aspectCount > 0)) then
  55.     m.setTextColor(colors.yellow)
  56.     elseif((aspectCount < 64) and (aspectCount > 16)) then
  57.     m.setTextColor(colors.cyan)
  58.     elseif(aspectCount == 64) then
  59.     m.setTextColor(colors.green)
  60.     end
  61. end
  62.  
  63. function writeA()-- function writes on the screen
  64.     m.clear()
  65.     m.setCursorPos(1,1)
  66.     height = 1
  67.     col = 0
  68.     for p,j in pairs(aspectsC) do
  69.         setColor(j["q"])
  70.         m.write(j["a"])
  71.         m.setCursorPos((col+1)*(colS-1),height)
  72.         m.write(fixNumber(j["q"]))
  73.         if height > h then
  74.             height = 1
  75.             col = col + 1
  76.         else
  77.             height = height+1
  78.         end
  79.         m.setCursorPos(col*colS+1,height)
  80.    
  81.     end
  82. end
  83. shell.run("clear")
  84. print("This program will output to the monitor on top the aspects it detects")
  85. print("Click on the screen to refresh the values")
  86.  
  87. while true do
  88. getA()
  89. order(aspects)
  90. writeA()
  91. local side, x, y = os.pullEvent("monitor_touch")
  92. os.reboot()
  93. end
Advertisement
Add Comment
Please, Sign In to add comment