Advertisement
jaklsfjlsak

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

Jul 13th, 2023 (edited)
562
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.  
  21.  
  22. Size = rangeUpgrade * 16
  23.  
  24.  
  25.  
  26. while true do
  27.     os.sleep(0.5)
  28.     local event, key = os.pullEvent()
  29.     if event == "redstone" then
  30.         local on = redstone.getAnalogInput(lever)
  31.         if on > 6 then
  32.             shield.enable(true)
  33.  
  34.         elseif on < 5 then
  35.             shield.enable(false)
  36.  
  37.         end
  38.     elseif event == "key" then
  39.         -- keys are represented by numbers, the number for 'C' is 46
  40.         if key == 46 then
  41.             print("C key pressed, running 'conf' script...")
  42.             shell.run("conf")
  43.         end
  44.     elseif event == "laserScanning" then
  45.         local type, lx, ly, lz, block = laser.getScanResult()
  46.         local fx, fy, fz = shield.getLocalPosition()
  47.        
  48.         t1x = lx - fx
  49.         t1y = ly - fy
  50.         t1z = lz - fz
  51.        
  52.         function shieldOffset()
  53.             if t1x > 0 then xfunc = -1
  54.             elseif t1x < 0 then xfunc = 1
  55.             elseif t1x == 0 then xfunc = 0
  56.             end
  57.             if t1y > 0 then yfunc = -1
  58.             elseif t1y < 0 then yfunc = 1
  59.             elseif t1y == 0 then yfunc = 0
  60.             end
  61.             if t1z > 0 then zfunc = -1
  62.             elseif t1z < 0 then zfunc = 1
  63.             elseif t1z == 0 then zfunc = 0
  64.             end
  65.         end
  66.         shieldOffset()
  67.        
  68.         l1x = lx - (xfunc*OffsetValue)
  69.         l1y = ly - (yfunc*OffsetValue)
  70.         l1z = lz - (zfunc*OffsetValue)
  71.        
  72.        
  73.         tx = (l1x-fx) / Size
  74.         ty = (l1y-fy) / Size
  75.         tz = (l1z-fz) / Size
  76.        
  77.         -- Assuming (lx, ly, lz) and (fx, fy, fz) are the coordinates of your two points
  78.         local dx = l1x - fx
  79.         local dy = l1y - fy
  80.         local dz = l1z - fz
  81.  
  82.         local distance = math.sqrt(dx*dx + dy*dy + dz*dz)
  83.        
  84.  
  85.         if distance < safedist then
  86.             print("Target is too Close!")
  87.         elseif distance > safedist then
  88.             shield.translation(tx, ty, tz)
  89.         end
  90.        
  91.     end
  92. end
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement