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 | - | function getRange() |
| 17 | + | |
| 18 | - | if upgrades:match("1/4 x Range") then
|
| 18 | + | |
| 19 | - | return 1 |
| 19 | + | |
| 20 | - | elseif upgrades:match("2/4 x Range") then
|
| 20 | + | |
| 21 | - | return 2 |
| 21 | + | |
| 22 | - | elseif upgrades:match("3/4 x Range") then
|
| 22 | + | Size = rangeUpgrade * 16 |
| 23 | - | return 3 |
| 23 | + | |
| 24 | - | elseif upgrades:match("4/4 x Range") then
|
| 24 | + | |
| 25 | - | return 4 |
| 25 | + | |
| 26 | - | elseif upgrades:match("0/4 x Range") then
|
| 26 | + | |
| 27 | - | return 0 |
| 27 | + | |
| 28 | local event, key = os.pullEvent() | |
| 29 | if event == "redstone" then | |
| 30 | local on = redstone.getAnalogInput(lever) | |
| 31 | - | Size = getRange() * 16 |
| 31 | + | |
| 32 | shield.enable(true) | |
| 33 | ||
| 34 | elseif on < 5 then | |
| 35 | shield.enable(false) | |
| 36 | ||
| 37 | end | |
| 38 | elseif event == "key" then | |
| 39 | -- keys are represented by numbers, the number for 'C' is 46 | |
| 40 | if key == 46 then | |
| 41 | print("C key pressed, running 'conf' script...")
| |
| 42 | shell.run("conf")
| |
| 43 | end | |
| 44 | elseif event == "laserScanning" then | |
| 45 | local type, lx, ly, lz, block = laser.getScanResult() | |
| 46 | local fx, fy, fz = shield.getLocalPosition() | |
| 47 | ||
| 48 | t1x = lx - fx | |
| 49 | t1y = ly - fy | |
| 50 | t1z = lz - fz | |
| 51 | ||
| 52 | function shieldOffset() | |
| 53 | if t1x > 0 then xfunc = -1 | |
| 54 | - | tx = (lx-fx) / Size |
| 54 | + | elseif t1x < 0 then xfunc = 1 |
| 55 | - | ty = (ly-fy) / Size |
| 55 | + | elseif t1x == 0 then xfunc = 0 |
| 56 | - | tz = (lz-fz) / Size |
| 56 | + | end |
| 57 | - | shield.translation(tx, ty, tz) |
| 57 | + | if t1y > 0 then yfunc = -1 |
| 58 | elseif t1y < 0 then yfunc = 1 | |
| 59 | elseif t1y == 0 then yfunc = 0 | |
| 60 | end | |
| 61 | if t1z > 0 then zfunc = -1 | |
| 62 | elseif t1z < 0 then zfunc = 1 | |
| 63 | elseif t1z == 0 then zfunc = 0 | |
| 64 | end | |
| 65 | end | |
| 66 | shieldOffset() | |
| 67 | ||
| 68 | l1x = lx - (xfunc*OffsetValue) | |
| 69 | l1y = ly - (yfunc*OffsetValue) | |
| 70 | l1z = lz - (zfunc*OffsetValue) | |
| 71 | ||
| 72 | ||
| 73 | tx = (l1x-fx) / Size | |
| 74 | ty = (l1y-fy) / Size | |
| 75 | tz = (l1z-fz) / Size | |
| 76 | ||
| 77 | -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points | |
| 78 | local dx = l1x - fx | |
| 79 | local dy = l1y - fy | |
| 80 | local dz = l1z - fz | |
| 81 | ||
| 82 | local distance = math.sqrt(dx*dx + dy*dy + dz*dz) | |
| 83 | ||
| 84 | ||
| 85 | if distance < safedist then | |
| 86 | print("Target is too Close!")
| |
| 87 | elseif distance > safedist then | |
| 88 | shield.translation(tx, ty, tz) | |
| 89 | end | |
| 90 | ||
| 91 | end | |
| 92 | end | |
| 93 | ||
| 94 |