Advertisement
wolfd

Untitled

Jul 27th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. function sort_by_amount(x, y)
  5.   return x.amount > y.amount
  6. end
  7.  
  8. function get_items()
  9.     local available_items = a.getAvailableItems()
  10.     local item_list = {}
  11.     local n = 1
  12.    
  13.     print(#available_items)
  14.  
  15.     for key,value in pairs( available_items ) do
  16.         local z = available_items[key]
  17.         local id = z[1]
  18.         item_list[n] = {}
  19.         item_list[n].id = id
  20.         item_list[n].name = id --string.sub(getUnlocalizedName(item_list[key].id),1,20)
  21.         item_list[n].amount = a.getItemAmount(item_list[key].id)
  22.         if (key%10 == 0) then
  23.             sleep(0.05)
  24.         end
  25.         n= n+1
  26.     end  
  27.     table.sort(item_list, sort_by_amount)
  28.     return item_list
  29. end
  30.  
  31. function display_items(item_list)
  32.     monX = 1
  33.     monY = 2
  34.     mon.clear()
  35.     for i = 1, total_items_to_display,1 do
  36.         name = item_list[i].name
  37.         amount = item_list[i].amount
  38.         mon.setCursorPos(monY, monX)
  39.         mon.write(name)
  40.         mon.setCursorPos(monY+21,monX)
  41.         mon.write(":        ")
  42.         amount_string = tostring(amount).." |"
  43.         mon.setCursorPos(monY+30-string.len(amount_string),monX)
  44.         mon.write(amount_string)
  45.         if monX == items_to_display_per_row then
  46.             monX = 0
  47.             monY = monY+30
  48.         end  
  49.         monX = monX+1
  50.     end  
  51. end
  52.  
  53. function main()
  54.     while true do
  55.         item_list = get_items()
  56.         display_items(item_list)
  57.         sleep(10)
  58.     end
  59. end
  60.  
  61. function boot()
  62.     iteration = 1
  63.     a = peripheral.wrap(a_direction)
  64.     mon = peripheral.wrap(mon_direction)
  65.     mon.setTextScale(0.5)
  66.     mon.clear()
  67.     mon.setTextScale(0.5)
  68.     mon.setCursorPos(34,26)
  69.     mon.write("AE  display  system  booting  up,  stand by...")
  70.     mon.setCursorPos(36,32)
  71.    
  72. end
  73.  
  74. items_to_display_per_row = 52
  75. total_items_to_display = 208
  76.  
  77. a_direction = "back"
  78. mon_direction = "top"
  79.  
  80. boot()
  81. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement