Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local OffsetValue = -3
- local shield = peripheral.find("warpdriveForceFieldProjector")
- local lasers = peripheral.getNames()
- local lever = "front"
- local lastLx, lastLy, lastLz = 0, 0, 0
- -- Calculate the offset position (still using OffsetValue)
- function shieldOffset(lx, ly, lz, fx, fy, fz)
- 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
- -- Download configuration file if missing.
- if not fs.exists("conf") then
- shell.run("pastebin get 38M5cNbZ conf")
- term.clear()
- end
- -- Filter peripherals: keep only warpdriveLaserCameras and set their beam frequency.
- for i = #lasers, 1, -1 do
- if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
- table.remove(lasers, i)
- else
- peripheral.wrap(lasers[i]).beamFrequency(1420)
- end
- end
- print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
- -- Determine shield range based on upgrades.
- local _, upgrades = shield.getUpgrades()
- local Size
- if upgrades:match("1/4 x Range") then
- Size = 16
- elseif upgrades:match("2/4 x Range") then
- Size = 32
- elseif upgrades:match("3/4 x Range") then
- Size = 48
- elseif upgrades:match("4/4 x Range") then
- Size = 64
- elseif upgrades:match("0/4 x Range") then
- Size = 0
- end
- while true do
- local event, keyOrLaser, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
- if event == "laserScanning" then
- lastLx, lastLy, lastLz = tonumber(lx), tonumber(ly), tonumber(lz)
- local fx, fy, fz = shield.getLocalPosition()
- local t1x, t1y, t1z, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz)
- local tx = (t1x - fx) / Size
- local ty = (t1y - fy) / Size
- local tz = (t1z - fz) / Size
- shield.translation(tx, ty, tz)
- print("Laser Coordinates: (" .. lastLx .. ", " .. lastLy .. ", " .. lastLz .. ")")
- print("Translated to: (" .. tx .. ", " .. ty .. ", " .. tz .. ")")
- elseif 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" and keyOrLaser == 46 then
- print("C key pressed, running 'conf' script...")
- shell.run("conf")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement