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 rangeUpgrade = 7 --Amount of Range Upgrades in Network, Including Relays
- local OffsetValue = 7 --How much you want your shield to be configured forward
- local shield = peripheral.find("warpdriveForceFieldProjector")
- local laser = peripheral.find("warpdriveLaserCamera")
- local lever = "front" -- format: front,back,left,right,top,bottom ONLY
- local safedist = 15 --Set Safe Distance
- -- Sets the frequency of the laser to 1420
- laser.beamFrequency(1420)
- -- initial message
- print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
- local _, upgrades = shield.getUpgrades()
- Size = rangeUpgrade * 16
- while true do
- os.sleep(0.5)
- local event, key = os.pullEvent()
- if event == "redstone" then
- local on = redstone.getAnalogInput(lever)
- if on > 6 then
- shield.enable(true)
- elseif on < 5 then
- shield.enable(false)
- end
- elseif event == "key" then
- -- keys are represented by numbers, the number for 'C' is 46
- if key == 46 then
- print("C key pressed, running 'conf' script...")
- shell.run("conf")
- end
- elseif event == "laserScanning" then
- local type, lx, ly, lz, block = laser.getScanResult()
- local fx, fy, fz = shield.getLocalPosition()
- t1x = lx - fx
- t1y = ly - fy
- t1z = lz - fz
- function shieldOffset()
- if t1x > 0 then xfunc = -1
- elseif t1x < 0 then xfunc = 1
- elseif t1x == 0 then xfunc = 0
- end
- if t1y > 0 then yfunc = -1
- elseif t1y < 0 then yfunc = 1
- elseif t1y == 0 then yfunc = 0
- end
- if t1z > 0 then zfunc = -1
- elseif t1z < 0 then zfunc = 1
- elseif t1z == 0 then zfunc = 0
- end
- end
- shieldOffset()
- l1x = lx - (xfunc*OffsetValue)
- l1y = ly - (yfunc*OffsetValue)
- l1z = lz - (zfunc*OffsetValue)
- tx = (l1x-fx) / Size
- ty = (l1y-fy) / Size
- tz = (l1z-fz) / Size
- -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points
- local dx = l1x - fx
- local dy = l1y - fy
- local dz = l1z - fz
- local distance = math.sqrt(dx*dx + dy*dy + dz*dz)
- if distance < safedist then
- print("Target is too Close!")
- elseif distance > safedist then
- shield.translation(tx, ty, tz)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement