Advertisement
jaklsfjlsak

726 sm v7

Jul 26th, 2023 (edited)
1,050
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. if fs.exists("conf") == false then
  2.     shell.run("pastebin get 38M5cNbZ conf")
  3.     term.clear()
  4. end
  5.  
  6. local OffsetValue = 3
  7. local shield = peripheral.find("warpdriveForceFieldProjector")
  8. local speaker = peripheral.find("warpdriveSpeaker")
  9. local lever = "front"
  10. local safedist = 15
  11.  
  12. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  13.  
  14. local _, upgrades = shield.getUpgrades()
  15.  
  16. function getRange()
  17.     if upgrades:match("1/4 x Range") then
  18.         return 1
  19.     elseif upgrades:match("2/4 x Range") then
  20.         return 2
  21.     elseif upgrades:match("3/4 x Range") then
  22.         return 3
  23.     elseif upgrades:match("4/4 x Range") then
  24.         return 4
  25.     elseif upgrades:match("0/4 x Range") then
  26.         return 0
  27.     end
  28. end
  29.  
  30. Size = getRange() * 16
  31.  
  32. -- function to update beam frequency for all the connected warpdriveLaserCamera peripherals
  33. local function updateLasersFrequency()
  34.     for _, name in ipairs(peripheral.getNames()) do
  35.         if peripheral.getType(name) == "warpdriveLaserCamera" then
  36.             local laser = peripheral.wrap(name)
  37.             laser.beamFrequency(1420)
  38.         end
  39.     end
  40. end
  41.  
  42. -- function to process the scanning results from all the available lasers
  43. local function processScanningResults()
  44.     for _, name in ipairs(peripheral.getNames()) do
  45.         if peripheral.getType(name) == "warpdriveLaserCamera" then
  46.             local type, lx, ly, lz, block = peripheral.wrap(name).getScanResult()
  47.             lx, ly, lz = tonumber(lx), tonumber(ly), tonumber(lz)
  48.             if lx and lx ~= 0 and ly and ly ~= 0 and lz and lz ~= 0 then
  49.                 -- the rest of your processing code goes here
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. while true do
  56.     local event, lx, ly, lz = os.pullEvent()
  57.  
  58.     if event == "key" and lx == 46 then
  59.         print("C key pressed, running 'conf' script...")
  60.         shell.run("conf")
  61.     end
  62.  
  63.     if event == "laserScanning" then
  64.         updateLasersFrequency()
  65.         processScanningResults()
  66.     elseif event == "redstone" then
  67.         local _, _, _, distance = shieldOffset()
  68.         local on = redstone.getAnalogInput(lever)
  69.         if on > 6 and distance > safedist then
  70.             shield.enable(true)
  71.         elseif on > 6 and distance < safedist then
  72.             shield.enable(false)
  73.             print("Target is too Close! Shield Disabled!")
  74.         elseif on < 5 then
  75.             shield.enable(false)
  76.         end
  77.     end
  78. end
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement