Advertisement
VADemon

Turtle mob killer and enchanter v1.12

May 11th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.05 KB | None | 0 0
  1. local enchantWithLevel = 30
  2. local chestDir = "dropDown"
  3. local enchantChestSuck = "suckUp"
  4. local enchantChestDrop = "dropUp"
  5.  
  6.  
  7. m = peripheral.wrap("right")
  8. m.setAutoCollect(true)
  9. local work = true
  10.  
  11. function drop_all_items()
  12.     for i = 1, 16 do
  13.         if turtle.getItemCount(i)~=0 then
  14.             turtle.select(i)
  15.             turtle[chestDir]()
  16.         end
  17.     end
  18.    
  19.     turtle.select(1)
  20. end
  21.  
  22. function getFirstEmptySlot()
  23.     for i = 1, 16 do
  24.         if turtle.getItemCount(i)==0 then
  25.             return i
  26.         end
  27.     end
  28.     print("[SEVERE] Turtle was full!")
  29.     drop_all_items() --drop all items if the turtle is full
  30. end
  31.  
  32. function validEnchantLevel(x)
  33.     if x>=1 and x<=30 then
  34.         print("Yes")
  35.         return true
  36.     end
  37.     print("No")
  38.     return false
  39. end
  40.  
  41. function enchant(lvl)
  42.     if m.getLevels()>=lvl then
  43.         if turtle.suckUp() then
  44.             turtle.select(getFirstEmptySlot()-1)
  45.             print(getFirstEmptySlot())
  46.             turtle.dropUp(turtle.getItemCount(getFirstEmptySlot()-1)-1)
  47.             if m.enchant(lvl) then
  48.                 print("Successfully enchanted an item from chest!")
  49.             else
  50.                 print("Failed to enchant an item from chest!")
  51.             end
  52.            
  53.             turtle.dropUp()
  54.             turtle.select(1)
  55.             return true
  56.         else
  57.             print("No item in the enchantment chest!")
  58.         end
  59.     end
  60.     return false
  61. end
  62.  
  63. function killndrop()
  64.     local count = 0
  65.     while os.pullEvent("start") do
  66.         while work do
  67.             if turtle.attack() then
  68.                 count = count + 1
  69.                 if count>=50 then
  70.                     drop_all_items()
  71.                     enchant(enchantWithLevel)
  72.                     count = 0
  73.                 end
  74.                 sleep(.25)
  75.             else
  76.                 sleep(.5)
  77.             end
  78.         end
  79.         print("Stopped killing these bitches :(")
  80.     end
  81. end
  82.  
  83. function keyInput()
  84. sleep(.1); os.queueEvent("start")
  85. local enchantWithLevel = enchantWithLevel
  86.     while true do
  87.         local event, char = os.pullEvent("char")
  88.         if char == "s" then
  89.             print("Stopping!")
  90.             work = false
  91.             sleep(2)
  92.             break
  93.         elseif char == "d" then
  94.             print("Dropping items...")
  95.             count = 0
  96.             drop_all_items()
  97.             count = 0
  98.         elseif char == "n" then
  99.             if m.getLevels()>=1 then
  100.                 print("Enchanting an item...")
  101.                 work = false
  102.                 sleep(1)
  103.                 print("\nChoose level to enchant with:")
  104.                 print("Use arrows on your keyboard to select")
  105.                 print("[DOWN]   -1 level | +1 level   [UP]")
  106.                 print("<-   -5 levels | +5 levels   ->")
  107.                 print("Press ENTER to enchant with chosen level")
  108.                 print("Current level: ".. tostring(m.getLevels()).." | Level chosen: "..tostring(enchantWithLevel))
  109.                
  110.                 local runIt
  111.                 while true do --do until the loop will break
  112.                     local event, key = os.pullEvent("key")
  113.                     if key == 28 then --Enter
  114.                         if validEnchantLevel(enchantWithLevel) then
  115.                             if m.getLevels()>=enchantWithLevel then
  116.                                 if m.enchant(enchantWithLevel) then
  117.                                     print("Sucessfully enchanted!")
  118.                                     break
  119.                                 elseif enchant(enchantWithLevel) then
  120.                                     print("Sucessfully enchanted!")
  121.                                     break
  122.                                 else
  123.                                     print("Couldn't find an item to enchant!")
  124.                                     print("Put it into the right chest or currently selected slot!")
  125.                                 end
  126.                             else
  127.                                 print("You don't have enough levels to enchant: \""..tostring(m.getLevels()).."\"")
  128.                             end
  129.                         end
  130.                         print("Press ESCAPE to exit the enchanting menu")
  131.                     elseif key == 200 then -- Arrow up
  132.                         if validEnchantLevel(enchantWithLevel + 1) then
  133.                             enchantWithLevel = enchantWithLevel + 1
  134.                             print("Currently selected level: "..enchantWithLevel)
  135.                         else
  136.                             print("Invalid enchantment level: "..(enchantWithLevel + 1))
  137.                         end
  138.                     elseif key == 208 then -- Arrow down
  139.                         if validEnchantLevel(enchantWithLevel - 1) then
  140.                             enchantWithLevel = enchantWithLevel - 1
  141.                             print("Currently selected level: "..enchantWithLevel)
  142.                         else
  143.                             print("Invalid enchantment level: "..(enchantWithLevel - 1))
  144.                         end
  145.                     elseif key == 203 then -- Arrow left
  146.                         if validEnchantLevel(enchantWithLevel - 5) then
  147.                             enchantWithLevel = enchantWithLevel - 5
  148.                             print("Currently selected level: "..enchantWithLevel)
  149.                         else
  150.                             print("Invalid enchantment level: "..(enchantWithLevel - 5))
  151.                         end
  152.                     elseif key == 205 then -- Arrow right
  153.                         if validEnchantLevel(enchantWithLevel) then
  154.                             enchantWithLevel = enchantWithLevel + 5
  155.                             print("Currently selected level: "..enchantWithLevel)
  156.                         else
  157.                             print("Invalid enchantment level: "..(enchantWithLevel + 5))
  158.                         end
  159.                     elseif key==1 or key==18 then -- ESCAPE
  160.                         print("Continuing...")
  161.                         break
  162.                     else
  163.                         print("You pressed the wrong key!")
  164.                     end
  165.                 end
  166.             else
  167.                 print("You don't have enough levels to enchant something!")
  168.             end
  169.             print("Continuing...")
  170.             work = true --return the state to "true" if it was set to false temporarily
  171.             os.queueEvent("start")
  172.         end
  173.     end
  174. end
  175.  
  176. if not validEnchantLevel(enchantWithLevel) then
  177.     print("You selected an invalid enchant level: \""..tostring(enchantWithLevel).."\"\nStopping...")
  178.     sleep(5)
  179.     error()
  180. end
  181.  
  182. print("Keys:")
  183. print("D - Urgently drop items")
  184. print("N - Enchant an item")
  185. print("S - Stop the turtle and exit")
  186.  
  187.  
  188. parallel.waitForAny(keyInput, killndrop)
  189.  
  190. --by VADemon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement