Advertisement
jaklsfjlsak

简化护盾制导

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