Guest User

comCenter

a guest
Feb 4th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. -------------Initialization--------
  2. local digTime = 7 --seconds
  3. local iterations = 0
  4. local cell = peripheral.wrap("back")
  5. local glass = peripheral.wrap("right")
  6.  
  7. local power = cell.getEnergyStored()
  8. local maxPower = cell.getMaxEnergyStored()
  9. local percentage = (power / maxPower) * 100
  10.  
  11. local commandString = "null"
  12. local commandNum = 0
  13. local tempNum = 0 --used in attempt to fix commandNum
  14.  
  15. local dontPrintData = false
  16. local iterationError = false
  17. local isChatCommand = false
  18.  
  19. local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
  20.  
  21. -------------Functions-------------
  22. local function listenForCommand()
  23.   while true do
  24.     event, command = os.pullEvent("chat_command")
  25.     print(event.." "..command)
  26.     isChatCommand = true
  27.   end
  28. end
  29.  
  30. local function checkCommand()
  31.   local tempCount = 0
  32.   for i in string.gmatch(command, "%S+") do
  33.     tempCount = tempCount + 1
  34.     print(i)
  35.     if tempCount == 1 then
  36.       commandString = i
  37.     elseif tempCount == 2 then
  38.       commandNum = i
  39.     end
  40.     if commandString == "mine" then
  41.       tonumber(commandNum)
  42.       tempNum = commandNum + 1
  43.     else
  44.       term.setTextColor(colors.red)
  45.       print("Invalid Command")
  46.       term.setTextColor(colors.white)
  47.     end
  48.   end
  49. end
  50.  
  51. local function getData()
  52.   term.setTextColor(colors.white)
  53.  
  54.   power = cell.getEnergyStored()
  55.   maxPower = cell.getMaxEnergyStored()
  56.   if dontPrintData == false then
  57.     print(power .. "RF out of " .. maxPower .. "RF")
  58.   end
  59.    
  60.   percentage = (power / maxPower) * 100
  61.   if dontPrintData == false then
  62.     print("aka " .. percentage .. "%")
  63.   end
  64. end
  65.  
  66. local function updateGlass()
  67.   glass.clear()
  68.   glass.addBox(1,1,150,65,0x000000,0.2)
  69.   glass.addText(6,6,"Current Power",0xCC4C4C)
  70.   glass.addText(6,20,power .. "RF / " .. maxPower .. "RF")
  71.   glass.addText(17,34,percentage .. " %",0xF2B233)
  72.  
  73.   --if rs.getInput("back") == true then
  74.     --glass.addText(63,51,"GENERATORS ON",0xCC4444)
  75.   --end
  76. end
  77.  
  78. local function moveFrame()
  79.   local blueInput = colors.test(rs.getBundledInput("top",colors.blue))
  80.   if blueInput == true then
  81.     rs.setBundledOutput("top",colors.red) --> wireless transmitter
  82.     sleep(.5)
  83.     rs.setBundledOutput("top",0)
  84.   end
  85. end
  86.  
  87. local function dig()
  88.   local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
  89.   local splitDigTime = digTime / 4
  90.   if not blueInput then
  91.     rs.setBundledOutput("top",colors.black) -->allows tesseract to transmit power
  92.     term.setTextColor(colors.green)
  93.     term.write("Iteration "..iterations)
  94.     dontPrintData = true
  95.     sleep(splitDigTime)
  96.     for i=1,2 do
  97.       term.write(".")
  98.       getData()
  99.       updateGlass()
  100.       term.setTextColor(colors.green)
  101.       sleep(splitDigTime)
  102.     end
  103.     print(".")
  104.     dontPrintData = false
  105.     getData()
  106.     updateGlass()
  107.     sleep(splitDigTime)
  108.     rs.setBundledOutput("top",0)
  109.   else
  110.     term.setTextColor(colors.red)
  111.     term.write("Skipped Iteration "..iterations)
  112.     sleep(splitDigTime)
  113.     dontPrintData = true
  114.     for i=1,2 do
  115.       term.write(".")
  116.       getData()
  117.       updateGlass()
  118.       term.setTextColor(colors.red)
  119.       sleep(splitDigTime)
  120.     end
  121.     print(",")
  122.     dontPrintData = false
  123.     getData()
  124.     updateGlass()
  125.     sleep(splitDigTime)
  126.   end
  127. end
  128.  
  129. local function mine()
  130.   print("Mining Process Started with "..iterations.." iterations...")
  131.   if iterations == 0 then
  132.     term.setTextColor(colors.red)
  133.     print("Error: 0 Iterations?")
  134.     term.setTextColor(colors.white)
  135.     iterationError = true
  136.   else
  137.     iterationError = false
  138.   end
  139.   while iterations > 0 do
  140.     getData()
  141.     updateGlass()
  142.     moveFrame()
  143.     dig()
  144.   end
  145. end
  146.    
  147. ------------Main Program----------
  148. local function main()
  149.   while true do
  150.     getData()
  151.     updateGlass()
  152.     if isChatCommand == true then
  153.       isChatCommand = false
  154.       checkCommand()
  155.       if commandString == "mine" then
  156.         iterations = tempNum - 1
  157.         mine()
  158.       end
  159.       commandString = "null"
  160.       commandNum = 0
  161.     end
  162.     sleep(1)
  163.   end
  164. end
  165.  
  166. parallel.waitForAny(main,listenForCommand)
Advertisement
Add Comment
Please, Sign In to add comment