Advertisement
MajorVictory

Turtle Autoattack

Jun 3rd, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. -- number of seconds before rebooting the machine, use -1 to disable
  2. local timeToReboot = 300
  3.  
  4. --time in seconds between updates
  5. local sleepTime = 0.5
  6.  
  7.  
  8. local seconds = 0
  9.  
  10. function SecondsToClock(sSeconds)
  11.     local nSeconds = tonumber(sSeconds)
  12.     if nSeconds == 0 then
  13.         return "00:00:00";
  14.     else
  15.         nHours = string.format("%02d", math.floor(nSeconds/3600));
  16.         nMins = string.format("%02d", math.floor(nSeconds/60 - (nHours*60)));
  17.         nSecs = string.format("%02d", math.floor(nSeconds - nHours*3600 - nMins *60));
  18.         return nHours..":"..nMins..":"..nSecs
  19.     end
  20. end
  21.  
  22. local w,h = term.getSize()
  23.  
  24. function printStatus()
  25.     term.clear()
  26.  
  27.     local clockTime = "Time: "..SecondsToClock(seconds)
  28.     term.setCursorPos(w - #clockTime+1, 1)
  29.     term.setBackgroundColor(colors.white)
  30.     term.setTextColor(colors.black)
  31.     term.write(clockTime)
  32.  
  33.     if timeToReboot > 0 then
  34.         local rebootDisplay = "Reboot in: "..string.format("%d",(timeToReboot - seconds))
  35.         term.setCursorPos(w - #rebootDisplay+1, 2)
  36.         term.write(rebootDisplay)
  37.     end
  38.  
  39.  
  40.     term.setBackgroundColor(colors.black)
  41.     term.setTextColor(colors.white)
  42. end
  43.  
  44. local isRunning = true
  45. local reboot = false
  46. local hitup = 0
  47.  
  48. while isRunning do
  49.     printStatus()
  50.  
  51.     turtle.attack()
  52.     hitup = hitup + 1
  53.  
  54.     if hitup > 5 then
  55.         hitup = 0
  56.         turtle.attackUp()
  57.     end
  58.  
  59.     turtle.suck()
  60.     turtle.suckUp()
  61.  
  62.     if timeToReboot > 0 and seconds >= timeToReboot then
  63.         term.clear()
  64.         term.setCursorPos(1,1)
  65.         term.write("Rebooting...")
  66.         reboot = true
  67.         isRunning = false
  68.         sleep(2)
  69.     else
  70.         seconds = seconds + sleepTime
  71.         sleep(sleepTime)
  72.     end
  73. end
  74.  
  75. if reboot then os.reboot() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement