Advertisement
VADemon

Turtle (mob spawner) killer v2.06

May 11th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. --how to use:
  2. --Place a melee turtle (facing the block where the mobs will be)
  3. --Place a pressure plate in front of turtle, so the falling mobs activate it
  4. -- ENJOY THE SHOW
  5.  
  6. local chestDir = "dropUp"
  7.  
  8. local redstoneSignalSide = "none"
  9. local per = peripheral.wrap("right")
  10. local count = 0
  11.  
  12. --get redstoneSignalSide for further using // HEAVY OPTIMIZATION
  13. while redstoneSignalSide=="none" do --wait for a correct redstone signal
  14.     print("Waiting for a redstone signal...")
  15.     os.pullEvent("redstone")
  16.     if rs.getInput("top") then
  17.         redstoneSignalSide = "top"
  18.     elseif rs.getInput("front") then
  19.         redstoneSignalSide = "front"
  20.     elseif rs.getInput("left") then
  21.         redstoneSignalSide = "left"
  22.     elseif rs.getInput("right") then
  23.         redstoneSignalSide = "right"
  24.     elseif rs.getInput("back") then
  25.         redstoneSignalSide = "back"
  26.     elseif rs.getInput("bottom") then
  27.         redstoneSignalSide = "bottom"
  28.     else
  29.         print("idk didnt find the redstone signal")
  30.     end
  31.     print("Redstone signal is coming from: ".. redstoneSignalSide)
  32. end
  33.    
  34. function drop_all_items()
  35.     for i = 1, 16 do
  36.         if turtle.getItemCount(i)~=0 then
  37.             turtle.select(i)
  38.             turtle[chestDir]()
  39.         end
  40.     end
  41.    
  42.     turtle.select(1)
  43. end
  44.  
  45. function attackWhileRedstone()
  46.     while rs.getInput(redstoneSignalSide)==true do --check if mob (rs=TRUE) is in front
  47.         if turtle.attack() then
  48.             count = count + 1
  49.             if count>=50 then
  50.                 drop_all_items()
  51.                 count = 0
  52.             end
  53.             sleep(.15)
  54.         end
  55.     end
  56. end
  57.  
  58. function killndrop()
  59.         while os.pullEvent("redstone") do --when redstone signal changes
  60.             --print("Redstone event")
  61.             attackWhileRedstone()
  62.             sleep(.75)
  63.             attackWhileRedstone()
  64.             --print("Input = false")
  65.         end
  66. end
  67.  
  68. function keyInput()
  69.     while true do
  70.         local event, char = os.pullEvent("char")
  71.         if char == "s" then
  72.             print("Stopping!")
  73.             break
  74.         elseif char == "d" then
  75.             print("Dropping items!")
  76.             count = 0
  77.             drop_all_items()
  78.             count = 0
  79.         end
  80.     end
  81. end
  82.  
  83. function sleepEvent()
  84.     sleep(1); os.queueEvent("redstone") --activates the turtle after getting a redstone signal
  85.     while true do
  86.         sleep(10)
  87.         os.queueEvent("redstone")
  88.     end
  89. end
  90.  
  91.  
  92. print("Keys:")
  93. print("S - Stop the turtle and exit")
  94. print("D - Drop items urgently")
  95. parallel.waitForAny(keyInput, killndrop, sleepEvent)
  96.  
  97. --by VADemon
  98. --[[Changelog
  99. v2.06
  100. Removed debug messages
  101. v2.05
  102. Code completely stable, needs some refactoring though
  103. v2.02:
  104. Turtle attacking only on redstone event
  105. v2.01:
  106. Bug fixed, turtle didn't wait for redstone event to track the side of signal
  107. v2.0:
  108. Rewrite of code
  109. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement