Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Uncomment to use given pipe side.
- --PipeSide="bottom"
- --Uncomment to use given monitor side(s). Put commas between for multiple sides, keep the curly braces.
- --MonitorSide={"top"}
- sleepTime=60 --In seconds. Default is 60.
- ItemsPerTick=10 --How many items it should search per tick. Default is 10.
- ItemThreshold=64 --The max amount of items it can have and still be requested. Default is 64.
- writeToConsole=true --Should it write to the computer itself?
- writeToMonitor=true --Should it write to connected monitors?
- local function getMonitors()
- MonTbl={}
- local Peripherals=peripheral.getNames()
- for i=1,#Peripherals do
- if peripheral.getType(Peripherals[i])=="monitor" then
- table.insert(MonTbl,Peripherals[i])
- end
- end
- return MonTbl
- end
- local function findPeripheral(type)
- local Peripherals=peripheral.getNames()
- for i=1,#Peripherals do
- if peripheral.getType(Peripherals[i])==type then
- return Peripherals[i]
- end
- end
- return nil
- end
- local function draw(str)
- if writeToMonitor then
- MonTbl=MonitorSide or getMonitors()
- for i=1,#MonTbl do
- local p=peripheral.wrap(MonTbl[i])
- p.write(str)
- end
- end
- if writeToConsole then
- term.write(str)
- end
- end
- local function Clear()
- if writeToMonitor then
- MonTbl=MonitorSide or getMonitors()
- for i=1,#MonTbl do
- local p=peripheral.wrap(MonTbl[i])
- p.clear()
- end
- end
- if writeToConsole then
- term.clear()
- end
- end
- local function CursorPos(x,y)
- if writeToMonitor then
- MonTbl=MonitorSide or getMonitors()
- for i=1,#MonTbl do
- local p=peripheral.wrap(MonTbl[i])
- p.setCursorPos(x,y)
- end
- end
- if writeToConsole then
- term.setCursorPos(x,y)
- end
- end
- local function countDown(sleepTime)
- for i=(sleepTime*10),0,-1 do
- CursorPos(1,1)
- draw(clr)
- CursorPos(1,1)
- draw(i/10)
- draw("s until next search.")
- sleep(0.1)
- end
- CursorPos(1,1)
- draw(clr)
- CursorPos(1,1)
- draw("Searching...")
- end
- --Setup for the main loop
- local clr=""
- local MonTbl=MonitorSide or getMonitors()
- x,y=term.getSize()
- for i=1,#MonTbl do
- local p=peripheral.wrap(MonTbl[i])
- local x2,y2=p.getSize()
- x=math.max(x,x2)
- y=math.max(y,y2)
- end
- for i=1,x do
- clr=clr.." " --String that will clear the whole line of a monitor.
- end
- if PipeSide and peripheral.getType(PipeSide)=="LogisticsPipes:Request" then
- local m=peripheral.wrap(PipeSide)
- else
- if peripheral.find then --Checks to see if peripheral.find exists at all
- local m=peripheral.find("LogisticsPipes:Request")
- else
- local m=findPeripheral("LogisticsPipes:Request") --This isn't as nice as peripheral.find(), but it'll work.
- end
- end
- if not m then
- error("No request pipe found.")
- end
- --Main loop
- while true do
- local Items=m.getAvailableItems()
- local Count=0
- for k,v in pairs(Items) do
- local id=v.getValue1()
- local amt=m.getItemAmount(id)
- if amt<=ItemThreshold then
- Count=Count+1
- m.makeRequest(id,amt)
- end
- if k%ItemsPerTick==0 then
- sleep(0.05)
- end
- end
- Clear()
- CursorPos(1,2)
- if Count==1 then
- draw(Count.." item pulled w/<="..ItemThreshold.." items.")
- else
- draw(Count.." items pulled w/<="..ItemThreshold.." items.")
- end
- countDown(sleepTime)
- end
- --Program by moomoomoo3O9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement