Advertisement
rhn

itembuffer

rhn
Mar 29th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.42 KB | None | 0 0
  1. if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
  2.     while true do
  3.         print("Number of slots to be filled before emptying(1-16):")
  4.         local answer = read()
  5.         if tonumber(answer)==nill then
  6.             print("-Wrong answer, input not a number-")
  7.         else
  8.             local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
  9.             if (0 < answerv and answerv <= 16) then
  10.                 slots=answerv
  11.                 --print("Crop ", croplist[answerv], " chosen")
  12.                 break
  13.             else
  14.                 print("-Wrong answer, input does not match range of choices-")
  15.             end
  16.         end
  17.     end
  18.  
  19.     while true do
  20.         print("Stacksize of items(1-64):")
  21.         local answer = read()
  22.         if tonumber(answer)==nill then
  23.             print("-Wrong answer, input not a number-")
  24.         else
  25.             local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
  26.             if (0 < answerv and answerv <= 64) then
  27.                 stacksize=answerv
  28.                 --print("Crop ", croplist[answerv], " chosen")
  29.                 break
  30.             else
  31.                 print("-Wrong answer, input does not match range of choices-")
  32.             end
  33.         end
  34.     end
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     --Write choices to file
  41.     local file = fs.open("choices","w")
  42.     file.writeLine("slots="..tostring(slots))
  43.     file.writeLine("stacksize="..tostring(stacksize))
  44.  
  45.     file.close()
  46. end
  47.  
  48.  
  49. os.loadAPI("choices") -- Reads choices from file
  50. local slots= choices.slots
  51. local stacksize= choices.stacksize
  52.  
  53.  
  54. --slots=14 --Number of slots to be filled before emtying
  55. --stacksize=64
  56.  
  57. local function empty()
  58.     for i=1,16 do
  59.         turtle.select(i)
  60.         turtle.drop()
  61.     end
  62. end
  63.  
  64.  
  65. while true do
  66. local emptyslot=0
  67. local maxcount=0
  68. for i=1,16 do
  69.     if turtle.getItemCount(i)==0 then
  70.         emptyslot=emptyslot+1
  71.     elseif turtle.getItemCount(i)>maxcount then
  72.             maxcount=turtle.getItemCount(i)
  73.     end
  74. end
  75.  
  76. if (emptyslot <= (16-slots) and maxcount>= 0.75*stacksize)  then
  77.     empty()
  78. elseif emptyslot==0 then
  79.     empty()
  80. end
  81. sleep(10)
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement