resaloli

MineColonies - Builder Requirements lister

Jan 20th, 2023
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | Gaming | 0 0
  1. -- Copyright 2023 © Roberto "ResaloliPT" Pires
  2. local builders = {}
  3.  
  4. function getBuilders()
  5.     local buildings = colony.getBuildings()
  6.  
  7.  
  8.     local count = 1
  9.     for i,v in ipairs(buildings) do
  10.         if v.type == 'builder' then
  11.             builders[count] = v
  12.             count = count + 1
  13.         end
  14.     end
  15. end
  16.  
  17. function drawSelection()
  18.     local selectedNum = nil;
  19.     local selected = false
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22.  
  23.     print("Select a builder:")
  24.     for i,v in pairs(builders) do
  25.         print(i .. ": " .. v.name)
  26.     end
  27.  
  28.     while selected == false do
  29.         term.write(">")
  30.         selectedNum = read()
  31.         if builders[tonumber(selectedNum)] == nil then
  32.             print("Try Again:")
  33.         else
  34.             selected = true
  35.         end
  36.     end
  37.  
  38.     drawBuilderRequests(builders[tonumber(selectedNum)])
  39. end
  40.  
  41. function drawBuilderRequests(builder)
  42.     term.clear()
  43.     term.setCursorPos(1,1)
  44.  
  45.     local filteredResources = {}
  46.     local builderResources = colony.getBuilderResources(builder.location)
  47.     for i,v in ipairs(builderResources) do
  48.         if (v.status == "DONT_HAVE" or v.status == "NEED_MORE") and
  49.             ((v.item.maxCount - (v.delivering)) > 0) then
  50.             --table.insert(filteredResources, v)
  51.         end
  52.  
  53.         textutils.pagedPrint(textutils.serialise(v))
  54.     end
  55.  
  56.  
  57.     print("'" .. builder.name .. "' Requires:")
  58.     local finalText = {}
  59.  
  60.     for i,v in ipairs(filteredResources) do
  61.         local remainingCount = (v.item.maxCount - (v.delivering))
  62.  
  63.         table.insert(finalText, remainingCount .. " of " .. v.item.displayName)
  64.     end
  65.  
  66.     textutils.pagedTabulate(finalText)
  67.  
  68.     os.pullEvent("key")
  69. end
  70.  
  71.  
  72. -- Program Exec
  73. getBuilders()
  74. while true do
  75.     drawSelection()
  76.     sleep(1)
  77. end
Add Comment
Please, Sign In to add comment