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 | local rangeUpgrade = 7 --Amount of Range Upgrades in Network, Including Relays | |
6 | local OffsetValue = 7 --How much you want your shield to be configured forward | |
7 | local shield = peripheral.find("warpdriveForceFieldProjector") | |
8 | local laser = peripheral.find("warpdriveLaserCamera") | |
9 | local lever = "front" -- format: front,back,left,right,top,bottom ONLY | |
10 | local safedist = 15 --Set Safe Distance | |
11 | -- Sets the frequency of the laser to 1420 | |
12 | laser.beamFrequency(1420) | |
13 | ||
14 | -- initial message | |
15 | print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure") | |
16 | ||
17 | ||
18 | local _, upgrades = shield.getUpgrades() | |
19 | ||
20 | Size = rangeUpgrade * 16 | |
21 | ||
22 | while true do | |
23 | os.sleep(0.5) | |
24 | local event, key = os.pullEvent() | |
25 | ||
26 | if event == "key" then | |
27 | -- keys are represented by numbers, the number for 'C' is 46 | |
28 | - | local event, key = os.pullEvent() |
28 | + | |
29 | - | if event == "redstone" then |
29 | + | |
30 | shell.run("conf") | |
31 | - | if on > 6 then |
31 | + | |
32 | elseif event == "laserScanning" then | |
33 | local type, lx, ly, lz, block = laser.getScanResult() | |
34 | local fx, fy, fz = shield.getLocalPosition() | |
35 | ||
36 | - | |
36 | + | |
37 | t1y = ly - fy | |
38 | - | elseif event == "key" then |
38 | + | |
39 | ||
40 | function shieldOffset() | |
41 | if t1x > 0 then xfunc = -1 | |
42 | elseif t1x < 0 then xfunc = 1 | |
43 | elseif t1x == 0 then xfunc = 0 | |
44 | end | |
45 | if t1y > 0 then yfunc = -1 | |
46 | elseif t1y < 0 then yfunc = 1 | |
47 | elseif t1y == 0 then yfunc = 0 | |
48 | end | |
49 | if t1z > 0 then zfunc = -1 | |
50 | elseif t1z < 0 then zfunc = 1 | |
51 | elseif t1z == 0 then zfunc = 0 | |
52 | end | |
53 | end | |
54 | shieldOffset() | |
55 | ||
56 | function dis() | |
57 | l1x = lx - (xfunc*OffsetValue) | |
58 | l1y = ly - (yfunc*OffsetValue) | |
59 | l1z = lz - (zfunc*OffsetValue) | |
60 | ||
61 | tx = (l1x-fx) / Size | |
62 | ty = (l1y-fy) / Size | |
63 | tz = (l1z-fz) / Size | |
64 | ||
65 | -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points | |
66 | dx = l1x - fx | |
67 | dy = l1y - fy | |
68 | - | l1x = lx - (xfunc*OffsetValue) |
68 | + | dz = l1z - fz |
69 | - | l1y = ly - (yfunc*OffsetValue) |
69 | + | |
70 | - | l1z = lz - (zfunc*OffsetValue) |
70 | + | distance = math.sqrt(dx*dx + dy*dy + dz*dz) |
71 | end | |
72 | dis() | |
73 | - | tx = (l1x-fx) / Size |
73 | + | |
74 | - | ty = (l1y-fy) / Size |
74 | + | print("Target is too Close! Shield Disabled!") |
75 | - | tz = (l1z-fz) / Size |
75 | + | shield.enable(false) --disable shield if too close |
76 | elseif distance > safedist then | |
77 | - | -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points |
77 | + | |
78 | - | local dx = l1x - fx |
78 | + | |
79 | - | local dy = l1y - fy |
79 | + | elseif event == "redstone" then |
80 | - | local dz = l1z - fz |
80 | + | dis() |
81 | local on = redstone.getAnalogInput(lever) | |
82 | - | local distance = math.sqrt(dx*dx + dy*dy + dz*dz) |
82 | + | if on > 6 and distance > safedist then |
83 | shield.enable(true) | |
84 | elseif on > 6 and distance < safedist then | |
85 | shield.enable(false) | |
86 | - | print("Target is too Close!") |
86 | + | print("Target is too Close! Shield Disabled!") |
87 | elseif on < 5 then | |
88 | shield.enable(false) | |
89 | end | |
90 | end | |
91 | end | |
92 |