Advertisement
Alexr360

Bomb Test

Apr 10th, 2024 (edited)
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2. local CHANNEL = 15
  3. modem.open(CHANNEL) -- Open channel for communication
  4.  
  5. -- Function to wait for a modem message on a specific channel
  6. local function receiveMessage()
  7.     local event, _, channel, _, message = os.pullEvent("modem_message")
  8.     if channel == CHANNEL then
  9.         return message
  10.     else
  11.         return receiveMessage()
  12.     end
  13. end
  14.  
  15. -- Function to summon TNT in a grid
  16. local function summonGrid(size, spacing, targetX, targetY, targetZ, projectileType)
  17.     local offset = math.floor(size / 2) * spacing
  18.     for dx = -offset, offset, spacing do
  19.         for dz = -offset, offset, spacing do
  20.             local x = targetX + dx
  21.             local z = targetZ + dz
  22.             commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, x, targetY, z))
  23.         end
  24.     end
  25. end
  26.  
  27. -- Receive projectile data
  28. local projectileType = receiveMessage()
  29. print("Projectile Type: " .. projectileType)
  30.  
  31. if projectileType == "TNT" or projectileType == "Nuke" then
  32.     print("Valid Type")
  33. else
  34.     print("Restarting")
  35.     os.reboot()
  36. end
  37.    
  38. local projectilePattern = receiveMessage()
  39. print("Projectile Pattern: " .. projectilePattern)
  40.  
  41. local iterations = receiveMessage() + 0
  42. print("Projectile Pattern: " .. iterations)
  43.  
  44. local targetX = receiveMessage()
  45. print("Target X: " .. targetX)
  46.  
  47. local targetY = receiveMessage() + 40
  48. print("Target Y: " .. targetY)
  49.  
  50. local targetZ = receiveMessage()
  51. print("Target Z: " .. targetZ)
  52.  
  53. -- Item Based on Type
  54. if projectileType == "TNT" then
  55.     projectileType = "minecraft:tnt"
  56.     spread = 7
  57. elseif projectileType == "Nuke" then
  58.     projectileType = "alexscaves:nuclear_bomb"
  59.     spread = 80
  60. end
  61.  
  62. modem.transmit(43, CHANNEL, "Bombardment Started")
  63.  
  64. -- Pattern Based on input
  65. for i = 1, tonumber(iterations) do
  66.     print("Firing iteration " .. i)
  67.     modem.transmit(43, CHANNEL, "Firing iteration " .. i)
  68.  
  69.     if projectilePattern == "Single" then
  70.         commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, targetX, targetY, targetZ))
  71.     elseif projectilePattern == "2x2" then
  72.         summonGrid(2, spread, targetX, targetY, targetZ, projectileType)
  73.     elseif projectilePattern == "3x3" then
  74.         summonGrid(3, spread, targetX, targetY, targetZ, projectileType)
  75.     elseif projectilePattern == "4x4" then
  76.         summonGrid(4, spread, targetX, targetY, targetZ, projectileType)
  77.     elseif projectilePattern == "5x5" then
  78.         summonGrid(5, spread, targetX, targetY, targetZ, projectileType)
  79.     end
  80.    
  81.     os.sleep(5)
  82. end
  83.  
  84.  
  85. -- Acknowledge firing
  86. modem.transmit(43, CHANNEL, "Bombardment Complete")
  87.  
  88. os.sleep(1)
  89. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement