Advertisement
jaklsfjlsak

8/7 水平采矿 25年测试可用

Aug 8th, 2023 (edited)
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. local OffsetValue = 3
  2. local shield = peripheral.find("warpdriveForceFieldProjector")
  3. local lasers = peripheral.getNames()
  4. local speaker = peripheral.find("warpdriveSpeaker")
  5. local lever = "front"
  6. local safedist = 15
  7. local lastLx, lastLy, lastLz = 0, 0, 0
  8.  
  9. function shieldOffset(lx, ly, lz, fx, fy, fz)
  10.     local dx = lx - fx
  11.     local dy = ly - fy
  12.     local dz = lz - fz
  13.     local distance = math.sqrt(dx * dx + dy * dy + dz * dz)
  14.     dx = dx / distance
  15.     dy = dy / distance
  16.     dz = dz / distance
  17.     local t1x = lx + dx * OffsetValue
  18.     local t1y = ly + dy * OffsetValue
  19.     local t1z = lz + dz * OffsetValue
  20.     return t1x, t1y, t1z, distance
  21. end
  22.  
  23. if fs.exists("conf") == false then
  24.     shell.run("pastebin get 38M5cNbZ conf")
  25.     term.clear()
  26. end
  27.  
  28. for i = #lasers, 1, -1 do
  29.     if peripheral.getType(lasers[i]) ~= "warpdriveLaserCamera" then
  30.         table.remove(lasers, i)
  31.     else
  32.         peripheral.wrap(lasers[i]).beamFrequency(1420)
  33.     end
  34. end
  35.  
  36. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  37.  
  38. local _, upgrades = shield.getUpgrades()
  39. local Size
  40. if upgrades:match("1/4 x Range") then
  41.     Size = 16
  42. elseif upgrades:match("2/4 x Range") then
  43.     Size = 32
  44. elseif upgrades:match("3/4 x Range") then
  45.     Size = 48
  46. elseif upgrades:match("4/4 x Range") then
  47.     Size = 64
  48. elseif upgrades:match("0/4 x Range") then
  49.     Size = 0
  50. end
  51.  
  52. while true do
  53.     local event, laserName, lx, ly, lz, block, _, _, _, type, metadata, resistance = os.pullEvent()
  54.  
  55.     if event == "laserScanning" then
  56.         lastLx, lastLy, lastLz = tonumber(lx), tonumber(ly), tonumber(lz)
  57.         local fx, fy, fz = shield.getLocalPosition()
  58.         local t1x, t1y, t1z, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz)
  59.  
  60.         tx = (t1x - fx) / Size
  61.         ty = (t1y - fy) / Size
  62.         tz = (t1z - fz) / Size
  63.  
  64.         if distance < safedist then
  65.             print("Target is too Close! Shield Disabled!")
  66.             shield.enable(false)
  67.             speaker.speak("Target Dis: " .. tostring(distance))
  68.             speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
  69.             speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz))
  70.         elseif distance > safedist then
  71.             shield.translation(tx, ty, tz)
  72.             speaker.speak("Target Dis: " .. tostring(distance))
  73.             speaker.speak("Offset Coordinates: x=" .. tostring(t1x) .. ", y=" .. tostring(t1y) .. ", z=" .. tostring(t1z))
  74.             speaker.speak("Laser Coordinates: x=" .. tostring(lastLx) .. ", y=" .. tostring(lastLy) .. ", z=" .. tostring(lastLz))
  75.         end
  76.     elseif event == "redstone" then
  77.         local fx, fy, fz = shield.getLocalPosition()
  78.         local _, _, _, distance = shieldOffset(lastLx, lastLy, lastLz, fx, fy, fz)
  79.         local on = redstone.getAnalogInput(lever)
  80.         if on > 6 and distance > safedist then
  81.             shield.enable(true)
  82.         elseif on > 6 and distance < safedist then
  83.             shield.enable(false)
  84.             print("Target is too Close! Shield Disabled!")
  85.         elseif on < 5 then
  86.             shield.enable(false)
  87.         end
  88.     elseif event == "key" and laserName == 46 then
  89.         print("C key pressed, running 'conf' script...")
  90.         shell.run("conf")
  91.     end
  92. end
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement