Advertisement
Alexr360

Main Controller

Apr 3rd, 2025 (edited)
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.50 KB | None | 0 0
  1. -- Combined Teleport and Artillery Control System
  2. local modem = peripheral.find("modem") or error("No modem attached", 0)
  3. local CHANNEL = 15
  4. modem.open(CHANNEL)
  5.  
  6. -- Function to wait for a modem message on a specific channel
  7. local function receiveMessage()
  8.     local event, _, channel, _, message = os.pullEvent("modem_message")
  9.     if channel == CHANNEL then
  10.         return message
  11.     else
  12.         return receiveMessage()
  13.     end
  14. end
  15.  
  16. local function teleportPlayer(player, x, y, z, dimension)
  17.     if dimension then
  18.         commands.exec(("execute in %s run tp %s %d %d %d"):format(dimension, player, x, y, z))
  19.     else
  20.         commands.exec(("tp %s %d %d %d"):format(player, x, y, z))
  21.     end
  22. end
  23.  
  24. -- Function to summon particles at a given position
  25. local function summonParticles(x, y, z, dimension)
  26.     for _ = 1, 10 do
  27.         if dimension then
  28.             commands.exec(("execute in %s run particle minecraft:portal %d %d %d 1 1 1 0.1 50"):format(dimension, x, y, z))
  29.         else
  30.             commands.exec(("particle minecraft:portal %d %d %d 1 1 1 0.1 50"):format(x, y, z))
  31.         end
  32.         sleep(0.1) -- Creates a brief delay between particle bursts
  33.     end
  34. end
  35.  
  36. -- Function to add slight randomness to coordinates
  37. local function addRandomness(coordinate)
  38.     -- Generate random number between -2 and 2
  39.     local randomOffset = math.random(-1, 1)
  40.    
  41.     -- 60% chance to apply randomness (accuracy simulation)
  42.     if math.random(1, 10) <= 6 then
  43.         return coordinate + randomOffset
  44.     end
  45.    
  46.     return coordinate
  47. end
  48.  
  49. -- Function to summon TNT in a grid with offset for alternating patterns
  50. local function summonGrid(size, spacing, targetX, targetY, targetZ, projectileType, iteration)
  51.     local offset = math.floor(size / 2) * spacing
  52.     local patternOffset = (iteration % 2) * (spacing / 2) -- Alternate pattern offset
  53.    
  54.     for dx = -offset, offset, spacing do
  55.         for dz = -offset, offset, spacing do
  56.             -- Apply alternating offset to create staggered pattern
  57.             local x = targetX + dx + patternOffset
  58.             local z = targetZ + dz + patternOffset
  59.            
  60.             -- Add randomness to each explosion
  61.             local randomX = addRandomness(x)
  62.             local randomY = addRandomness(targetY)
  63.             local randomZ = addRandomness(z)
  64.            
  65.             commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, randomX, randomY, randomZ))
  66.         end
  67.     end
  68. end
  69.  
  70. -- Seed the random number generator
  71. math.randomseed(os.time())
  72.  
  73. term.clear()
  74. term.setCursorPos(1, 1)
  75. print("Bastion Network Online!")
  76. print("Waiting for command...")
  77.  
  78. -- Main program loop
  79. while true do
  80.     local command = receiveMessage()
  81.    
  82.     if command == "Recall" then
  83.         print("Recalling Player...")
  84.         modem.transmit(43, CHANNEL, "Recalling Player...")
  85.  
  86.         print("Starting Teleporter")
  87.         os.sleep(2)
  88.  
  89.         for i = 1, 100 do
  90.             local chargePercent = i
  91.             print("Charging " .. chargePercent .. "%")
  92.             modem.transmit(43, CHANNEL, "Charging " .. chargePercent .. "%")
  93.             sleep(0.05) -- 100 updates over 5 seconds
  94.         end
  95.  
  96.         -- Teleport the player
  97.         local targetX, targetY, targetZ = -1413, 249, 20, "minecraft:overworld"
  98.         teleportPlayer("Alexr036", targetX, targetY, targetZ, dimension)
  99.  
  100.         -- Summon teleport particles
  101.         summonParticles(targetX, targetY, targetZ, dimension)
  102.        
  103.     elseif command == "Teleport" then
  104.         print("Programming Started")
  105.  
  106.         local positionX = receiveMessage()
  107.         print("Position X: " .. positionX)
  108.  
  109.         local positionY = receiveMessage()
  110.         print("Position Y: " .. positionY)
  111.  
  112.         local positionZ = receiveMessage()
  113.         print("Position Z: " .. positionZ)
  114.  
  115.         local dimension = receiveMessage()
  116.         print("Target Dimension: " .. dimension)
  117.  
  118.         print("Starting Teleporter")
  119.         os.sleep(2)
  120.  
  121.         for i = 1, 100 do
  122.             print("Charging " .. i .. "%")
  123.             modem.transmit(43, CHANNEL, "Charging " .. i .. "%")
  124.             sleep(0.05)
  125.         end
  126.  
  127.         -- Teleport the player across dimensions
  128.         teleportPlayer("Alexr036", positionX, positionY, positionZ, dimension)
  129.  
  130.         -- Summon teleport particles
  131.         summonParticles(positionX, positionY, positionZ, dimension)
  132.        
  133.     elseif command == "TNT" or command == "Nuke" or command == "Arrows" then
  134.         print("Artillery System Online")
  135.         modem.transmit(43, CHANNEL, "Artillery System Online")
  136.  
  137.         local projectileType = command
  138.         local projectilePattern = receiveMessage()
  139.         local iterations      = tonumber(receiveMessage())
  140.         local targetX         = receiveMessage()
  141.         local targetY         = receiveMessage() + 40
  142.         local targetZ         = receiveMessage()
  143.  
  144.         -- Map to Minecraft entities & define spread
  145.         local spread
  146.         if projectileType == "TNT" then
  147.             projectileType = "minecraft:tnt"
  148.             spread = 7
  149.         elseif projectileType == "Nuke" then
  150.             projectileType = "alexscaves:nuclear_bomb"
  151.             spread = 80
  152.         elseif projectileType == "Arrows" then
  153.             projectileType = "minecraft:arrow"
  154.             spread = 12.5
  155.         end
  156.  
  157.         modem.transmit(43, CHANNEL, "Bombardment Started")
  158.  
  159.         for i = 1, iterations do
  160.             print("Iteration "..i)
  161.             modem.transmit(43, CHANNEL, "Iteration "..i)
  162.  
  163.             if projectilePattern == "Spray" then
  164.                 local spiralCount = 900 -- Number of spiral steps
  165.                 local spacing = 0.5      -- Distance between each arrow
  166.                 local dx, dz = 0, 0    -- Current position
  167.                 local dirX, dirZ = 1, 0
  168.                 local segmentLength = 1
  169.                 local stepsTaken = 0
  170.                 local segmentPassed = 0
  171.  
  172.                 for i = 1, spiralCount do
  173.                     local summonX = targetX + dx * spacing
  174.                     local summonZ = targetZ + dz * spacing
  175.  
  176.                     commands.exec(('summon %s %d %d %d {Motion:[0.0,-10.0,0.0],Potion:"minecraft:slowness",Effects:[{Id:2,Amplifier:3,Duration:200},{Id:19,Amplifier:1,Duration:100}]}'):format(projectileType, summonX, targetY, summonZ))
  177.                     dx = dx + dirX
  178.                     dz = dz + dirZ
  179.                     stepsTaken = stepsTaken + 1
  180.  
  181.                     if stepsTaken == segmentLength then
  182.                         dirX, dirZ = -dirZ, dirX
  183.                         segmentPassed = segmentPassed + 1
  184.                         stepsTaken = 0
  185.                         if segmentPassed % 2 == 0 then
  186.                             segmentLength = segmentLength + 1
  187.                         end
  188.                     end
  189.                 end
  190.                 modem.transmit(43, CHANNEL, "Spray Complete")
  191.                
  192.             elseif projectilePattern == "StabCharge" then
  193.                 print("Executing Stab Charge with orbital laser visuals")
  194.                 modem.transmit(43, CHANNEL, "Orbital Laser: Stab Charge begun")
  195.  
  196.                 local maxPerLevel = 6
  197.                 local beamHeight = 20  -- Height from which the laser descends
  198.                 local beamDuration = 15  -- How long the beam particle effect lasts
  199.                 local laserParticle = "minecraft:dust 1 0 0 1" -- Bright red beam
  200.  
  201.                 for j = 1, 10 do
  202.                     local stabY = targetY - j
  203.                     local count = math.ceil((j / 10) * maxPerLevel)
  204.  
  205.                     for k = 1, count do
  206.                         local xOff = addRandomness(targetX)
  207.                         local zOff = addRandomness(targetZ)
  208.                         commands.exec(("particle minecraft:flash %d %d %d 0 0 0 0 1 force"):format(xOff, stabY, zOff))
  209.                         commands.exec(("summon %s %d %d %d {Fuse:10,Motion:[0.0,-10.0,0.0]}"):format(
  210.                             projectileType, xOff, stabY, zOff))
  211.                     end
  212.                     sleep(0.1)
  213.                 end
  214.  
  215.                 modem.transmit(43, CHANNEL, "Orbital Laser complete")
  216.                
  217.             else
  218.                 -- calculate height variation
  219.                 local variationY = (i % 3) * 2
  220.                 local iterationY = targetY + variationY
  221.  
  222.                 if projectilePattern == "Single" then
  223.                     commands.exec(("summon %s %d %d %d {Fuse:100}"):format(projectileType, targetX, iterationY, targetZ))
  224.                 elseif projectilePattern == "2x2" then
  225.                     summonGrid(2, spread, targetX, iterationY, targetZ, projectileType, i)
  226.                 elseif projectilePattern == "3x3" then
  227.                     summonGrid(3, spread, targetX, iterationY, targetZ, projectileType, i)
  228.                 elseif projectilePattern == "4x4" then
  229.                     summonGrid(4, spread, targetX, iterationY, targetZ, projectileType, i)
  230.                 elseif projectilePattern == "5x5" then
  231.                     summonGrid(5, spread, targetX, iterationY, targetZ, projectileType, i)
  232.                 end
  233.  
  234.                 modem.transmit(43, CHANNEL, "Bombardment Complete")
  235.             end
  236.             os.sleep(0.2)
  237.         end
  238.        
  239.     elseif command == "Remote Connected" then
  240.         print("Connected to System")
  241.         modem.transmit(43, CHANNEL, "Connected to System")
  242.     else
  243.         print("Unknown command: " .. command)
  244.         modem.transmit(43, CHANNEL, "Unknown command")
  245.     end
  246.    
  247.     print("Waiting for next command...")
  248. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement