Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local freq = 34900
- -- Get the list of all peripherals
- local peripherals = peripheral.getNames()
- -- Filter and wrap all warpdriveLasers, setting their beam frequency
- local lasers = {}
- for _, name in ipairs(peripherals) do
- if peripheral.getType(name) == "warpdriveLaser" then
- local laser = peripheral.wrap(name)
- laser.beamFrequency(freq)
- table.insert(lasers, laser)
- end
- end
- -- Filter and wrap all warpdriveLaserCameras, setting their beam frequency
- local scanlasers = {}
- for _, name in ipairs(peripherals) do
- if peripheral.getType(name) == "warpdriveLaserCamera" then
- local scanlaser = peripheral.wrap(name)
- scanlaser.beamFrequency(1420)
- scanlasers[name] = scanlaser -- Use the name as the key for easy access
- end
- end
- -- Main event loop
- while true do
- -- Wait for laserScanning event
- local event, peripheralName, lx, ly, lz, block = os.pullEvent("laserScanning")
- -- Check if it's from a known scanlaser
- if event == "laserScanning" and scanlasers[peripheralName] then
- print("Received laser scanning event from: "..peripheralName)
- local lastScanLaser = scanlasers[peripheralName]
- local scanResult = {lastScanLaser.getScanResult()}
- lx, ly, lz = tonumber(scanResult[2]), tonumber(scanResult[3]), tonumber(scanResult[4])
- -- Fire all lasers at the target coordinates
- for _, laser in ipairs(lasers) do
- local laserX, laserY, laserZ = laser.getLocalPosition()
- local dx = lx - laserX
- local dy = ly - laserY
- local dz = lz - laserZ
- laser.emitBeam(dx, dy, dz)
- os.sleep(0) -- yield to allow the coroutine scheduler to run
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement