Advertisement
Guest User

startup

a guest
Jun 5th, 2013
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. anvil = peripheral.wrap("right")
  2. xp = peripheral.wrap("left")
  3. m=peripheral.wrap("top")
  4. xp.setAutoCollect(true)
  5. if fs.exists("totalserved") then
  6. h=fs.open("totalserved", "r")
  7. total = h.readLine()
  8. h.close()
  9. total= math.abs(total)
  10. else total = 0
  11. end
  12.  
  13. function save()
  14. h= fs.open("totalserved", "w")
  15. h.write(total)
  16. h.close()
  17. end
  18.  
  19. function clear()
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. end
  23.  
  24. function clearmon()
  25. m.clear()
  26. m.setCursorPos(1,1)
  27. end
  28.  
  29. local cPrint = function (text)
  30. local x2, y2 = term.getCursorPos()
  31. local x,y = term.getSize()
  32. term.setCursorPos(math.ceil((x/2) - (text:len() / 2)), y2)
  33. print(text)
  34. end
  35.  
  36. local cPrintMon = function (text)
  37. local x2, y2 =m.getCursorPos()
  38. local x,y = m.getSize()
  39. m.setCursorPos(math.ceil((x/2) - (text:len() /2)), y2)
  40. m.write(text)
  41. m.setCursorPos(x2, y2+1)
  42. end
  43.  
  44. function enchant()
  45.     if xp.getLevels() > 30 then
  46.         turtle.select(3)
  47.         if turtle.getItemCount(3) ~=1 then
  48.             clear()
  49.             cPrint("Place 1 book into slot 3")
  50.             sleep(5)
  51.         else
  52.             if xp.enchant(30) then
  53.                 total = total + 30
  54.                 save()
  55.             else
  56.                 clear()
  57.                 cPrint("an error occured, is a book in slot 3?")
  58.                 sleep(5)
  59.             end
  60.         end
  61.     else
  62.         clear()
  63.         cPrint ("Not Enough EXP available")
  64.         sleep(5)
  65.     end
  66. end
  67.  
  68.  
  69. function repair()
  70. local cost = anvil.getRepairCost(1,2)
  71. local levels = xp.getLevels()
  72. if cost == 0 then
  73. clear()
  74. cPrint("invalid Items")
  75. sleep(5)
  76. elseif cost > levels then
  77. clear()
  78. cPrint("Not enough levels, needed "..cost.." levels")
  79. sleep(5)
  80. else
  81. if anvil.repair(1,2) then
  82. total = total + cost
  83. save()
  84. else
  85. clear()
  86. cPrint("an unknown error occured")
  87. sleep (5)
  88. end
  89. end
  90. end
  91. function mon ()
  92. while true do
  93. clearmon()
  94. cPrintMon ("Turtle XP Station")
  95. cPrintMon ("")
  96. cPrintMon ("Currently Level: "..xp.getLevels())
  97. cPrintMon ("")
  98. cPrintMon ("")
  99. cPrintMon ("For Anvil place items into")
  100. cPrintMon ("Slot 1 AND Slot 2")
  101. cPrintMon ("")
  102. cPrintMon ("For Enchanting place book")
  103. cPrintMon ("into Slot 3")
  104. cPrintMon ("")
  105. cPrintMon ("Total Levels Served: "..total)
  106. sleep(10)
  107. end
  108. end
  109.  
  110. function menu()
  111. while true do
  112. clear()
  113. cPrint("Please Choose One")
  114. local n=1
  115. while true do
  116. local x,y = term.getCursorPos()
  117. term.clearLine()
  118. if n==1 then cPrint (">Enchant<  Anvil ")
  119. else         cPrint (" Enchant  >Anvil<") end
  120. term.setCursorPos(x,y)
  121. a,b=os.pullEvent()
  122. while a~="key" do a, b=os.pullEvent() end
  123. if b==203 and n == 2 then n=1 end
  124. if b==205 and n==1 then n=2 end
  125. if b==28 then print ("") break end
  126. end
  127. if n==1 then enchant() end
  128. if n==2 then repair() end
  129. end
  130. end
  131.  
  132. while true do
  133. parallel.waitForAll(mon, menu)
  134. sleep (1)
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement