Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if fs.exists("conf") == false then
- shell.run("pastebin get 38M5cNbZ conf")
- term.clear()
- end
- local OffsetValue = 3
- local shield = peripheral.find("warpdriveForceFieldProjector")
- local speaker = peripheral.find("warpdriveSpeaker")
- local lever = "front"
- local safedist = 15
- print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
- local _, upgrades = shield.getUpgrades()
- function getRange()
- if upgrades:match("1/4 x Range") then
- return 1
- elseif upgrades:match("2/4 x Range") then
- return 2
- elseif upgrades:match("3/4 x Range") then
- return 3
- elseif upgrades:match("4/4 x Range") then
- return 4
- elseif upgrades:match("0/4 x Range") then
- return 0
- end
- end
- Size = getRange() * 16
- while true do
- local event, peripheralName, lx, ly, lz = os.pullEvent()
- if event == "key" and peripheralName == 46 then
- print("C key pressed, running 'conf' script...")
- shell.run("conf")
- end
- if event == "laserScanning" then
- local laser = peripheral.wrap(peripheralName)
- --laser.beamFrequency(1420)
- local type, lx, ly, lz, block = laser.getScanResult()
- lx, ly, lz = tonumber(lx), tonumber(ly), tonumber(lz)
- local fx, fy, fz = shield.getLocalPosition()
- function shieldOffset()
- local dx = lx - fx
- local dy = ly - fy
- local dz = lz - fz
- local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
- dx = dx / distance
- dy = dy / distance
- dz = dz / distance
- local t1x = lx + dx * OffsetValue
- local t1y = ly + dy * OffsetValue
- local t1z = lz + dz * OffsetValue
- return t1x, t1y, t1z, distance
- end
- local t1x, t1y, t1z, distance = shieldOffset()
- tx = (t1x - fx) / Size
- ty = (t1y - fy) / Size
- tz = (t1z - fz) / Size
- if distance < safedist then
- print("Target is too Close! Shield Disabled!")
- shield.enable(false)
- speaker.speak("Target Dis: " .. tostring(distance))
- speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
- speaker.speak("Laser Coordinates: x=" .. tostring(lx) .. ", y=" .. tostring(ly) .. ", z=" .. tostring(lz))
- elseif distance > safedist then
- shield.translation(tx, ty, tz)
- speaker.speak("Target Dis: " .. tostring(distance))
- speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
- speaker.speak("Laser Coordinates: x=" .. tostring(lx) .. ", y=" .. tostring(ly) .. ", z=" .. tostring(lz))
- end
- elseif event == "redstone" then
- local _, _, _, distance = shieldOffset()
- local on = redstone.getAnalogInput(lever)
- if on > 6 and distance > safedist then
- shield.enable(true)
- elseif on > 6 and distance < safedist then
- shield.enable(false)
- print("Target is too Close! Shield Disabled!")
- elseif on < 5 then
- shield.enable(false)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement