Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au and Nuqube.co--
- local scriptName, version, pastebinCode = "StockKeeper", "v1.0", "iWHbXKyf"
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or Nuqube.co or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- -- CHANGELOG --
- --V1.0
- -- SETUP --
- local tArgs = {...}
- do
- update = function(script_name, pastebincode)
- print("UPDATING") shell.run("pastebin get "..pastebincode.." update")
- if fs.exists("update") then
- fs.delete(script_name) fs.copy("update", script_name) fs.delete("update") print("UPDATE SUCCESS")
- else
- print("UPDATE FAILED")
- end
- sleep(2) os.reboot()
- end
- end
- if tArgs[1] == "update" then update(scriptName, pastebinCode) end
- input = {"bottom", "top", "front", "back"}
- sideReverse = {["bottom"] = "up", ["top"] = "down", ["left"] = "right", ["right"] = "left", ["front"] = "back", ["back"] = "front"}
- output = "bottom"
- craftingLoc = {1, 2, 3, 5, 6, 7, 9, 10, 11}
- redstone.setOutput("back", false)
- if fs.exists("dataStore") then
- local fh = fs.open("dataStore", 'r')
- data = textutils.unserialize(fh:readAll())
- fh.close()
- end
- data = data or {}
- function wrapper(param)
- local result = false
- result = peripheral.wrap(param) or false
- if result == false then print("missing chest @ "..param) end
- return result
- end
- chest = wrapper(output)
- function crafting(param)
- local result, tempPeripheral, inputData, materialsData, requiredMaterials, gatheringMaterials, matReturn = false, false, {}, {}, true, true, {}
- for a,b in pairs(input) do
- tempPeripheral = wrapper(b)
- if tempPeripheral ~= false then
- tempPeripheral.condenseItems()
- inputData[b] = tempPeripheral.getAllStacks()
- end
- end
- for a,b in pairs(inputData) do
- for c,d in pairs(inputData[a]) do
- materialsData[inputData[a][c]["id"]..":"..inputData[a][c]["rawName"]] = (materialsData[inputData[a][c]["id"]..":"..inputData[a][c]["rawName"]] or 0) + inputData[a][c]["qty"]
- end
- end
- for a,b in pairs(param["materials"]) do
- if tostring(materialsData[a]) ~= "nil" then
- if tonumber(materialsData[a]) < b then
- requiredMaterials = false
- end
- end
- end
- if requiredMaterials then
- for y,z in pairs(param["recipe"]) do
- for a,b in pairs(input) do
- tempPeripheral = wrapper(b)
- if tempPeripheral ~= false then
- tempPeripheral.condenseItems()
- inputData[b] = tempPeripheral.getAllStacks()
- end
- end
- for a,b in pairs(inputData) do
- for c,d in pairs(inputData[a]) do
- if inputData[a][c]["id"]..":"..inputData[a][c]["rawName"] == param["recipe"][y]["id"] then
- if inputData[a][c]["qty"] >= param["recipe"][y]["qty"] then
- tempPeripheral, matReturn[y] = wrapper(a), a
- tempPeripheral.pushItemIntoSlot(sideReverse[a], c, param["recipe"][y]["qty"], craftingLoc[y])
- end
- end
- end
- end
- end
- turtle.select(4)
- result = turtle.craft()
- for a,b in pairs(matReturn) do
- tempPeripheral = wrapper(matReturn[a])
- tempPeripheral.pullItemIntoSlot(sideReverse[matReturn[a]], craftingLoc[a], 64)
- end
- tempPeripheral = wrapper(output)
- tempPeripheral.pullItemIntoSlot(sideReverse[output], 4, 64)
- end
- return result
- end
- function scan()
- local craft, tempListA, tempListB, result = true, nil, {}, false
- for a,b in pairs(data) do
- chest.condenseItems()
- tempListA = chest.getAllStacks()
- tempListB = {}
- for a,b in pairs(tempListA) do tempListB[tempListA[a]["id"]..":"..tempListA[a]["rawName"]] = (tempListB[tempListA[a]["id"]..":"..tempListA[a]["rawName"]] or 0) + tempListA[a]["qty"] end
- if data[a]["min"] ~= false then
- if tostring(tempListB[a]) == "nil" or tempListB[a] < data[a]["min"] then
- craft = crafting(data[a]["craftMin"])
- result = true
- else
- craft = false
- end
- end
- if tostring(tempListB[a]) ~= "nil" and data[a]["max"] ~= false then
- if tempListB[a] > data[a]["max"] then
- craft = crafting(data[a]["craftMax"])
- result = true
- else
- craft = false
- end
- end
- end
- return result
- end
- if tArgs[1] == "mem" then
- local tempPeripheral, listA, listB, paramMin, paramMax, tempData, num, hold = wrapper(output), nil, {}, nil, nil, data, 0, nil
- local lock = true
- while lock do
- term.clear() term.setCursorPos(1,1)
- print("needs empty chest @ output to work")
- print("place result item in first slot of turtle and hit enter")
- read()
- if turtle.getItemCount(1) >= 1 then lock = false end
- end
- tempPeripheral.pullItemIntoSlot(sideReverse[output], 1, 1, 1)
- listA = tempPeripheral.getAllStacks()
- hold = listA[1]["id"]..":"..listA[1]["rawName"]
- tempData[hold] = {["min"] = false, ["max"] = false, ["craftMin"] = {["recipe"] = false, ["materials"] = false}, ["craftMax"] = {["recipe"] = false, ["materials"] = false}}
- tempPeripheral.pushItemIntoSlot(sideReverse[output], 1, 1, 1)
- term.clear() term.setCursorPos(1,1)
- print("type minium amount to keep stocked or false and hit enter")
- tempData[hold]["min"] = tonumber(read()) or false
- term.clear() term.setCursorPos(1,1)
- print("type maxium amount to keep stocked or false and hit enter")
- tempData[hold]["max"] = tonumber(read()) or false
- if tempData[hold]["min"] ~= false then
- lock = true
- while lock do
- term.clear() term.setCursorPos(1,1)
- print("remove previous setup items")
- print("place minium craft recipe in top-left 3x3 format and hit enter")
- read()
- num = 0
- for a,b in pairs(craftingLoc) do num = num + turtle.getItemCount(b) end
- if num >= 1 then lock = false end
- end
- for a,b in pairs(craftingLoc) do tempPeripheral.pullItemIntoSlot(sideReverse[output], b, 64, a) end
- listA = tempPeripheral.getAllStacks()
- tempData[hold]["craftMin"]["materials"], tempData[hold]["craftMin"]["recipe"] = {}, {}
- for a,b in pairs(listA) do
- tempData[hold]["craftMin"]["materials"][listA[a]["id"]..":"..listA[a]["rawName"]] = (tempData[hold]["craftMin"]["materials"][listA[a]["id"]..":"..listA[a]["rawName"]] or 0) + listA[a]["qty"]
- tempData[hold]["craftMin"]["recipe"][a] = {["id"] = listA[a]["id"]..":"..listA[a]["rawName"], ["qty"] = listA[a]["qty"]}
- end
- for a,b in pairs(craftingLoc) do tempPeripheral.pushItemIntoSlot(sideReverse[output], a, 64, b) end
- end
- if tempData[hold]["max"] ~= false then
- lock = true
- while lock do
- term.clear() term.setCursorPos(1,1)
- print("remove previous setup items")
- print("place maxium craft recipe in top-left 3x3 format and hit enter")
- read()
- num = 0
- for a,b in pairs(craftingLoc) do num = num + turtle.getItemCount(b) end
- if num >= 1 then lock = false end
- end
- for a,b in pairs(craftingLoc) do tempPeripheral.pullItemIntoSlot(sideReverse[output], b, 64, a) end
- listA = tempPeripheral.getAllStacks()
- tempData[hold]["craftMax"]["materials"], tempData[hold]["craftMax"]["recipe"] = {}, {}
- for a,b in pairs(listA) do
- tempData[hold]["craftMax"]["materials"][listA[a]["id"]..":"..listA[a]["rawName"]] = (tempData[hold]["craftMax"]["materials"][listA[a]["id"]..":"..listA[a]["rawName"]] or 0) + listA[a]["qty"]
- tempData[hold]["craftMax"]["recipe"][a] = {["id"] = listA[a]["id"]..":"..listA[a]["rawName"], ["qty"] = listA[a]["qty"]}
- end
- for a,b in pairs(craftingLoc) do tempPeripheral.pushItemIntoSlot(sideReverse[output], a, 64, b) end
- end
- data = tempData
- local fh = fs.open("dataStore", 'w')
- fh.write(textutils.serialize(data))
- fh.close()
- else
- while true do
- local result = false
- result = scan()
- if not result then
- os.startTimer(1)
- os.pullEvent()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment