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 = 8 --Amount of Range Upgrades in Network, Including Relays
- local OffsetValue = 0 --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 == "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
- -- Laser scan target position
- local lx, ly, lz = laser.getScanResult()
- -- Shield position
- local fx, fy, fz = shield.getLocalPosition()
- function shieldOffset()
- -- Calculate direction vector from shield position to laser scan target position
- local dx = lx - fx
- local dy = ly - fy
- local dz = lz - fz
- -- Calculate the length of the direction vector
- local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
- -- Normalize the direction vector to have a length of 1 (unit vector)
- dx = dx / distance
- dy = dy / distance
- dz = dz / distance
- -- Calculate the final target position by extending the direction vector by OffsetValue
- local t1x = lx + dx * OffsetValue
- local t1y = ly + dy * OffsetValue
- local t1z = lz + dz * OffsetValue
- end
- 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) --disable shield if too close
- elseif distance > safedist then
- shield.translation(tx, ty, tz)
- end
- elseif event == "redstone" then
- dis()
- 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