SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Laser‑Guided Warp System (“ztc”) with clean, scaled UI and full X,Y,Z reporting | |
| 2 | ||
| 3 | -- 1) Wrap terminal + any attached monitors | |
| 4 | - | |
| 4 | + | local screens = {}
|
| 5 | - | for i = #lasers, 1, -1 do |
| 5 | + | |
| 6 | - | if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then |
| 6 | + | -- Terminal |
| 7 | - | table.remove(lasers, i) |
| 7 | + | table.insert(screens, {
|
| 8 | - | else |
| 8 | + | clear = function() term.clear() term.setCursorPos(1,1) end, |
| 9 | - | peripheral.wrap(lasers[i]).beamFrequency(1420) |
| 9 | + | getSize = function() return term.getSize() end, |
| 10 | setTextColor = term.setTextColor, | |
| 11 | setBackgroundColor = term.setBackgroundColor, | |
| 12 | setCursorPos = term.setCursorPos, | |
| 13 | - | print("Emit Scanning Laser to Set Jump Target Without Y Movements")
|
| 13 | + | write = term.write, |
| 14 | - | |
| 14 | + | }) |
| 15 | ||
| 16 | - | local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent() |
| 16 | + | -- Monitors |
| 17 | - | |
| 17 | + | for _, side in ipairs(peripheral.getNames()) do |
| 18 | - | if event == "laserScanning" then |
| 18 | + | if peripheral.getType(side) == "monitor" then |
| 19 | - | -- Convert the laser scanning coordinates to numbers and store them |
| 19 | + | local m = peripheral.wrap(side) |
| 20 | - | local lastLx = tonumber(lx) |
| 20 | + | table.insert(screens, {
|
| 21 | - | local lastLy = tonumber(ly) |
| 21 | + | clear = function() m.clear(); m.setCursorPos(1,1) end, |
| 22 | - | local lastLz = tonumber(lz) |
| 22 | + | getSize = function() return m.getSize() end, |
| 23 | - | |
| 23 | + | setTextColor = function(c) m.setTextColor(c) end, |
| 24 | - | |
| 24 | + | setBackgroundColor = function(c) m.setBackgroundColor(c) end, |
| 25 | - | print("Laser Target: X:" .. lastLx .. " Y:" .. lastLy .. " Z:" .. lastLz)
|
| 25 | + | setCursorPos = function(x,y) m.setCursorPos(x,y) end, |
| 26 | write = function(txt) m.write(txt) end, | |
| 27 | - | -- Package the coordinates into a table (you can also send a formatted string) |
| 27 | + | monitor = m, |
| 28 | - | local data = { x = lastLx, y = lastLy, z = lastLz }
|
| 28 | + | }) |
| 29 | - | |
| 29 | + | end |
| 30 | - | -- Broadcast the coordinates using a custom protocol ("coordBroadcast")
|
| 30 | + | |
| 31 | - | rednet.broadcast(data, "HorizontalJumpBroadcast") |
| 31 | + | |
| 32 | -- 2) Auto‑scale monitors so 5 lines fit (lines 1,3,5) | |
| 33 | for _, s in ipairs(screens) do | |
| 34 | if s.monitor then | |
| 35 | local best = 0.5 | |
| 36 | for _, scale in ipairs({1,0.5}) do
| |
| 37 | s.monitor.setTextScale(scale) | |
| 38 | local w,h = s.getSize() | |
| 39 | if w >= 40 and h >= 5 then | |
| 40 | best = scale | |
| 41 | break | |
| 42 | end | |
| 43 | end | |
| 44 | s.monitor.setTextScale(best) | |
| 45 | end | |
| 46 | end | |
| 47 | ||
| 48 | -- 3) Helpers | |
| 49 | local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end | |
| 50 | local function clearAll() forAll(function(s) s.clear() end) end | |
| 51 | ||
| 52 | -- 4) Header & Subtitle | |
| 53 | local titleText = "Laser Guided Warp System" | |
| 54 | local subtitleText = "Emit Scanning Laser to Warp" | |
| 55 | ||
| 56 | local function drawHeader() | |
| 57 | forAll(function(s) | |
| 58 | local w,_ = s.getSize() | |
| 59 | s.clear() | |
| 60 | -- Title (line 1): white on black | |
| 61 | local xT = math.floor((w - #titleText)/2) + 1 | |
| 62 | s.setTextColor(colors.white) | |
| 63 | s.setBackgroundColor(colors.black) | |
| 64 | s.setCursorPos(xT,1) | |
| 65 | s.write(titleText) | |
| 66 | -- Subtitle (line 3): black on lightGray | |
| 67 | local xS = math.floor((w - #subtitleText)/2) + 1 | |
| 68 | s.setTextColor(colors.black) | |
| 69 | s.setBackgroundColor(colors.lightGray) | |
| 70 | s.setCursorPos(xS,3) | |
| 71 | s.write(subtitleText) | |
| 72 | end) | |
| 73 | end | |
| 74 | ||
| 75 | -- 5) Setup peripherals | |
| 76 | rednet.open("top")
| |
| 77 | local lasers = peripheral.getNames() | |
| 78 | for i=#lasers,1,-1 do | |
| 79 | if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then | |
| 80 | table.remove(lasers,i) | |
| 81 | else | |
| 82 | peripheral.wrap(lasers[i]).beamFrequency(1420) | |
| 83 | end | |
| 84 | end | |
| 85 | ||
| 86 | -- 6) Initial draw | |
| 87 | clearAll() | |
| 88 | drawHeader() | |
| 89 | ||
| 90 | -- 7) Dynamic coordinate line on row 5 (full X, Y, Z) | |
| 91 | local function updateCoords(x,y,z) | |
| 92 | local line = string.format("Target: X:%d Y:%d Z:%d", x, y, z)
| |
| 93 | forAll(function(s) | |
| 94 | local w,_ = s.getSize() | |
| 95 | -- clear entire line 5 | |
| 96 | s.setTextColor(colors.black) | |
| 97 | s.setBackgroundColor(colors.lightGray) | |
| 98 | s.setCursorPos(1,5) | |
| 99 | s.write(string.rep(" ", w))
| |
| 100 | -- write centered | |
| 101 | local xs = math.floor((w - #line)/2) + 1 | |
| 102 | s.setCursorPos(xs,5) | |
| 103 | s.write(line) | |
| 104 | end) | |
| 105 | end | |
| 106 | ||
| 107 | -- 8) Main loop: listen for laserScanning | |
| 108 | while true do | |
| 109 | local event, side, lx, ly, lz = os.pullEvent("laserScanning")
| |
| 110 | local tx = tonumber(lx) | |
| 111 | local ty = tonumber(ly) | |
| 112 | local tz = tonumber(lz) | |
| 113 | updateCoords(tx, ty, tz) | |
| 114 | rednet.broadcast({ x = tx, y = ty, z = tz }, "HorizontalJumpBroadcast")
| |
| 115 | end | |
| 116 |