SHOW:
|
|
- or go back to the newest paste.
1 | local OffsetValue = 3 | |
2 | local shield = peripheral.find("warpdriveForceFieldProjector") | |
3 | local lasers = peripheral.getNames() | |
4 | local speaker = peripheral.find("warpdriveSpeaker") | |
5 | local lever = "front" | |
6 | local safedist = 15 | |
7 | local lastLx, lastLy, lastLz = 0, 0, 0 | |
8 | ||
9 | -- Helper: only speak if a speaker is present | |
10 | local function trySpeak(msg) | |
11 | if speaker then speaker.speak(msg) end | |
12 | end | |
13 | ||
14 | function shieldOffset(lx, ly, lz, fx, fy, fz) | |
15 | local dx = lx - fx | |
16 | local dy = ly - fy | |
17 | local dz = lz - fz | |
18 | local distance = math.sqrt(dx * dx + dy * dy + dz * dz) | |
19 | dx = dx / distance | |
20 | dy = dy / distance | |
21 | dz = dz / distance | |
22 | local t1x = lx + dx * OffsetValue | |
23 | - | if fs.exists("conf") == false then |
23 | + | |
24 | local t1z = lz + dz * OffsetValue | |
25 | return t1x, t1y, t1z, distance | |
26 | end | |
27 | ||
28 | if not fs.exists("conf") then | |
29 | shell.run("pastebin get 38M5cNbZ conf") | |
30 | term.clear() | |
31 | end | |
32 | ||
33 | for i = #lasers, 1, -1 do | |
34 | if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then | |
35 | table.remove(lasers, i) | |
36 | else | |
37 | peripheral.wrap(lasers[i]).beamFrequency(1420) | |
38 | end | |
39 | end | |
40 | ||
41 | print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure") | |
42 | trySpeak("Control System Online") | |
43 | ||
44 | local _, upgrades = shield.getUpgrades() | |
45 | local Size | |
46 | if upgrades:match("1/4 x Range") then | |
47 | Size = 16 | |
48 | elseif upgrades:match("2/4 x Range") then | |
49 | Size = 32 | |
50 | elseif upgrades:match("3/4 x Range") then | |
51 | Size = 48 | |
52 | elseif upgrades:match("4/4 x Range") then | |
53 | - | local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent() |
53 | + | |
54 | elseif upgrades:match("0/4 x Range") then | |
55 | Size = 0 | |
56 | end | |
57 | ||
58 | while true do | |
59 | local event, laserName, lx, ly, lz = os.pullEvent() | |
60 | - | tx = (t1x - fx) / Size |
60 | + | |
61 | - | ty = (t1y - fy) / Size |
61 | + | |
62 | - | tz = (t1z - fz) / Size |
62 | + | |
63 | local t1x, t1y, t1z, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz) | |
64 | ||
65 | local tx = (t1x - fx) / Size | |
66 | local ty = (t1y - fy) / Size | |
67 | - | speaker.speak("Target Dis: " .. tostring(distance)) |
67 | + | local tz = (t1z - fz) / Size |
68 | - | speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z)) |
68 | + | |
69 | - | speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz)) |
69 | + | -- round once for speaking |
70 | - | elseif distance > safedist then |
70 | + | local rd = math.floor(distance + 0.5) |
71 | local rt1x = math.floor(t1x + 0.5) | |
72 | - | speaker.speak("Target Dis: " .. tostring(distance)) |
72 | + | local rt1y = math.floor(t1y + 0.5) |
73 | - | speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z)) |
73 | + | local rt1z = math.floor(t1z + 0.5) |
74 | - | speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz)) |
74 | + | |
75 | if distance < safedist then | |
76 | print("Target is too Close! Shield Disabled!") | |
77 | trySpeak("Target is too Close! Shield Disabled!") | |
78 | shield.enable(false) | |
79 | trySpeak("Target Dis: " .. rd) | |
80 | trySpeak("Offset Coordinates: x=" .. rt1x .. ", y=" .. rt1y .. ", z=" .. rt1z) | |
81 | trySpeak("Laser Coordinates: x=" .. lastLx .. ", y=" .. lastLy .. ", z=" .. lastLz) | |
82 | else | |
83 | shield.translation(tx, ty, tz) | |
84 | trySpeak("Target Dis: " .. rd) | |
85 | - | elseif on < 5 then |
85 | + | trySpeak("Offset Coordinates: x=" .. rt1x .. ", y=" .. rt1y .. ", z=" .. rt1z) |
86 | trySpeak("Laser Coordinates: x=" .. lastLx .. ", y=" .. lastLy .. ", z=" .. lastLz) | |
87 | end | |
88 | ||
89 | elseif event == "redstone" then | |
90 | local fx, fy, fz = shield.getLocalPosition() | |
91 | local _, _, _, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz) | |
92 | local on = redstone.getAnalogInput(lever) | |
93 | if on > 6 and distance > safedist then | |
94 | shield.enable(true) | |
95 | elseif on > 6 and distance < safedist then | |
96 | print("Target is too Close! Shield Disabled!") | |
97 | trySpeak("Target is too Close! Shield Disabled!") | |
98 | shield.enable(false) | |
99 | else | |
100 | shield.enable(false) | |
101 | end | |
102 | ||
103 | elseif event == "key" and laserName == 46 then | |
104 | print("C key pressed, running 'conf' script...") | |
105 | shell.run("conf") | |
106 | end | |
107 | end | |
108 |