View difference between Paste ID: BpEAj3Zj and fXLxQmpe
SHOW: | | - or go back to the newest paste.
1
-- Laser‑Guided Warp System (“ztc”) with H/I/O prompts and O‑key to run otc
2
3
-- 1) Wrap terminal + any attached monitors
4
local screens = {}
5
6
-- Terminal wrapper
7
table.insert(screens, {
8
  clear              = function() term.clear(); term.setCursorPos(1,1) end,
9
  getSize            = function() return term.getSize() end,
10
  setTextColor       = term.setTextColor,
11
  setBackgroundColor = term.setBackgroundColor,
12
  setCursorPos       = term.setCursorPos,
13
  write              = term.write,
14
})
15
16
-- Monitor wrappers
17
for _, side in ipairs(peripheral.getNames()) do
18
  if peripheral.getType(side) == "monitor" then
19
    local m = peripheral.wrap(side)
20
    table.insert(screens, {
21
      clear              = function() m.clear(); m.setCursorPos(1,1) end,
22
      getSize            = function() return m.getSize() end,
23
      setTextColor       = function(c) m.setTextColor(c) end,
24
      setBackgroundColor = function(c) m.setBackgroundColor(c) end,
25
      setCursorPos       = function(x,y) m.setCursorPos(x,y) end,
26
      write              = function(txt) m.write(txt) end,
27
      monitor            = m,
28
    })
29
  end
30
end
31
32
-- 2) Auto‑scale monitors so at least 7 lines will fit
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 >= 7 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
51
-- Clear every screen to lightGray
52
local function clearAll()
53
  forAll(function(s)
54
    s.setTextColor(colors.black)
55
    s.setBackgroundColor(colors.lightGray)
56
    s.clear()
57
  end)
58
end
59
60
-- 4) Static texts
61-
local titleText     = "Laser Guided Warp System"
61+
local titleText     = "Horizontal Mining System"
62-
local subtitleText  = "Emit Scanning Laser to Warp"
62+
local subtitleText  = "Emit Scanning Laser to Mine Target"
63-
local offsetText    = "Mining Laser Offset ( I ): "
63+
local offsetText    = "Horizontal Miner ( L ): "
64-
local proximityText = "3D Proximity Offset ( O ): "
64+
65
local promptI       = "Press C to Configure Miner"
66-
local promptI       = "Press I to Toggle Laser Miner Offset"
66+
local promptO       = "Press L to Toggle Miner"
67-
local promptO       = "Press O to Toggle 3D Proximity Offset"
67+
68
-- Draw title, subtitle, offset‑state and proximity‑state lines
69
local function drawStatic()
70
  forAll(function(s)
71
    local w,_ = s.getSize()
72
    -- Title (line 1): white on black
73
    local xT = math.floor((w - #titleText)/2) + 1
74
    s.setTextColor(colors.white)
75
    s.setBackgroundColor(colors.black)
76
    s.setCursorPos(xT,1)
77
    s.write(titleText)
78
79
    -- Subtitle (line 3): black on lightGray
80
    local xS = math.floor((w - #subtitleText)/2) + 1
81
    s.setTextColor(colors.black)
82
    s.setBackgroundColor(colors.lightGray)
83
    s.setCursorPos(xS,3)
84
    s.write(subtitleText)
85
86
    -- Mining Laser Offset (line 4)
87
    local fullOffset = offsetText.."OFF"
88
    local xO = math.floor((w - #fullOffset)/2) + 1
89
    s.setTextColor(colors.black)
90
    s.setBackgroundColor(colors.lightGray)
91
    s.setCursorPos(1,4)
92
    s.write(string.rep(" ", w))
93
    s.setCursorPos(xO,4)
94
    s.write(offsetText)
95
    s.setTextColor(colors.white)
96
    s.setBackgroundColor(colors.red)
97
    s.write("OFF")
98
99
  end)
100-
    -- 3D Proximity Offset (line 5)
100+
101-
    local fullProx = proximityText.."OFF"
101+
102-
    local xP = math.floor((w - #fullProx)/2) + 1
102+
103
local function drawPrompt()
104
  forAll(function(s)
105-
    s.setCursorPos(1,5)
105+
106
    -- line h-2: O prompt
107-
    s.setCursorPos(xP,5)
107+
108-
    s.write(proximityText)
108+
109
    s.setCursorPos(1,h-2)
110
    s.write(string.rep(" ", w))
111
    local xO = math.floor((w - #promptO)/2) + 1
112
    s.setCursorPos(xO,h-2)
113
    s.write(promptO)
114
    -- line h-1: H prompt
115
    s.setTextColor(colors.white)
116
    s.setBackgroundColor(colors.blue)
117
    s.setCursorPos(1,h-1)
118
    s.write(string.rep(" ", w))
119
    local xH = math.floor((w - #promptH)/2) + 1
120
    s.setCursorPos(xH,h-1)
121
    s.write(promptH)
122
    -- line h: I prompt
123
    s.setBackgroundColor(colors.blue)
124
    s.setCursorPos(1,h)
125
    s.write(string.rep(" ", w))
126
    local xI = math.floor((w - #promptI)/2) + 1
127
    s.setCursorPos(xI,h)
128
    s.write(promptI)
129
  end)
130
end
131
132
-- 5) Set up warpdriveLaserCamera peripherals
133
rednet.open("top")
134
local cams = peripheral.getNames()
135
for i=#cams,1,-1 do
136
  if peripheral.getType(cams[i]) ~= "warpdriveLaserCamera" then
137
    table.remove(cams,i)
138
  else
139
    peripheral.wrap(cams[i]).beamFrequency(1420)
140
  end
141
end
142
143
-- 6) Initial draw (blank coords)
144
clearAll()
145
drawStatic()
146
drawPrompt()
147
148
-- 7) Coords line, accepts nil → blanks before first scan
149
local function updateCoords(x,y,z)
150
  local sx = x and tostring(x) or "    "
151
  local sy = y and tostring(y) or "    "
152
  local sz = z and tostring(z) or "    "
153
  local coordLine = string.format("Target: X:%s   Y:%s   Z:%s", sx, sy, sz)
154
  forAll(function(s)
155
    local w,_ = s.getSize()
156
    s.setTextColor(colors.black)
157
    s.setBackgroundColor(colors.lightGray)
158
    s.setCursorPos(1,6)
159
    s.write(string.rep(" ", w))
160
    local cx = math.floor((w - #coordLine)/2) + 1
161
    s.setCursorPos(cx,6)
162
    s.write(coordLine)
163
  end)
164
end
165
166
-- draw initial blanks (on line 6)
167
updateCoords(nil,nil,nil)
168
169
-- 8) Main loop: scan + key handling
170
while true do
171
  local ev,k,b,c,d = os.pullEventRaw()
172
  if ev == "laserScanning" then
173
    local tx = tonumber(b)
174
    local ty = tonumber(c)
175
    local tz = tonumber(d)
176
    updateCoords(tx,ty,tz)
177
local data = { x = tx, y = ty, z = tz }
178
    rednet.broadcast(data, "SMineBroadcast")
179
180
  elseif ev == "key" then
181
    if k == keys.h then
182
      os.reboot()
183
    elseif k == keys.c then
184
      shell.run("conf")
185
      clearAll(); drawStatic(); updateCoords(tx,ty,tz); drawPrompt()
186
    elseif k == keys.l then
187
      rednet.broadcast("Toggle", "Miner")
188
    end
189
  end
190
end
191-
    rednet.broadcast(data, "HorizontalJumpBroadcast")
191+