Advertisement
jaklsfjlsak

激光制导护盾系统(反跳,采矿, 近距离报警,近距离关闭)

Jul 14th, 2023 (edited)
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(fs.exists("conf") == false) then
  2.     shell.run("pastebin get 38M5cNbZ conf")
  3.     term.clear()
  4. end
  5. local rangeUpgrade = 7 --Amount of Range Upgrades in Network, Including Relays
  6. local OffsetValue = 7 --How much you want your shield to be configured forward
  7. local shield = peripheral.find("warpdriveForceFieldProjector")
  8. local laser = peripheral.find("warpdriveLaserCamera")
  9. local lever = "front" -- format: front,back,left,right,top,bottom ONLY
  10. local safedist = 15 --Set Safe Distance
  11. -- Sets the frequency of the laser to 1420
  12. laser.beamFrequency(1420)
  13.  
  14. -- initial message
  15. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  16.  
  17.  
  18. local _, upgrades = shield.getUpgrades()
  19.  
  20. Size = rangeUpgrade * 16
  21.  
  22. while true do
  23.     os.sleep(0.5)
  24.     local event, key = os.pullEvent()    
  25.        
  26.     if event == "key" then
  27.         -- keys are represented by numbers, the number for 'C' is 46
  28.         if key == 46 then
  29.             print("C key pressed, running 'conf' script...")
  30.             shell.run("conf")
  31.         end
  32.     elseif event == "laserScanning" then
  33.         local type, lx, ly, lz, block = laser.getScanResult()
  34.         local fx, fy, fz = shield.getLocalPosition()
  35.        
  36.         t1x = lx - fx
  37.         t1y = ly - fy
  38.         t1z = lz - fz
  39.        
  40.         function shieldOffset()
  41.             if t1x > 0 then xfunc = -1
  42.             elseif t1x < 0 then xfunc = 1
  43.             elseif t1x == 0 then xfunc = 0
  44.             end
  45.             if t1y > 0 then yfunc = -1
  46.             elseif t1y < 0 then yfunc = 1
  47.             elseif t1y == 0 then yfunc = 0
  48.             end
  49.             if t1z > 0 then zfunc = -1
  50.             elseif t1z < 0 then zfunc = 1
  51.             elseif t1z == 0 then zfunc = 0
  52.             end
  53.         end
  54.         shieldOffset()
  55.        
  56.         function dis()
  57.             l1x = lx - (xfunc*OffsetValue)
  58.             l1y = ly - (yfunc*OffsetValue)
  59.             l1z = lz - (zfunc*OffsetValue)
  60.            
  61.             tx = (l1x-fx) / Size
  62.             ty = (l1y-fy) / Size
  63.             tz = (l1z-fz) / Size
  64.            
  65.             -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points
  66.             dx = l1x - fx
  67.             dy = l1y - fy
  68.             dz = l1z - fz
  69.  
  70.             distance = math.sqrt(dx*dx + dy*dy + dz*dz)
  71.         end
  72.         dis()
  73.         if distance < safedist then
  74.             print("Target is too Close! Shield Disabled!")
  75.             shield.enable(false) --disable shield if too close
  76.         elseif distance > safedist then
  77.             shield.translation(tx, ty, tz)
  78.         end
  79.     elseif event == "redstone" then
  80.         dis()
  81.         local on = redstone.getAnalogInput(lever)
  82.         if on > 6 and distance > safedist then
  83.             shield.enable(true)
  84.         elseif on > 6 and distance < safedist then
  85.             shield.enable(false)
  86.              print("Target is too Close! Shield Disabled!")
  87.         elseif on < 5 then
  88.             shield.enable(false)
  89.         end
  90.     end
  91. end
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement