Advertisement
Thunder7102

launcher

May 24th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --[[
  2.     Programmer: totestots/noiro
  3.     Purpose: An easy-to-use launcher with hotkeys and fast launching with auto-execution
  4.         Enjoy!
  5. ]]
  6.  
  7. --This is a name list that will be accessed to randomly assign a name to turtles
  8. local nameList = {
  9.     "Bob George",
  10.     "Turtlenator",
  11.     "Tortoiminer",
  12.     "Destroyer",
  13.     "Tu Amiga",
  14.     "Tu Amigo",
  15.     "Cat Luvr",
  16.     "Expensive Calculator",
  17.     "Buttermilk",
  18.     "Hopes and Dreams",
  19.     "Elvis", "Lugia",
  20.     "Pink Panther"
  21.  }
  22.  
  23.  
  24. function nameTurtle()
  25.     --Pulls a random name from namelist and names the turtle
  26.     name = nameList[math.random(1,#nameList)]..tostring(math.random(1,100))
  27.     os.setComputerLabel(name)
  28. end
  29.  
  30. function render()
  31.     --Builds and shows the screen
  32.     term.clear()
  33.     term.setCursorPos(1,1)
  34.     print("\t\t"..os.getComputerLabel().." ready!")
  35.     local sizeX, sizeY = term.getSize()
  36.    
  37.     --Makes a nice little separator
  38.     for i=0,sizeX do
  39.         term.write("=")
  40.     end
  41.    
  42.     print("\nFuel: "..turtle.getFuelLevel().." / "..turtle.getFuelLimit())
  43.     print("Quick Launch:")
  44.     print("\t t - Mine Tree")
  45.     print("\t r - Refuel all in Inv")
  46.     print("\t b - [NOT IN YET] Build Stuff")
  47.     print("\t ENTER - Exit Launcher\n")
  48.    
  49.     for i=0,sizeX do
  50.         term.write("=")
  51.     end
  52.    
  53.     term.setCursorPos(1,sizeY)
  54.     term.write("InGame Time: "..textutils.formatTime(os.time(),false))
  55.     term.setCursorPos(sizeX, sizeY)
  56. end
  57.  
  58. function execute(programPath, ...)
  59.     --Runs a program of the specified path
  60.     term.clear()
  61.     term.setCursorPos(1,1)
  62.     shell.run(programPath, ...)
  63.     reboot()
  64. end
  65.  
  66. function run()
  67.     --If you're going to pick him up and put him down a lot, should probs refresh this
  68.     os.importAPI("api/move")
  69.     turtle.setCoords(0,0,0,"north")
  70.     render()
  71. end
  72.  
  73. function launcher()
  74.     --Launches based on what you press
  75.     while true do
  76.         key = getInput()
  77.         term.clear()
  78.         term.setCursorPos(1,1)
  79.         if key == 28 then
  80.             break
  81.         elseif key == 20 then
  82.             shell.run("programs/tree")
  83.         elseif key == 22 then
  84.             shell.run("update")
  85.             os.reboot()
  86.         elseif key == 19 then
  87.             shell.run("programs/refuel")
  88.         elseif key == 48 then
  89.             shell.run("programs/build")
  90.         end
  91.         render()
  92.     end
  93. end
  94.  
  95. function getInput()
  96.     --This will take the keys for the user's input and respond based on it
  97.     local event, key = os.pullEvent("key")
  98.     return key
  99. end
  100. --STARTUP - This is if running for the first time
  101. if not fs.exists("update") then
  102.     local toDelete = shell.getRunningProgram()
  103.     shell.run("pastebin","get","0Qx78iw0","update")
  104.     shell.run("update")
  105.    
  106.     nameTurtle()
  107.     fs.delete(toDelete)
  108.     os.reboot()
  109. else
  110.     os.loadAPI("api/move")
  111.     turtle.setCoords(0,0,0,"north")
  112.     render()
  113.     launcher()
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement