Advertisement
Guest User

botnet.lua

a guest
Sep 19th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. -- A program to control multiple mining turtles.
  2. -- For UnbrokenMotion and Friends.
  3. -- Version 0.1.
  4.  
  5. local termWidth, termHeight = term.getSize()
  6. local termHalfWidth = termWidth / 2
  7. local termHalfHeight = termHeight / 2
  8.  
  9. -- Setup start.
  10. -- Self explanatory, prints text centered on the screen.
  11. -- Or at least, it tries to.
  12. function centeredText(y, text)
  13.     local textLength = string.len(text)
  14.     local cursorXPos = termHalfWidth - (textLength / 2)
  15.     term.setCursorPos(cursorXPos, y)
  16.     term.write(text)
  17. end
  18.  
  19. -- A standard dialog screen.
  20. function dialog(text, bgColor, fgColor, btColor)
  21.     -- Set background color.
  22.     paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
  23.     term.setBackgroundColor(bgColor)
  24.     term.setTextColor(fgColor)
  25.     centeredText(termHalfHeight, text)
  26.    
  27.     --draw buttons.
  28.     local buttonEnd = (termHalfWidth + 2)
  29.     local buttonStart = (termHalfWidth - 2)
  30.    
  31.     local yPos = (termHalfHeight + 2)
  32.  
  33.     paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
  34.     term.setCursorPos(buttonStart+1, yPos)
  35.     term.write("Okay")
  36.    
  37.     --wait for input.
  38.     while true do
  39.         -- sets multiple variables using os.pullEvent, if the mouse if clicked.
  40.         local event, button, x, y = os.pullEvent("mouse_click")
  41.        
  42.         -- Basic logic to check which button has been pressed.
  43.         if y == yPos then
  44.             break
  45.         end
  46.     end
  47. end
  48.  
  49. -- A y/n dialog screen.
  50. function truthDialog(text, bgColor, fgColor, btColor)
  51.     -- Set background color.
  52.     paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
  53.     term.setBackgroundColor(bgColor)
  54.     term.setTextColor(fgColor)
  55.     centeredText(termHalfHeight, text)
  56.    
  57.     --draw buttons.
  58.     local yesEnd = (termHalfWidth - 1)
  59.     local yesStart = (yesEnd - 4)
  60.     local noStart = (termHalfWidth + 1)
  61.     local noEnd = (noStart + 3)
  62.     local yPos = (termHalfHeight + 2)
  63.  
  64.     paintutils.drawLine(yesStart, yPos, yesEnd, yPos, btColor)
  65.     paintutils.drawLine(noStart, yPos, noEnd, yPos, btColor)
  66.     term.setCursorPos(yesStart+1, yPos)
  67.     term.write("yes")
  68.    
  69.     term.setCursorPos(noStart+1, yPos)
  70.     term.write("no")
  71.    
  72.     --wait for input.
  73.     while true do
  74.         -- sets multiple variables using os.pullEvent, if the mouse is clicked.
  75.         local event, button, x, y = os.pullEvent("mouse_click")
  76.        
  77.         -- Basic logic to check which button has been pressed.
  78.         if y == yPos then
  79.             if x >= yesStart and x <= yesEnd then
  80.                 return true
  81.             elseif x >= noStart and x <= noEnd then
  82.                 return false
  83.             end
  84.         end
  85.     end
  86. end
  87.  
  88. -- Testing functions, TEMPORARY
  89. dialog("Hello, world!", colors.blue, colors.white, colors.lightBlue)
  90. local value = truthDialog("Hello, world!", colors.blue, colors.white, colors.lightBlue)
  91. -- Setup End.
  92.  
  93. term.setCursorPos(1, termHeight)
  94. print(value)
  95. sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement