Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --how to use:
- --Place a melee turtle (facing the block where the mobs will be)
- --Place a pressure plate in front of turtle, so the falling mobs activate it
- -- ENJOY THE SHOW
- local chestDir = "dropUp"
- local redstoneSignalSide = "none"
- local per = peripheral.wrap("right")
- local count = 0
- --get redstoneSignalSide for further using // HEAVY OPTIMIZATION
- while redstoneSignalSide=="none" do --wait for a correct redstone signal
- print("Waiting for a redstone signal...")
- os.pullEvent("redstone")
- if rs.getInput("top") then
- redstoneSignalSide = "top"
- elseif rs.getInput("front") then
- redstoneSignalSide = "front"
- elseif rs.getInput("left") then
- redstoneSignalSide = "left"
- elseif rs.getInput("right") then
- redstoneSignalSide = "right"
- elseif rs.getInput("back") then
- redstoneSignalSide = "back"
- elseif rs.getInput("bottom") then
- redstoneSignalSide = "bottom"
- else
- print("idk didnt find the redstone signal")
- end
- print("Redstone signal is coming from: ".. redstoneSignalSide)
- end
- function drop_all_items()
- for i = 1, 16 do
- if turtle.getItemCount(i)~=0 then
- turtle.select(i)
- turtle[chestDir]()
- end
- end
- turtle.select(1)
- end
- function attackWhileRedstone()
- while rs.getInput(redstoneSignalSide)==true do --check if mob (rs=TRUE) is in front
- if turtle.attack() then
- count = count + 1
- if count>=50 then
- drop_all_items()
- count = 0
- end
- sleep(.15)
- end
- end
- end
- function killndrop()
- while os.pullEvent("redstone") do --when redstone signal changes
- --print("Redstone event")
- attackWhileRedstone()
- sleep(.75)
- attackWhileRedstone()
- --print("Input = false")
- end
- end
- function keyInput()
- while true do
- local event, char = os.pullEvent("char")
- if char == "s" then
- print("Stopping!")
- break
- elseif char == "d" then
- print("Dropping items!")
- count = 0
- drop_all_items()
- count = 0
- end
- end
- end
- function sleepEvent()
- sleep(1); os.queueEvent("redstone") --activates the turtle after getting a redstone signal
- while true do
- sleep(10)
- os.queueEvent("redstone")
- end
- end
- print("Keys:")
- print("S - Stop the turtle and exit")
- print("D - Drop items urgently")
- parallel.waitForAny(keyInput, killndrop, sleepEvent)
- --by VADemon
- --[[Changelog
- v2.06
- Removed debug messages
- v2.05
- Code completely stable, needs some refactoring though
- v2.02:
- Turtle attacking only on redstone event
- v2.01:
- Bug fixed, turtle didn't wait for redstone event to track the side of signal
- v2.0:
- Rewrite of code
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement