SHOW:
|
|
- or go back to the newest paste.
1 | if fs.exists("conf") == false then | |
2 | shell.run("pastebin get 38M5cNbZ conf") | |
3 | term.clear() | |
4 | end | |
5 | ||
6 | - | local OffsetValue = 3 |
6 | + | |
7 | local lasers = peripheral.getNames() -- get all peripherals | |
8 | local lever = "front" | |
9 | local safedist = 15 | |
10 | local distance -- Initialize here | |
11 | ||
12 | -- filter only warpdriveLaserCamera peripherals | |
13 | for i=#lasers, 1, -1 do | |
14 | if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then | |
15 | table.remove(lasers, i) | |
16 | else | |
17 | peripheral.wrap(lasers[i]).beamFrequency(1420) | |
18 | end | |
19 | end | |
20 | ||
21 | print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure") | |
22 | ||
23 | local _, upgrades = shield.getUpgrades() | |
24 | ||
25 | function getRange() | |
26 | if upgrades:match("1/4 x Range") then | |
27 | return 1 | |
28 | elseif upgrades:match("2/4 x Range") then | |
29 | return 2 | |
30 | elseif upgrades:match("3/4 x Range") then | |
31 | return 3 | |
32 | elseif upgrades:match("4/4 x Range") then | |
33 | return 4 | |
34 | elseif upgrades:match("0/4 x Range") then | |
35 | return 0 | |
36 | end | |
37 | end | |
38 | ||
39 | Size = getRange() * 16 | |
40 | ||
41 | function dis(lx, ly, lz, fx, fy, fz) | |
42 | local dx = lx - fx | |
43 | local dy = ly - fy | |
44 | local dz = lz - fz | |
45 | local distance = math.sqrt(dx * dx + dy * dy + dz * dz) | |
46 | return distance | |
47 | end | |
48 | ||
49 | while true do | |
50 | for _, laserName in ipairs(lasers) do | |
51 | local laser = peripheral.wrap(laserName) | |
52 | local event, key = os.pullEvent() | |
53 | os.sleep(0.5) | |
54 | ||
55 | if event == "key" then | |
56 | if key == 46 then | |
57 | print("C key pressed, running 'conf' script...") | |
58 | shell.run("conf") | |
59 | - | function shieldOffset() |
59 | + | |
60 | - | local dx = lx - fx |
60 | + | |
61 | - | local dy = ly - fy |
61 | + | |
62 | - | local dz = lz - fz |
62 | + | |
63 | - | local distance = math.sqrt(dx * dx + dy * dy + dz * dz) |
63 | + | |
64 | - | dx = dx / distance |
64 | + | |
65 | - | dy = dy / distance |
65 | + | |
66 | - | dz = dz / distance |
66 | + | |
67 | - | local t1x = lx + dx * OffsetValue |
67 | + | tx = (lx - fx) / Size |
68 | - | local t1y = ly + dy * OffsetValue |
68 | + | ty = (ly - fy) / Size |
69 | - | local t1z = lz + dz * OffsetValue |
69 | + | tz = (lz - fz) / Size |
70 | - | return t1x, t1y, t1z, distance |
70 | + | |
71 | distance = dis(lx, ly, lz, fx, fy, fz) -- Update the value here | |
72 | ||
73 | - | local t1x, t1y, t1z, distance = shieldOffset() |
73 | + | |
74 | print("Target is too Close! Shield Disabled!") | |
75 | - | tx = (t1x - fx) / Size |
75 | + | |
76 | - | ty = (t1y - fy) / Size |
76 | + | |
77 | - | tz = (t1z - fz) / Size |
77 | + | |
78 | end | |
79 | elseif event == "redstone" then | |
80 | local on = redstone.getAnalogInput(lever) | |
81 | if on > 6 and distance > safedist then | |
82 | shield.enable(true) | |
83 | elseif on > 6 and distance < safedist then | |
84 | shield.enable(false) | |
85 | print("Target is too Close! Shield Disabled!") | |
86 | - | local _, _, _, distance = shieldOffset() |
86 | + | |
87 | shield.enable(false) | |
88 | end | |
89 | end | |
90 | end | |
91 | end | |
92 |