Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Simple item transferrer from chosen inventory adjacent to computer, to/from another inventory adjacent to that.
- -- X Y
- -- C
- -- C: ComputerCraft computer adjacent to inventory X
- -- X,Y: Inventories adjacent to each other.
- -- Install script named "startup". First time run go through the options, selecting side of X is attached to C, which direction C is relative to X(ingame coordinate directions), pull or push mode, stack size and delay.
- -- Most efficient in push mode!
- sides={"top","bottom","right","left","front","back"}
- directions={"up","down","north","south","west","east"}
- if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
- while true do --Asks for side for attached inventory
- print("Please pick which side of computer has attached inventory.")
- for i=1, #sides do
- print(i..". "..sides[i])
- end
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 6) then
- if peripheral.isPresent(sides[answerv]) then
- side1=answerv
- --print("Side ", sides[side1], " chosen")
- break
- else
- print("-No adjacent inventory found at chosen side-")
- end
- else
- print("-Wrong answer, input does not match number of sides-")
- end
- end
- end
- print("-------------------------------")
- while true do --Ask for direction to push items from attached inventory
- print("Please pick direction of secondary inventory.")
- for i=1, #directions do
- print(i..". "..directions[i])
- end
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 6) then
- side2=answerv
- --print("Direction ", directions[side2], " chosen")
- break
- else
- print("-Wrong answer, input does not match number of directions-")
- end
- end
- end
- print("-------------------------------")
- while true do --Push or pull
- print("Push or pull items?")
- print("1. Push items (Recommended)")
- print("2. Pull items")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 2) then
- operation=answerv
- break
- else
- print("-Wrong answer, input does not match range-")
- end
- end
- end
- print("-------------------------------")
- if operation == 2 then
- while true do --pull inv size
- print("Size of inventory to pull from?")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 64) then
- pullsize=answerv
- break
- else
- print("-Wrong answer, input does not match range-")
- end
- end
- end
- end
- print("-------------------------------")
- while true do --Ask for stack size to move
- print("Please pick stacksize(1-64) for each item transfer.")
- print("(64 Recommended)")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 64) then
- stack=answerv
- --print("Stacksize ", stack, " chosen")
- break
- else
- print("-Wrong answer, input does not match range of stacksize-")
- end
- end
- end
- print("-------------------------------")
- while true do --Ask for delay between transfer cycle(cycle = one stack from each slot in inventory)
- print("Please pick delay between transfer cycles in seconds.")
- print("(0.5+, but higher recommended)")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0.5 <= answerv) then
- delay=answerv
- --print("Delay ", delay, " chosen")
- break
- else
- print("-Wrong answer, delay too small. Do you WANT lag? This is how you get lag!!!-")
- end
- end
- end
- --Write choices to file
- local file = fs.open("choices","w")
- file.writeLine("side1="..tostring(side1))
- file.writeLine("side2="..tostring(side2))
- file.writeLine("stack="..tostring(stack))
- file.writeLine("delay="..tostring(delay))
- file.writeLine("operation="..tostring(operation))
- file.close()
- print("-------------------------------")
- print(" / )")
- print(" ' /")
- print("---' (_____")
- print(" ((__)")
- print(" _ ((___)")
- print(" -'((__)")
- print("--.___((_)")
- print("-------------------------------")
- end
- sleep(math.random()) --Random delay to stagger startup of many scripts on chunkload.
- os.loadAPI("choices") -- Reads choices from file
- local side1 = choices.side1
- local side2= choices.side2
- local stack= choices.stack
- local delay= choices.delay
- local operation= choices.operation
- print("Beginning item transfer with following settings:")
- print("Side of attached inventory to the: "..sides[side1])
- print("Direction of secondary inventory: "..directions[side2])
- if operation == 1 then
- print("Pushing items from primary to secondary inventory")
- else
- print("Pulling items from secondary to primary inventory")
- end
- print("Stack size of: "..stack)
- print("Cycle delay: "..delay.." second(s).")
- inv = peripheral.wrap(sides[side1])
- invsize = inv.size()
- while true do
- if operation == 1 then
- sleepcounter=0
- for i=1,invsize do
- if inv.getItemMeta(i) ~= nil then
- inv.pushItems(directions[side2],i,stack)
- sleep(0.1)
- else
- sleepcounter=sleepcounter+1
- sleep(0.005)
- end
- end
- if sleepcounter ==invsize then
- --print("No work, sleeping 10s")
- sleep(10)
- end
- elseif operation == 2 then
- for i=1,pullsize do
- inv.pullItems(directions[side2],i,stack)
- sleep(0.1)
- end
- end
- sleep(delay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement