Advertisement
Alexr360

Artillary Controller

Apr 10th, 2024 (edited)
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Print a line of dashes for aesthetics
  2. local function lineBreak()
  3.     local width, height = term.getSize()
  4.     for i = 1, width do
  5.       io.write("-")
  6.     end
  7.     io.write("\n")
  8. end
  9. -- Function to clear the screen
  10. local function clearScreen()
  11.     term.clear()
  12.     term.setCursorPos(1, 1)
  13. end
  14.  
  15. clearScreen()
  16. -- Print the welcome message
  17. print("Artillery Controller")
  18. lineBreak()
  19. print("Select a weapon:")
  20. print("1. TNT")
  21. print("2. Nuke")
  22. lineBreak()
  23.  
  24. local choice = read()
  25.  
  26. if choice == "1" then
  27.   projectileType = "TNT"
  28. elseif choice == "2" then
  29.   print("Authorization Code:")
  30.   local choice = read()
  31.   if choice == "1234" then
  32.     print("Codes Accepted")
  33.     projectileType = "Nuke"
  34.   end
  35. end
  36.  
  37. clearScreen()
  38.  
  39.  
  40. -- Ask for shot size
  41. print("Artillery Controller")
  42. lineBreak()
  43. print("Weapon:"..projectileType)
  44. lineBreak()
  45. print("Size of Shot:")
  46. print("1. 1x1")
  47. print("2. 2x2")
  48. if projectileType == "TNT" then
  49.     print("3. 3x3")
  50.     print("4. 4x4")
  51.     print("5. 5x5")
  52.    
  53.     local choice = read()
  54.  
  55.     if choice == "2" then
  56.       projectilePattern = "2x2"
  57.     elseif choice == "3" then
  58.       projectilePattern = "3x3"
  59.     elseif choice == "4" then
  60.       projectilePattern = "4x4"
  61.     elseif choice == "5" then
  62.       projectilePattern = "5x5"
  63.     else
  64.       projectilePattern = "Single"
  65.     end
  66. elseif projectileType == "Nuke" then
  67.     local choice = read()
  68.  
  69.     if choice == "2" then
  70.       projectilePattern = "2x2"
  71.     else
  72.       projectilePattern = "Single"
  73.     end
  74. end
  75. clearScreen()
  76.  
  77.  
  78. print("Artillery Controller")
  79. lineBreak()
  80. print("Weapon:"..projectileType)
  81. print("Pattern:"..projectilePattern)
  82. lineBreak()
  83. print("Number of Itterations")
  84. lineBreak()
  85. local iterations = tonumber(read())
  86. clearScreen()
  87.  
  88. print("Artillery Controller")
  89. lineBreak()
  90. print("Weapon:"..projectileType)
  91. print("Pattern:"..projectilePattern)
  92. lineBreak()
  93. print("Select a targeting method")
  94. print("1. Current Position")
  95. print("2. Custom Current")
  96. print("3. Offset Position")
  97. lineBreak()
  98.  
  99. local choice = read()
  100.  
  101. if choice == "2" then
  102.     print("X: ")
  103.     targetX = read()
  104.     print("Y: ")
  105.     targetY = read()
  106.     print("Z: ")
  107.     targetZ = read()
  108. elseif choice == "3" then
  109.     X, Y, Z = gps.locate()
  110.     print("X: ")
  111.     targetX = X + read()
  112.     print("Y: ")
  113.     targetY = Y + read()
  114.     print("Z: ")
  115.     targetZ = Z + read()
  116. else
  117.     targetX, targetY, targetZ = gps.locate()
  118. end
  119.  
  120. clearScreen()
  121. print("Artillery Controller")
  122. lineBreak()
  123. print("Weapon:"..projectileType)
  124. print("Pattern:"..projectilePattern)
  125. print("X:"..targetX)
  126. print("Y:"..targetY)
  127. print("Z:"..targetZ)
  128. lineBreak()
  129. print("Please Confirm")
  130. print("1. Confirm Input")
  131. print("2. Cancel")
  132. lineBreak()
  133.  
  134.  
  135. local choice = read()
  136.  
  137. if choice == "1" then
  138.     clearScreen()
  139.     print("Artillery Controller")
  140.     lineBreak()
  141.     print("Starting Programing")
  142.     lineBreak()
  143.    
  144.     local modem = peripheral.find("modem") or error("No modem attached", 0)
  145.     modem.open(43) -- Open 43 so we can receive replies
  146.  
  147.     modem.transmit(15, 43, projectileType)
  148.     print("Weapon:"..projectileType)
  149.     os.sleep(1)
  150.     modem.transmit(15, 43, projectilePattern)
  151.     print("Pattern:"..projectilePattern)
  152.     os.sleep(1)
  153.     modem.transmit(15, 43, iterations)
  154.     print("Iterations:"..iterations)
  155.     os.sleep(1)
  156.     modem.transmit(15, 43, targetX)
  157.     print("X:"..targetX)
  158.     os.sleep(1)
  159.     modem.transmit(15, 43, targetY)
  160.     print("Y:"..targetY)
  161.     os.sleep(1)
  162.     modem.transmit(15, 43, targetZ)
  163.     print("Z:"..targetZ)
  164.        
  165.     os.sleep(0.5)
  166.     clearScreen()
  167.     print("Artillery Controller")
  168.     lineBreak()
  169.     print("Programing Complete")
  170.     lineBreak()
  171.     print("Firing Now")
  172.    
  173.     clearScreen()
  174.     print("Artillery Controller")
  175.     lineBreak()
  176.     print("Programing Complete")
  177.     for i = 1, iterations+2 do
  178.         local event, side, channel, replyChannel, message, distance
  179.         repeat
  180.           event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  181.         until channel == 43
  182.         print(tostring(message))
  183.     end
  184. else
  185.   print("Cancelled")
  186. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement