Advertisement
Guest User

botnet.lua

a guest
Sep 20th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. -- A program to control multiple mining turtles.
  2. -- For UnbrokenMotion and Friends.
  3. -- Version 0.1.
  4. -- This code is probably a [redacted for discord] mess
  5.  
  6. local termWidth, termHeight = term.getSize()
  7. local termHalfWidth = math.floor(termWidth / 2)
  8. local termHalfHeight = math.floor(termHeight / 2)
  9.  
  10. -- Character table.
  11. -- If you have a better way of doing this, lemme know.
  12. local keyboard = {
  13.     [30] = 'a',
  14.     [48] = 'b',
  15.     [46] = 'c',
  16.     [32] = 'd',
  17.     [18] = 'e',
  18.     [33] = 'f',
  19.     [34] = 'g',
  20.     [35] = 'h',
  21.     [23] = 'i',
  22.     [36] = 'j',
  23.     [37] = 'k',
  24.     [38] = 'l',
  25.     [50] = 'm',
  26.     [49] = 'n',
  27.     [24] = 'o',
  28.     [25] = 'p',
  29.     [16] = 'q',
  30.     [19] = 'r',
  31.     [31] = 's',
  32.     [20] = 't',
  33.     [22] = 'u',
  34.     [47] = 'v',
  35.     [17] = 'w',
  36.     [45] = 'x',
  37.     [21] = 'y',
  38.     [44] = 'z',
  39.     [2] = '1',
  40.     [3] = '2',
  41.     [4] = '3',
  42.     [5] = '4',
  43.     [6] = '5',
  44.     [7] = '6',
  45.     [8] = '7',
  46.     [9] = '8',
  47.     [10] = '9',
  48.     [11] = '0',
  49.     [57] = ' '
  50. }
  51.  
  52. -- Self explanatory, this function prints text centered on the screen.
  53. -- Or at least, it tries to.
  54. function centeredText(y, text)
  55.     local textLength = string.len(text)
  56.     local cursorXPos = termHalfWidth - math.floor(textLength / 2)
  57.     term.setCursorPos(cursorXPos, y)
  58.     term.write(text)
  59. end
  60.  
  61. -- A standard dialog screen.
  62. function dialog(text, bgColor, fgColor, btColor)
  63.     -- Set background color.
  64.     paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
  65.     term.setBackgroundColor(bgColor)
  66.     term.setTextColor(fgColor)
  67.     centeredText(termHalfHeight, text)
  68.    
  69.     --draw buttons.
  70.     local buttonEnd = (termHalfWidth + 3)
  71.     local buttonStart = (termHalfWidth - 2)
  72.    
  73.     local yPos = (termHalfHeight + 2)
  74.  
  75.     paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
  76.     term.setCursorPos(buttonStart+1, yPos)
  77.     term.write("Okay")
  78.    
  79.     --wait for input.
  80.     while true do
  81.         -- sets multiple variables using os.pullEvent, if the mouse if clicked.
  82.         local event, button, x, y = os.pullEvent("mouse_click")
  83.         -- Basic logic to check which button has been pressed.
  84.         if y == yPos then
  85.             if x >= buttonStart and x <= buttonEnd then
  86.                 break
  87.             end
  88.         end
  89.     end
  90. end
  91.  
  92. -- A y/n dialog screen.
  93. function truthDialog(text, bgColor, fgColor, btColor)
  94.     -- Set background color.
  95.     paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
  96.     term.setBackgroundColor(bgColor)
  97.     term.setTextColor(fgColor)
  98.     centeredText(termHalfHeight, text)
  99.    
  100.     --draw buttons.
  101.     local yesEnd = (termHalfWidth - 1)
  102.     local yesStart = (yesEnd - 4)
  103.     local noStart = (termHalfWidth + 1)
  104.     local noEnd = (noStart + 3)
  105.     local yPos = (termHalfHeight + 2)
  106.  
  107.     paintutils.drawLine(yesStart, yPos, yesEnd, yPos, btColor)
  108.     paintutils.drawLine(noStart, yPos, noEnd, yPos, btColor)
  109.     term.setCursorPos(yesStart+1, yPos)
  110.     term.write("yes")
  111.    
  112.     term.setCursorPos(noStart+1, yPos)
  113.     term.write("no")
  114.    
  115.     --wait for input.
  116.     while true do
  117.         -- sets multiple variables using os.pullEvent, if the mouse is clicked.
  118.         local event, button, x, y = os.pullEvent("mouse_click")
  119.        
  120.         -- Basic logic to check which button has been pressed.
  121.         if y == yPos then
  122.             if x >= yesStart and x <= yesEnd then
  123.                 return true
  124.             elseif x >= noStart and x <= noEnd then
  125.                 return false
  126.             end
  127.         end
  128.     end
  129. end
  130.  
  131. -- A textfield dialog screen.
  132. function textDialog(text, bgColor, fgColor, btColor)
  133.     -- Set background color.
  134.     paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
  135.     term.setBackgroundColor(bgColor)
  136.     term.setTextColor(fgColor)
  137.     centeredText(termHalfHeight, text)
  138.    
  139.     --draw buttons.
  140.     local buttonEnd = (termHalfWidth + 3)
  141.     local buttonStart = (termHalfWidth - 2)
  142.    
  143.     local yPos = (termHalfHeight + 5)
  144.  
  145.     paintutils.drawLine(1, yPos - 2, termWidth, yPos - 2, btColor)
  146.     paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
  147.     term.setCursorPos(buttonStart+1, yPos)
  148.     term.write("Okay")
  149.    
  150.     --wait for input.
  151.     local content = ""
  152.     while true do
  153.         -- sets multiple variables using os.pullEvent, if key is pressed.
  154.         local event, key, mouseX, mouseY = os.pullEvent()
  155.         -- return stored value when enter key pressed
  156.         if event == "key" then
  157.             if key == keys.enter then
  158.                 return content
  159.         -- Otherwise, concatenate to the value.
  160.             elseif keyboard[key] ~= nil and string.len(content) < termWidth - 2 then
  161.                 content = content .. keyboard[key]
  162.                 -- display output.
  163.                 term.setCursorPos(2, yPos - 2)
  164.                 term.write(content)
  165.             end
  166.         end
  167.        
  168.         -- check if button clicked
  169.         -- Basic logic to check which button has been pressed.
  170.         if event == "mouse_click" then
  171.             if mouseY == yPos then
  172.                 if mouseX >= buttonStart and mouseX <= buttonEnd then
  173.                     return content
  174.                 end
  175.             end
  176.         end
  177.     end
  178. end
  179.  
  180. -- Setup start.
  181. dialog("Welcome to mineX!", colors.blue, colors.white, colors.lightBlue)
  182. dialog("Please follow the prompts.", colors.blue, colors.white, colors.lightBlue)
  183. if turtle then
  184.     dialog("Turtle.", colors.blue, colors.white, colors.lightBlue)
  185. else
  186.     dialog("Compute", colors.blue, colors.white, colors.lightBlue)
  187. end
  188.  
  189. term.setCursorPos(1, termHeight)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement