Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Laser‑Guided Warp System (“ztc”) with clean, scaled UI and full X,Y,Z reporting
- -- 1) Wrap terminal + any attached monitors
- local screens = {}
- -- Terminal
- table.insert(screens, {
- clear = function() term.clear() term.setCursorPos(1,1) end,
- getSize = function() return term.getSize() end,
- setTextColor = term.setTextColor,
- setBackgroundColor = term.setBackgroundColor,
- setCursorPos = term.setCursorPos,
- write = term.write,
- })
- -- Monitors
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "monitor" then
- local m = peripheral.wrap(side)
- table.insert(screens, {
- clear = function() m.clear(); m.setCursorPos(1,1) end,
- getSize = function() return m.getSize() end,
- setTextColor = function(c) m.setTextColor(c) end,
- setBackgroundColor = function(c) m.setBackgroundColor(c) end,
- setCursorPos = function(x,y) m.setCursorPos(x,y) end,
- write = function(txt) m.write(txt) end,
- monitor = m,
- })
- end
- end
- -- 2) Auto‑scale monitors so 5 lines fit (lines 1,3,5)
- for _, s in ipairs(screens) do
- if s.monitor then
- local best = 0.5
- for _, scale in ipairs({1,0.5}) do
- s.monitor.setTextScale(scale)
- local w,h = s.getSize()
- if w >= 40 and h >= 5 then
- best = scale
- break
- end
- end
- s.monitor.setTextScale(best)
- end
- end
- -- 3) Helpers
- local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
- local function clearAll() forAll(function(s) s.clear() end) end
- -- 4) Header & Subtitle
- local titleText = "Laser Guided Warp System"
- local subtitleText = "Emit Scanning Laser to Warp"
- local function drawHeader()
- forAll(function(s)
- local w,_ = s.getSize()
- s.clear()
- -- Title (line 1): white on black
- local xT = math.floor((w - #titleText)/2) + 1
- s.setTextColor(colors.white)
- s.setBackgroundColor(colors.black)
- s.setCursorPos(xT,1)
- s.write(titleText)
- -- Subtitle (line 3): black on lightGray
- local xS = math.floor((w - #subtitleText)/2) + 1
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(xS,3)
- s.write(subtitleText)
- end)
- end
- -- 5) Setup peripherals
- rednet.open("top")
- local lasers = peripheral.getNames()
- for i=#lasers,1,-1 do
- if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
- table.remove(lasers,i)
- else
- peripheral.wrap(lasers[i]).beamFrequency(1420)
- end
- end
- -- 6) Initial draw
- clearAll()
- drawHeader()
- -- 7) Dynamic coordinate line on row 5 (full X, Y, Z)
- local function updateCoords(x,y,z)
- local line = string.format("Target: X:%d Y:%d Z:%d", x, y, z)
- forAll(function(s)
- local w,_ = s.getSize()
- -- clear entire line 5
- s.setTextColor(colors.black)
- s.setBackgroundColor(colors.lightGray)
- s.setCursorPos(1,5)
- s.write(string.rep(" ", w))
- -- write centered
- local xs = math.floor((w - #line)/2) + 1
- s.setCursorPos(xs,5)
- s.write(line)
- end)
- end
- -- 8) Main loop: listen for laserScanning
- while true do
- local event, side, lx, ly, lz = os.pullEvent("laserScanning")
- local tx = tonumber(lx)
- local ty = tonumber(ly)
- local tz = tonumber(lz)
- updateCoords(tx, ty, tz)
- rednet.broadcast({ x = tx, y = ty, z = tz }, "HorizontalJumpBroadcast")
- end
Advertisement
Add Comment
Please, Sign In to add comment