DrFair

Enchant Turtle

Mar 9th, 2013
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. xp = peripheral.wrap("left")
  2. anvil = peripheral.wrap("right")
  3. xp.setAutoCollect(true)
  4. term.clear()
  5. w,h = term.getSize()
  6. elvl = 30
  7. turtle.select(1)
  8.  
  9. function swrite(str,x,y)
  10. term.setCursorPos(x,y)
  11. term.write(str)
  12. end
  13.  
  14. function swritecenter(str,y)
  15. term.setCursorPos(w/2 - #str/2,y)
  16. term.write(str)
  17. end
  18.  
  19. function cline(y)
  20. term.setCursorPos(1,y)
  21. term.clearLine()
  22. end
  23.  
  24. function drawUI()
  25. swritecenter("Welcome to Fair's XP Turtle.",1)
  26. swrite("How to use enchant/repair:",2,3)
  27. swrite("1. Place item(s) in slot 1/2.",2,4)
  28. swrite("2. Use Arrowkeys to change level.",2,5)
  29. swrite("3. Press ENTER to enchant/repair.",2,6)
  30. swrite("NOTE: Exit, enter turtle to update.",2,13)
  31. end
  32.  
  33. function updateLVL()
  34. swrite("Current stored levels: "..xp.getLevels().." ",2,8)
  35. end
  36.  
  37. function updateSEL()
  38. cline(9)
  39. swrite("Selected enchant level: "..elvl,2,9)
  40. end
  41.  
  42. function updateREP(str)
  43. cline(9)
  44. swrite("Items repair level cost: "..str,2,9)
  45. end
  46.  
  47. function update(str)
  48. swrite("Last status:",2,10)
  49. term.setCursorPos(1,11)
  50. term.clearLine()
  51. swrite(str,2,11)
  52. end
  53.  
  54. drawUI()
  55. updateLVL()
  56. updateSEL()
  57. updateREP("N/A")
  58. update("Startup complete.")
  59.  
  60. while true do
  61. event,key = os.pullEvent()
  62. if turtle.getItemCount(2) == 0 then
  63. updateSEL()
  64. else
  65. if anvil.getRepairCost(1,2) > 0 then
  66. updateREP(tostring(anvil.getRepairCost(1,2)))
  67. else
  68. updateREP("N/A")
  69. end
  70. end
  71. if event == "key" then
  72. if key == 28 then
  73. if turtle.getItemCount(2) == 0 then
  74. if elvl <= xp.getLevels() then
  75. if xp.enchant(elvl) then
  76. update("Success enchant of "..elvl.." levels.")
  77. else
  78. update("Something went wrong in enchant.")
  79. end
  80. else
  81. update("Turtle level not high enough.")
  82. end
  83. else
  84. if anvil.getRepairCost(1,2) <= xp.getLevels() then
  85. if anvil.repair(1,2) then
  86. update("Success repair of items.")
  87. else
  88. update("Something went wrong in repair.")
  89. end
  90. else
  91. update("Turtle level not high enough.")
  92. end
  93. end
  94. elseif key == 200 or key == 205 then
  95. if elvl < 30 then
  96. elvl = elvl + 1
  97. updateSEL()
  98. end
  99. elseif key == 208 or key == 203 then
  100. if elvl > 1 then
  101. elvl = elvl - 1
  102. updateSEL()
  103. end
  104. end
  105. end
  106. updateLVL()
  107. os.sleep(0.1)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment