Advertisement
neonerz

enchanter

Mar 25th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. --
  2. --Killing Floor XP Turtle Enchater by neonerZ v1.0
  3. --http://youtube.com/neonerz
  4. --
  5.  
  6. xp = peripheral.wrap("left")
  7. rednet.open("right")
  8. xp.setAutoCollect(false)
  9. currentLevel = 0
  10.  
  11. --Rednet sendMessage function, ID = computer ID
  12. function sendMessage(id,name,mode,message)
  13.     message = {name=name,mode=mode,message=message}
  14.     sMessage = textutils.serialize(message)
  15.     rednet.send(id, sMessage)
  16. end
  17.  
  18. print("Starting up")
  19. sendMessage(254,"enchanter01","info","Starting up")
  20. sleep(5)
  21.  
  22. while true do
  23.     print("Waiting for 30 levels")
  24.     sendMessage(254,"enchanter01","info","Collecting levels")
  25.     xp.collect()
  26.     --if less than 30 levels, wait for more
  27.     while xp.getLevels() < 30 do
  28.         xp.collect()
  29.             if xp.getLevels() > currentLevel then
  30.                 currentLevel = xp.getLevels()
  31.                 sendMessage(254,"enchanter01","level",currentLevel)
  32.                 print("Current Level: "..currentLevel)
  33.             end
  34.         sleep(.1)
  35.     end
  36.  
  37.     print("30 Levels obtained, enchanting book")
  38.     sendMessage(254,"enchanter01","info","Enchanting book")
  39.    
  40.     --When levels are greater than or equal to 30 start enchanting
  41.     if xp.getLevels() >= 30 then
  42.         turtle.select(1)
  43.         turtle.transferTo(16, 1)
  44.         turtle.select(16)
  45.         --Tries to enchant book, if works, move on, if not display error
  46.         if pcall(xp.enchant, 30) then
  47.             turtle.drop(1)
  48.             sleep(.1)
  49.             turtle.select(1)
  50.             redstone.setOutput("bottom", true)
  51.             sleep(.5)
  52.             redstone.setOutput("bottom", false)
  53.             print("Book enchanted and on it's way")
  54.             sendMessage(254,"enchanter01","info","Book en route")
  55.             sleep(1)
  56.             currentLevel=0
  57.         else
  58.             print("ERROR: Could not enchant book")
  59.             sendMessage(254,"enchanter01","info","No books?")
  60.             sleep(.1)
  61.             sendMessage(254,"enchanter01","error","Enchant failed.")
  62.             sleep(30)
  63.         end
  64.     end
  65. end
  66.  
  67.     sendMessage(254,"enchanter01","info","Shutting down")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement