Advertisement
wolfd

Untitled

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