Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem") or error("No modem attached", 0)
- local CHANNEL = 15
- modem.open(CHANNEL) -- Open channel for communication
- -- Function to wait for a modem message on a specific channel
- local function receiveMessage()
- local event, _, channel, _, message = os.pullEvent("modem_message")
- if channel == CHANNEL then
- return message
- else
- return receiveMessage()
- end
- end
- -- Function to summon TNT in a grid
- local function summonGrid(size, spacing, targetX, targetY, targetZ, projectileType)
- local offset = math.floor(size / 2) * spacing
- for dx = -offset, offset, spacing do
- for dz = -offset, offset, spacing do
- local x = targetX + dx
- local z = targetZ + dz
- commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, x, targetY, z))
- end
- end
- end
- -- Receive projectile data
- local projectileType = receiveMessage()
- print("Projectile Type: " .. projectileType)
- if projectileType == "TNT" or projectileType == "Nuke" then
- print("Valid Type")
- else
- print("Restarting")
- os.reboot()
- end
- local projectilePattern = receiveMessage()
- print("Projectile Pattern: " .. projectilePattern)
- local iterations = receiveMessage() + 0
- print("Projectile Pattern: " .. iterations)
- local targetX = receiveMessage()
- print("Target X: " .. targetX)
- local targetY = receiveMessage() + 40
- print("Target Y: " .. targetY)
- local targetZ = receiveMessage()
- print("Target Z: " .. targetZ)
- -- Item Based on Type
- if projectileType == "TNT" then
- projectileType = "minecraft:tnt"
- spread = 7
- elseif projectileType == "Nuke" then
- projectileType = "alexscaves:nuclear_bomb"
- spread = 80
- end
- modem.transmit(43, CHANNEL, "Bombardment Started")
- -- Pattern Based on input
- for i = 1, tonumber(iterations) do
- print("Firing iteration " .. i)
- modem.transmit(43, CHANNEL, "Firing iteration " .. i)
- if projectilePattern == "Single" then
- commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, targetX, targetY, targetZ))
- elseif projectilePattern == "2x2" then
- summonGrid(2, spread, targetX, targetY, targetZ, projectileType)
- elseif projectilePattern == "3x3" then
- summonGrid(3, spread, targetX, targetY, targetZ, projectileType)
- elseif projectilePattern == "4x4" then
- summonGrid(4, spread, targetX, targetY, targetZ, projectileType)
- elseif projectilePattern == "5x5" then
- summonGrid(5, spread, targetX, targetY, targetZ, projectileType)
- end
- os.sleep(5)
- end
- -- Acknowledge firing
- modem.transmit(43, CHANNEL, "Bombardment Complete")
- os.sleep(1)
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement