SHARE
    TWEET
    jaklsfjlsak

    激光扫描发射器 水平跳船 投屏

    Apr 20th, 2025 (edited)
    430
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    1. -- Laser‐Guided Warp System ("ztc") with clean, scaled UI and full X,Y,Z reporting
    2. -- 1) Wrap terminal + any attached monitors
    3. local screens = {}
    4. -- Terminal
    5. table.insert(screens, {
    6. clear = function() term.clear() term.setCursorPos(1,1) end,
    7. getSize = function() return term.getSize() end,
    8. setTextColor = term.setTextColor,
    9. setBackgroundColor = term.setBackgroundColor,
    10. setCursorPos = term.setCursorPos,
    11. write = term.write,
    12. })
    13. -- Monitors
    14. for _, side in ipairs(peripheral.getNames()) do
    15. if peripheral.getType(side) == "monitor" then
    16. local m = peripheral.wrap(side)
    17. table.insert(screens, {
    18. clear = function() m.clear(); m.setCursorPos(1,1) end,
    19. getSize = function() return m.getSize() end,
    20. setTextColor = function(c) m.setTextColor(c) end,
    21. setBackgroundColor = function(c) m.setBackgroundColor(c) end,
    22. setCursorPos = function(x,y) m.setCursorPos(x,y) end,
    23. write = function(txt) m.write(txt) end,
    24. monitor = m,
    25. })
    26. end
    27. end
    28. -- 2) Auto‐scale monitors so 5 lines fit (lines 1,3,5)
    29. for _, s in ipairs(screens) do
    30. if s.monitor then
    31. local best = 0.5
    32. for _, scale in ipairs({1,0.5}) do
    33. s.monitor.setTextScale(scale)
    34. local w,h = s.getSize()
    35. if w >= 40 and h >= 5 then
    36. best = scale
    37. break
    38. end
    39. end
    40. s.monitor.setTextScale(best)
    41. end
    42. end
    43. -- 3) Helpers
    44. local function forAll(fn) for _,s in ipairs(screens) do fn(s) end end
    45. local function clearAll() forAll(function(s) s.clear() end) end
    46. -- 4) Header & Subtitle
    47. local titleText = "Laser Guided Warp System"
    48. local subtitleText = "Emit Scanning Laser to Warp"
    49. local function drawHeader()
    50. forAll(function(s)
    51. local w,_ = s.getSize()
    52. s.clear()
    53. -- Title (line 1): white on black
    54. local xT = math.floor((w - #titleText)/2) + 1
    55. s.setTextColor(colors.white)
    56. s.setBackgroundColor(colors.black)
    57. s.setCursorPos(xT,1)
    58. s.write(titleText)
    59. -- Subtitle (line 3): black on lightGray
    60. local xS = math.floor((w - #subtitleText)/2) + 1
    61. s.setTextColor(colors.black)
    62. s.setBackgroundColor(colors.lightGray)
    63. s.setCursorPos(xS,3)
    64. s.write(subtitleText)
    65. end)
    66. end
    67. -- 5) Setup peripherals
    68. rednet.open("top")
    69. local lasers = peripheral.getNames()
    70. for i=#lasers,1,-1 do
    71. if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
    72. table.remove(lasers,i)
    73. else
    74. peripheral.wrap(lasers[i]).beamFrequency(1420)
    75. end
    76. end
    77. -- 6) Initial draw
    78. clearAll()
    79. drawHeader()
    80. -- 7) Dynamic coordinate line on row 5 (full X, Y, Z)
    81. local function updateCoords(x,y,z)
    82. local line = string.format("Target: X:%d Y:%d Z:%d", x, y, z)
    83. forAll(function(s)
    84. local w,_ = s.getSize()
    85. -- clear entire line 5
    86. s.setTextColor(colors.black)
    87. s.setBackgroundColor(colors.lightGray)
    88. s.setCursorPos(1,5)
    89. s.write(string.rep(" ", w))
    90. -- write centered
    91. local xs = math.floor((w - #line)/2) + 1
    92. s.setCursorPos(xs,5)
    93. s.write(line)
    94. end)
    95. end
    96. -- 8) Main loop: listen for laserScanning
    97. while true do
    98. local event, side, lx, ly, lz = os.pullEvent("laserScanning")
    99. local tx = tonumber(lx)
    100. local ty = tonumber(ly)
    101. local tz = tonumber(lz)
    102. updateCoords(tx, ty, tz)
    103. rednet.broadcast({ x = tx, y = ty, z = tz }, "HorizontalJumpBroadcast")
    104. end
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /