Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --{program="bDrone",version="1.01",date="2021-03-15"}
- ---------------------------------------
- -- bDrone by Kaikaku
- -- 2021-03-15, v1.01 desription
- -- 2021-03-13, v1.00 initial
- -- A35d84ge
- ---------------------------------------
- ---------------------------------------
- ---- DESCRIPTION ----------------------
- ---------------------------------------
- -- Builds at build height limit either
- -- a prank drone that drops every
- -- morning an item or a rapid fire
- -- drone that shoots via wireless
- -- commands up to 2880 arrows.
- -- For more details see info screens
- -- in program and YouTube video.
- ---------------------------------------
- ---- ASSUMPTIONS ----------------------
- ---------------------------------------
- -- Standard turtle is okay.
- -- Needs crafty turtle for RFD.
- -- Needs modem to send fire command.
- ---------------------------------------
- ---- PARAMETERS -----------------------
- ---------------------------------------
- local cVersion ="v1.01"
- local cPrgName ="bDrone"
- local cMinFuel =600
- local cSleepTime=60+5
- local cMaxTurns =-1
- local turnCounter =0
- local turnsRemaining =cMaxTurns
- local harvestedStuff=0
- local harvestedStuffTotal=0
- local blnAskForParameters =true
- local blnDebugPrint =false--true--
- local blnRefill=false
- local blnFire=false
- local amountFire=0
- local blnRFD=false
- ---------------------------------------
- ---- VARIABLES ------------------------
- ---------------------------------------
- local slotDropper=1
- local slotSensor=2
- local slotTrapdoor=3
- local slotCarpet=4
- local slotJunkStart=5
- local slotJunkEnd=13
- local slotModem=14
- local slotDiskDrive=15
- local slotDisk=16
- local slotFuel=16
- local upSteps=0
- local blockDropper = {}
- blockDropper[1]="minecraft:dropper"
- blockDropper[2]="minecraft:dispenser"
- local isComputer=false
- ---------------------------------------
- ---- Early UI functions ---------------
- ---------------------------------------
- local function swapColors()
- local backColor=term.getBackgroundColor()
- local textColor=term.getTextColor()
- term.setBackgroundColor(textColor)
- term.setTextColor(backColor)
- end
- local function printUI(strInput)
- if strInput==ni then strInput="" end
- if strInput=="header" then
- term.write("") swapColors() print("") swapColors()
- elseif strInput=="line" then
- term.write("") swapColors() print("") swapColors()
- elseif strInput=="footer" then
- term.write("") print()
- else
- term.write("")
- strInput=strInput.." "
- term.write(string.sub(strInput,1,37))
- swapColors() print("") swapColors()
- end
- end
- local function coloredTextAt(inputText,outputRow,outputCol,textColor,backColor)
- -- writes and colors text to coordinates
- local oldRow, oldCol = term.getCursorPos()
- local oldTextColor=term.getTextColor()
- local oldBackColor=term.getBackgroundColor()
- if textColor==nil then textColor=term.getTextColor() end
- if backColor==nil then backColor=term.getBackgroundColor() end
- term.setTextColor(textColor)
- term.setBackgroundColor(backColor)
- term.setCursorPos(outputRow,outputCol)
- term.write(inputText)
- term.setCursorPos(oldRow, oldCol)
- term.setTextColor(oldTextColor)
- term.setBackgroundColor(oldBackColor)
- end
- ---------------------------------------
- ---- tArgs ----------------------------
- ---------------------------------------
- local tArgs = {...}
- local paraIdentified=false
- local paraNumberCount=0
- term.clear() term.setCursorPos(1,1)
- -- header
- if #tArgs~=0 then
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku. Enjoy!")
- printUI("line")
- print("Starting...")
- end
- -- check parameters
- for i=1,#tArgs do
- blnAskForParameters=false
- paraIdentified=false
- -- rfd-rapid fire drone?
- if not paraIdentified then
- if string.lower(tArgs[i])=="rfd" then
- paraIdentified=true blnRFD=true
- blnAskForParameters=false
- print("Option: build Rapid Fire Drone!")
- end
- end
- -- fire?
- if not paraIdentified then
- if string.lower(tArgs[i])=="fire" then
- if #tArgs<i+1 then error("Parameter 'fire' requires number (e.g., "..cPrgName.." fire 100)") end
- amountFire=tonumber(tArgs[i+1])
- if amountFire==nil then error("Parameter 'fire' requires number (e.g., "..cPrgName.." fire 100)") end
- if amountFire<0 then amountFire=1 end
- paraIdentified=true blnFire=true
- blnAskForParameters=false
- print("Option: fire drone!")
- break
- end
- end
- -- refill?
- if not paraIdentified then
- if string.lower(tArgs[i])=="refill" or string.lower(tArgs[i])=="refil" then
- paraIdentified=true blnRefill=true
- blnAskForParameters=false
- print("Option: refill a drone!")
- end
- end
- -- max movement up
- if not paraIdentified then
- if paraNumberCount==0 then
- cMaxTurns=tonumber(tArgs[i]) -- used to cap hight
- paraIdentified=true
- paraNumberCount=paraNumberCount+1
- blnAskForParameters=false
- print("Option: cap movement up at "..cMaxTurns)
- end
- end
- if not paraIdentified then
- error("Error: Unknown parameter "..i..":'"..tArgs[i].."'")
- end
- sleep(0.3)
- end
- if blnFire then
- -- fire has high priority
- if cMaxTurns>0 then cMaxTurns=-1 print("Info: fire overrides max up movement.") end
- if blnRefill then blnRefill=false print("Info: fire overrides refill.") end
- end
- if cMaxTurns>0 and blnRefill then
- -- refill has no hight max
- cMaxTurns=-1
- print("Info: refill overrides max up movement.")
- end
- ---------------------------------------
- -- basic functions for turtle control -
- ---------------------------------------
- -- 2021-03-05 stuff -
- -- 2021-02-06 select+place -
- -- 2021-01-29 save turtle go func -
- -- checkInventory w/ exit -
- -- refuelManager -
- ---------------------------------------
- local function gf(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.forward() do end end end
- local function gb(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.back() do end end end
- local function gu(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.up() do end end end
- local function gd(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.down() do end end end
- local function gl(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnLeft() do end end end
- local function gr(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnRight() do end end end
- local function df() turtle.dig() end
- local function du() turtle.digUp() end
- local function dd() turtle.digDown() end
- local function pf() return turtle.place() end
- local function pu() return turtle.placeUp() end
- local function pd() return turtle.placeDown() end
- local function sf() turtle.suck() end
- local function su() turtle.suckUp() end
- local function sd() turtle.suckDown() end
- local function Df() turtle.drop() end
- local function Du(n) turtle.dropUp(n) end
- local function Dd() turtle.dropDown() end
- local function ss(s) turtle.select(s) end
- local function gic(s) return turtle.getItemCount(s) end
- local function gfs(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.forward() do df() end end end
- local function gbs(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.back() do gl() gl() df() gr() gr() end end end
- local function gus(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.up() do du() end end end
- local function gds(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.down() do dd() end end end
- local function pfs() df() turtle.place() end
- local function pus() du() turtle.placeUp() end
- local function pds() dd() turtle.placeDown() end
- local function gfr() return turtle.forward() end -- <<-- add to template
- local function gbr() return turtle.back() end
- local function gur() return turtle.up() end
- local function gdr() return turtle.down() end
- local function spd(s,blnForward)
- if s==nil then s=turtle.currentSlot() end
- if blnForward==nil then blnForward=true end
- ss(s) pd() if blnForward then gf() end
- end
- local function spu(s,blnForward)
- if s==nil then s=turtle.currentSlot() end
- if blnForward==nil then blnForward=true end
- ss(s) pu() if blnForward then gf() end
- end
- local function spf(s,blnBack)
- if s==nil then s=turtle.currentSlot() end
- if blnBack==nil then blnBack=true end
- ss(s) pf() if blnBack then gb() end
- end
- local function waitKey(strText)
- local event, scancode
- write(strText)
- event, scancode = os.pullEvent("key")
- print()
- end
- local function askForInputText(textt)
- local at=""
- -- check prompting texts
- if textt==nil then textt="Enter text:" end
- -- ask for input
- write(textt)
- at=read()
- return at
- end
- local function askForNumber(askText, minValue, maxValue)
- -- gets entered data, ensures it's a number and returns it
- -- keeps asking if entry is not a number
- -- adapts to min and max values
- -- allways writes in screen line 13 (last for turtles)
- -- calls askForInputText
- local blnReask=true
- local returnNumber=nil
- if minValue==nil then minValur=1 end
- if maxValue==nil then maxValue=100 end
- if askText==nil then askText="Key in number and press Enter: " end
- while blnReask do
- term.setCursorPos(1,13)
- returnNumber=askForInputText(askText)
- if returnNumber==nil then
- blnReask=true
- else
- returnNumber=tonumber(returnNumber)
- if returnNumber==nil then
- blnReask=true
- else
- returnNumber=math.floor(returnNumber)
- if returnNumber>maxValue then returnNumber=maxValue end
- if returnNumber<minValue then returnNumber=minValue end
- blnReask=false
- end
- end
- end
- return returnNumber
- end
- local function pressKeyNoSpecials(askText)
- -- excludes ctrl / alt / shifts
- -- catches windows
- -- retruns the key number (if needed at all)
- local tmpEvent, tmpKey
- if askText==nil then askText="Press key to START! (stop w/ ctrl+t) " end
- tmpKey=341
- while tmpKey>=340 and tmpKey<=346 do -- ctrls, alts, shifts
- term.write("Press key to START! (stop w/ ctrl+t) ") tmpEvent, tmpKey = os.pullEvent("key")
- if tmpKey==nil then tmpKey=341 end -- win
- end
- return tmpKey
- end
- local function checkFuel()
- local tmp=turtle.getFuelLevel()
- return tmp
- end
- local function checkTurtle()
- -- turtle?
- local turtleOk, turtleVal = pcall(checkFuel)
- if not turtleOk then
- term.clear() term.setCursorPos(1,1)
- if blnFire then isComputer=true return end
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku")
- printUI("line")
- printUI("This is mainly a turtle program.")
- printUI(" Please, execute it with a turtle!")
- printUI("")
- printUI("However, you can use computers to")
- printUI(" send fire commands to rapid fire")
- printUI(" drones. Do this with the command:")
- printUI("")
- printUI(" "..cPrgName.." fire xxx")
- printUI("")
- printUI(" with xxx=number of redstone pulses")
- printUI("")
- printUI("Enjoy! ")
- printUI("footer")
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("fire commands",9,8,nil,colors.red)
- coloredTextAt(cPrgName.." fire xxx",4,11,colors.red)
- coloredTextAt("",9,15,colors.red)
- error()
- end
- end
- local function sleepDots(sec)
- if sec==nil then sec=10 end
- if sec<1 then return end
- for i=1,sec-1 do
- sleep(1)
- term.write(".")
- end
- sleep(1)
- print(".")
- end
- local function checkInventory(s, nMin, nMax, textt, blnExitOnFalse, blnRepeat)
- -- checks if in slot s are not less than nMin and not more than nMax items
- -- returns true if okay
- -- if not displays textt
- -- blnExitOnFalse=true raises an error
- -- blnRepeat=true repeatedly sks to put in the right number of items (overrides blnExitOnFalse)
- local oldSlot = turtle.getSelectedSlot()
- if s==nil then s=turtle.getSelectedSlot() end
- if nMin==nil then nMin=0 end
- if nMax==nil then nMax=64 end
- if blnExitOnFalse==nil then blnExitOnFalse=false end
- if blnRepeat==nil then blnRepeat=false end
- if blnRepeat~=true then blnRepeat=false end
- while true do
- if turtle.getItemCount(s)<nMin or turtle.getItemCount(s)>nMax then
- print(textt)
- if not blnRepeat then
- -- single check ends with this
- if blnExitOnFalse then
- error()
- else
- ss(oldSlot) return false
- end
- end
- -- repeated check
- ss(s)
- sleepDots(3)
- else
- -- everything is fine
- ss(oldSlot) return true
- end
- end
- end
- local function refuelFromSlot(s, n) -- slot, amount to consume
- if s==nil then s=16 end
- if n==nil then n=64 end
- local currentSlot = turtle.getSelectedSlot()
- local fuelItems = turtle.getItemCount(s)
- local returnValue = false
- if fuelItems>0 then
- ss(s)
- returnValue=turtle.refuel(n)
- ss(currentSlot)
- end
- return returnValue
- end
- local function refuelManager(setMinFuel,setSlotFuel,waitTime)
- local currentSlotSelected=turtle.getSelectedSlot()
- ss(setSlotFuel)
- while turtle.getFuelLevel()<setMinFuel do
- print("Need more fuel ("..turtle.getFuelLevel().."/"..setMinFuel..").")
- if not refuelFromSlot(setSlotFuel) then
- -- unsucessfull try
- print(" Please, put fuel items in slot "..setSlotFuel.."!")
- term.write(" Sleeping "..waitTime.." seconds")
- sleepDots(waitTime)
- else
- print("Refueled...")
- end
- end
- ss(currentSlotSelected)
- end
- local function debugPrint(str1,str2,str3,str4)
- if blnDebugPrint then
- if str1==nil then str1="" end term.write(str1)
- if str2==nil then str2="" end term.write(str2)
- if str3==nil then str3="" end term.write(str3)
- if str4==nil then str4="" end print(str4)
- end
- end
- local function inspectFor(blockArray, strDirection)
- if strDirection==nil then strDirection="f" end
- local blnOk, data
- -- inspect
- if strDirection=="d" then blnOk, data = turtle.inspectDown()
- elseif strDirection=="u" then blnOk, data = turtle.inspectUp()
- elseif strDirection=="f" then blnOk, data = turtle.inspect()
- else
- print("Warning: Unknown direction '",strDirection,"' in inspectFor, taking (f)orward instead.")
- strDirection="f"
- blnOk, data = turtle.inspect()
- end
- if data.name~=nil then debugPrint("Found:"..string.lower(data.name)) end
- -- compare
- local i=1
- while blockArray[i]~=nil do
- debugPrint("Compare to:"..string.lower(blockArray[i]))
- if data.name~=nil then
- if string.lower(data.name) == string.lower(blockArray[i]) then return true end
- end
- i=i+1
- end
- return false -- reached a nil value
- end
- local function prepareStartup()
- -- step 1: startup program for disk/startup
- fs.delete("disk/startup")
- file = fs.open("disk/startup","w")
- file.write(
- [[
- -- copy prg. to computer as startup
- fs.delete("startup")
- fs.copy("disk/aDroneFire","startup")
- fs.delete("disk/startup")
- print("reboot in 10 seconds") sleep(10)
- os.reboot()
- ]]
- )
- file.close()
- -- step 2: program to be installed as startup on computer
- fs.delete("disk/aDroneFire")
- file = fs.open("disk/aDroneFire","w")
- file.write([[
- ---------------------------------------
- -- bDrone_listener by Kaikaku
- -- 2021-03-13, v1.00 initial
- ---------------------------------------
- ---------------------------------------
- ---- DESCRIPTION ----------------------
- ---------------------------------------
- -- This program is installed by bDrone
- -- to enable the computer on a RFD
- -- to receive fire commands
- shell.run("label set RapidFireDrone")
- term.clear() term.setCursorPos(1,1)
- print("Rapid Fire Drone: Listener active")
- local numShots = 10
- local tArgs = {...}
- if #tArgs >= 1 then -- no error check
- if tonumber(tArgs[1])~=nil then
- numShots=tonumber(tArgs[1])
- end
- end
- local function setRedstone(blnValue)
- rs.setOutput("bottom",blnValue)
- rs.setOutput("left",blnValue)
- rs.setOutput("right",blnValue)
- rs.setOutput("back",blnValue)
- rs.setOutput("front",blnValue)
- end
- local function shoot(number)
- if number==nil then number = 1 elseif number <1 then number = 1 end
- for i=1,number do
- setRedstone(true)
- os.sleep(0.1)
- setRedstone(false)
- os.sleep(0.1)
- end
- end
- -- MAIN
- local modem = peripheral.wrap("top")
- modem.open(1234)
- local a,b,c,d,e,f
- while true do
- while true do
- a,b,c,d,e,f = os.pullEvent("modem_message")
- --if a~=nil then print("a:",a) end
- --if b~=nil then print("b:",b) end
- --if c~=nil then print("c:",c) end
- --if d~=nil then print("d:",d) end
- --if e~=nil then print("e:",e) end
- --if f~=nil then print("f:",f) end
- if c==1234 and e=="abcefd_fire" then numShots=d print("Fire "..d.." times! ") break end
- end
- shoot(numShots)
- end
- ]])
- end
- ------------------------------------------------------------------------------
- -- main: description ---------------------------------------------------------
- ------------------------------------------------------------------------------
- checkTurtle()
- if blnAskForParameters then
- term.clear() term.setCursorPos(1,1)
- local iPage=0
- local iPageMax=2
- local event, key, isHeld
- local blnLoop=true
- term.clear() term.setCursorPos(1,1) iPage=iPage+1
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
- printUI("line")
- -- 1234567890123456789012345678901234567
- printUI("This program builds and operates a ")
- printUI(" prank drone. Select mode:")
- printUI(" ")
- printUI(" 1 = build regular drone")
- printUI(" 2 = build rapid fire drone")
- printUI(" 3 = refill drone")
- printUI(" 4 = fire rapid fire drone")
- printUI(" ")
- printUI("footer")
- term.write("Press key 1,2,3,4 to select mode")
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("Select mode",17,5,colors.red)
- coloredTextAt("1",4,7,colors.red)
- coloredTextAt("2",4,8,colors.red)
- coloredTextAt("3",4,9,colors.red)
- coloredTextAt("4",4,10,colors.red)
- while blnLoop do -- option selection example --<< put in template
- event, key, isHeld = os.pullEvent("key")
- if key~=nil then
- if keys.getName(key)=="one" or keys.getName(key)=="two" or keys.getName(key)=="three" or keys.getName(key)=="four" then
- blnLoop=false
- end
- end
- end
- if keys.getName(key)=="one" then
- term.clear() term.setCursorPos(1,1) iPage=iPage+1
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
- printUI("line")
- -- 1234567890123456789012345678901234567
- printUI("Build drone, inventory set-up:")
- printUI(" sl.1: 1+ dispenser/dropper")
- printUI(" sl.2: 1+ daylight detector")
- printUI(" sl.3: 4+ iron trapdoors (opt.)")
- printUI(" sl.4: 4+ carpets (optional)")
- printUI(" sl.5-13: junk items the drone")
- printUI(" will drop/dispens every morning.")
- printUI(" Slots 6-12 are optional.")
- printUI("footer")
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("Build drone",2,4,nil,colors.red)
- coloredTextAt("1",10,5,colors.red) coloredTextAt("dispenser/dropper",13,5,colors.red)
- coloredTextAt("1",10,6,colors.red) coloredTextAt("daylight detector",13,6,colors.red)
- coloredTextAt("junk items",13,9,colors.red)
- pressKeyNoSpecials("Press key to START! (stop w/ ctrl+t) ")
- end
- if keys.getName(key)=="two" then
- term.clear() term.setCursorPos(1,1) iPage=iPage+1
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
- printUI("line")
- -- 1234567890123456789012345678901234567
- printUI("Build rapid fire drone, inventory:")
- printUI(" sl.1: 5+ dispensers/droppers")
- printUI(" sl.2: 1 computer")
- printUI(" sl.3: 4+ iron trapdoors (opt.)")
- printUI(" sl.4: 4+ carpets (optional)")
- printUI(" sl.5-13: arrows/junk items")
- printUI(" sl.14: 1 wireless/ender modem")
- printUI(" sl.15: 1 disk drive | sl.16: 1 disk")
- printUI("footer")
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("Build rapid fire drone",2,4,nil,colors.red)
- coloredTextAt("5",10,5,colors.red) coloredTextAt("dispensers",13,5,colors.red)
- coloredTextAt("1",10,6,colors.red) coloredTextAt("computer",13,6,colors.red)
- coloredTextAt("arrows",13,9,colors.red)
- coloredTextAt("1",11,10,colors.red) coloredTextAt("modem",28,10,colors.red)
- coloredTextAt("1",11,11,colors.red) coloredTextAt("disk drive",13,11,colors.red)
- coloredTextAt("1",33,11,colors.red) coloredTextAt("disk",35,11,colors.red)
- pressKeyNoSpecials("Press key to START! (stop w/ ctrl+t) ")
- blnRFD=true
- end
- if keys.getName(key)=="three" then
- term.clear() term.setCursorPos(1,1) iPage=iPage+1
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
- printUI("line")
- -- 1234567890123456789012345678901234567
- printUI("Refill existing drone, inventory:")
- printUI("A) Fill turtle with items to")
- printUI(" be put in drone (junk/arrows)")
- printUI("B) And/or put chest with items ")
- printUI(" in front of turtle")
- printUI("Info: For rapid fire drones you may")
- printUI(" use up to 3 turtles for quicker")
- printUI(" refill (give head start).")
- printUI("footer")
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("Refill",2,4,nil,colors.red)
- coloredTextAt("A)",2,5,colors.red)
- coloredTextAt("B)",2,7,colors.red)
- pressKeyNoSpecials("Press key to START! (stop w/ ctrl+t) ")
- blnRefill=true
- end
- if keys.getName(key)=="four" then
- term.clear() term.setCursorPos(1,1) iPage=iPage+1
- printUI("header")
- printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
- printUI("line")
- -- 1234567890123456789012345678901234567
- printUI("Fire rapid fire drone:")
- printUI(" ")
- printUI("Enter number (1-576) of redstone")
- printUI(" pulses. Eachs pulse will dispense")
- printUI(" 5 items (e.g., shot 5 arrows).")
- printUI(" ")
- printUI("If drone runs dry use refill option.")
- printUI(" ")
- printUI("footer")
- term.write("Key in number and press Enter: ") -- required to catch option number from 1st screen
- coloredTextAt(cPrgName,2,2,colors.red)
- coloredTextAt("Fire",2,4,nil,colors.red)
- coloredTextAt("Enter number",2,6,colors.red)
- event, key, isHeld = os.pullEvent("key")
- amountFire=askForNumber("Key in number and press Enter: ",1,576)
- blnFire=true
- end
- end
- local function getFirstEmptySlot(startAt) -- <<-- put in template
- if startAt==nil then startAt=1 end
- if startAt>16 or startAt<1 then return nil end
- for i=startAt,16,1 do
- if gic(i)==0 then return i end
- end
- for i=1,startAt,1 do
- if gic(i)==0 then return i end
- end
- return nil
- end
- local function identifyTool(toolSide) -- <<-- add to template
- -- returns name of tool at side toolSide
- -- returns no_tool if there is none
- -- requires at least one empty slot for tool check (throws error)
- if toolSide==nil then toolSide="right" end
- if toolSide~="right" and toolSide~="r" then toolSide="left" end
- local slotNumber = getFirstEmptySlot()
- local slotSelected=turtle.getSelectedSlot()
- local toolName="no_tool"
- if slotNumber==nil then error("Couldn't find empty slot to check tool on side '"..toolSide.."'!") end
- ss(slotNumber)
- -- step 1: get name
- if toolSide=="right" or toolSide=="r" then
- turtle.equipRight()
- else
- turtle.equipLeft()
- end
- -- step 2: get name
- local data = turtle.getItemDetail()
- if data~=nil then toolName=data.name end
- -- step 3: re-equipget name
- if toolSide=="right" or toolSide=="r" then
- turtle.equipRight()
- else
- turtle.equipLeft()
- end
- ss(slotSelected)
- return toolName
- end
- local function findModem() -- delete if no modem useage <<-- add to template
- for _, p in pairs( rs.getSides() ) do
- if peripheral.isPresent(p) and peripheral.getType(p) == "modem" then return true,p end
- end
- return false,nil
- end
- local function ensureModem() -- delete if no modem useage <<-- add to template
- -- Equips modem from slotFuel either right or left, depending which solt is free.
- -- Throws an error if both sides are already taken.
- -- Return modem side
- local modemExists, modemSide = findModem()
- if isComputer then
- while not modemExists do
- print("No modem found, attach a modem to computer!")
- sleepDots(3)
- modemExists, modemSide = findModem()
- end
- else -- isTurtle
- local slotSelected=turtle.getSelectedSlot()
- while not modemExists do
- ss(slotFuel)
- print("Turtle has no modem, put one wireless modem in slot "..slotFuel.."!")
- sleepDots(3)
- if gic()== 1 then
- -- check right side
- if identifyTool("right")=="no_tool" then
- turtle.equipRight()
- elseif identifyTool("left")=="no_tool" then
- turtle.equipLeft()
- else
- error("Could find empty tool slot to equip modem! Please, manually remove one tool. E.g., in lua editor with 'turtle.equipLeft()'")
- end
- end
- modemExists, modemSide = findModem()
- end
- ss(slotSelected)
- end
- return modemSide
- end
- ------------------------------------------------------------------------------
- -- main: pre-main options ----------------------------------------------------
- ------------------------------------------------------------------------------
- if blnFire then
- term.clear() term.setCursorPos(1,1)
- local modem = peripheral.wrap(ensureModem())
- modem.transmit(1234,amountFire,"abcefd_fire")
- print("Fire ("..amountFire..") command sent! :)")
- return
- end
- ------------------------------------------------------------------------------
- -- main: program -------------------------------------------------------------
- ------------------------------------------------------------------------------
- term.clear() term.setCursorPos(1,1)
- ---- step 0: check starting stuff ----
- print("step 0: checking inventory...")
- if not blnRefill then
- if not blnRFD then
- -- normal drone inventory
- checkInventory(slotDropper, 1,nil,"Put 1+ dispenser/dropper in slot "..slotDropper.."!", true, true)
- checkInventory(slotSensor, 1,nil,"Put 1+ daylight detector in slot "..slotSensor.."!", true, true)
- checkInventory(slotTrapdoor, 4,nil,"Option: Put 4+ trapdoorse in slot "..slotTrapdoor.."!", false)
- checkInventory(slotCarpet, 4,nil,"Option: Put 4+ carpets in slot "..slotCarpet.."!", false)
- checkInventory(slotJunkStart, 1,nil,"Put some items to be dropped in slot "..slotJunkStart.."!", true, true)
- sleep(1)
- else
- -- RFD inventory
- checkInventory(slotDropper, 5,nil,"Put 5+ dispenser/dropper in slot "..slotDropper.."!", true, true)
- checkInventory(slotSensor, 1, 1,"Put 1+ computer in slot "..slotSensor.."!", true, true)
- checkInventory(slotTrapdoor, 4,nil,"Option: Put 4+ trapdoorse in slot "..slotTrapdoor.."!", false)
- checkInventory(slotCarpet, 4,nil,"Option: Put 4+ carpets in slot "..slotCarpet.."!", false)
- checkInventory(slotJunkStart, 1,nil,"Put some items to be dropped in slot "..slotJunkStart.."!", true, true)
- checkInventory(slotModem, 1, 1,"Put 1 wireless/ender modem in slot "..slotModem.."!", true, true)
- checkInventory(slotDiskDrive, 1, 1,"Put 1 disk drive in slot "..slotDiskDrive.."!", true, true)
- checkInventory(slotDisk, 1, 1,"Put 1 floppy disk in slot "..slotDisk.."!", true, true)
- sleep(1)
- end
- else
- blnLoop=true
- while blnLoop do
- for i=1,16 do sf() end
- blnLoop=true
- for i=1,16 do
- if gic(i)>0 then blnLoop=false break end
- end
- if blnLoops then
- print("Put some items into turtle or chest in front of it!")
- sleepDots(5)
- end
- end
- end
- -- fuel
- refuelManager(cMinFuel,slotFuel,10)
- -- recheck floppy disk?
- if blnRFD then checkInventory(slotDisk, 1, 1,"Put 1 floppy disk back in slot "..slotDisk.."!", true, true) end
- ---- step 1: go up ----
- term.clear() term.setCursorPos(1,1) -- clean up in case of warnings
- print("step 0: checking inventory...")
- print("... done")
- print("step 1: go up...")
- upSteps=0
- while turtle.up() do
- upSteps=upSteps+1
- term.setCursorPos(19, 3)
- term.write("moved up "..upSteps.." blocks")
- if cMaxTurns>0 and upSteps>=cMaxTurns then break end
- end
- term.setCursorPos(19, 3)
- print()
- print("... done")
- ---- step 2: check build space ----
- local blnBlocked=false
- local blnFirstBlocked=false
- term.write("step 2: check build space...")
- if not blnRefill then
- repeat
- blnBlocked=false
- blnFirstBlocked=false
- for i=1,2 do
- -- RFD?
- if blnRFD then
- if not blnBlocked then
- gl() if not gfr() then blnBlocked=true gr() end
- end
- if not blnBlocked and turtle.inspectDown() then
- blnBlocked=true gb() gr()
- else
- if not blnBlocked then gb() gr() end
- end
- end
- -- fd
- if not blnBlocked and not gfr() then blnBlocked=true end
- -- left fd
- if not blnBlocked then
- gl()
- if not gfr() then blnBlocked=true gr() gb() end
- if not blnBlocked and turtle.inspectDown() then blnBlocked=true gb() gr() gb() end
- end
- -- right fd
- if not blnBlocked then
- gb()
- if not gbr() then blnBlocked=true gr() gb() end
- if not blnBlocked and turtle.inspectDown() then blnBlocked=true gf() gr() gb() end
- end
- -- return after one half
- if not blnBlocked then
- gf() gl() gf()
- end
- -- original orientation
- if i==1 and blnBlocked then blnFirstBlocked=true end
- if i==2 then
- if not blnFirstBlocked and blnBlocked then gl(2) end
- --if blnFirstBlocked then gl(2) end
- end
- debugPrint("i="..i.."|blnFirstBlocked=",blnFirstBlocked,"|blnBlocked=",blnBlocked)
- end
- if blnBlocked then
- print("Layer blocked, try 2 deeper...")
- if upSteps<4 then
- gd(upSteps)
- error("Couldn't find place to build the drone :(")
- end
- gd(2) upSteps=upSteps-2
- else
- print(" done")
- end
- until not blnBlocked
- else
- print(" no")
- end
- ---- step 3: build drone ----
- term.write("step 3: build drone...")
- if not blnRefill then
- -- assumption: T's at build limit, at center w/ original orientation
- -- step 3.1 build trap doors and carpets
- for i=1,2 do
- if blnRFD then gl() gf() ss(slotDropper) pd() gb() gr() end
- gf()
- if blnRFD and i~=2 then pd() end
- gl() gf() ss(slotTrapdoor) pd() gb(2) pd() gf() ss(slotCarpet) pf() gr(2) pf() gr() gf()
- end
- -- step 3.2 build core
- if not blnRFD then
- gd() ss(slotSensor) pu() gd() ss(slotDropper) pu()
- upSteps=upSteps-2
- else
- ss(slotSensor) pd() gb() ss(slotModem) pf()
- gd(2) ss(slotDiskDrive) pf() ss(slotDisk) Df()
- prepareStartup()
- gu() peripheral.call("front","turnOn")
- gu() ss(slotDropper) pd() gb() gd(2) gf()
- ss(slotDisk) sf() ss(slotDiskDrive) df()
- gd() gf() ss(slotDropper) pu()
- upSteps=upSteps-3
- end
- print(" done")
- else
- print(" no")
- end
- ---- step 4: fill up with junk ----
- term.write("step 4: fill up with junk...")
- if not blnRefill then
- for i=slotJunkStart,slotJunkEnd do
- if gic(i)>0 then ss(i) Du(64) end
- end
- print(" inital fill done")
- else
- -- basic dropper/dispenser
- for i=1,16 do if gic(i)>0 then ss(i) Du(64) end end
- -- other droppers/dispensers
- gf() gu() gr()
- for iDropper=1,4 do
- if inspectFor(blockDropper,"u") then
- for i=1,16 do
- if gic(i)>0 then
- ss(i) Du(64)
- end
- end
- else
- print("No Dropper/Dispensor here to refill.")
- end
- gf() gr() gf()
- end
- gl()
- print(" done")
- end
- ---- step 5: return, finishing stuff / report ----
- term.write("step 5: return...")
- gd(upSteps)
- if blnRefill then gb() gd() end
- print(" done")
- print("Prank prepared !") ss(1)
- sleep(0.4)
- print("***************************************")
- print("* Check out YouTube for more videos *")
- print("* and turtle programs by Kaikaku :) *")
- print("***************************************")
Add Comment
Please, Sign In to add comment