Advertisement
jaklsfjlsak

护盾采矿2

Jul 12th, 2023
1,114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.87 KB | None | 0 0
  1. -- detects if there even is a force field attached
  2. local shield = peripheral.find("warpdriveForceFieldProjector")
  3.  
  4. if not shield then
  5.     print("No Force Field Projector Connected.")
  6.     return
  7. end
  8.  
  9. if shield.isInterfaced() == false then
  10.     print("No Computer Interface Upgrade Installed.")
  11.     return
  12. end
  13.  
  14. local _, upgrades = shield.getUpgrades()
  15.  
  16. -- this function is really janky but I don't want to make it better
  17. function getRange()
  18.     if upgrades:match("1/4 x Range") then
  19.         return 1
  20.     elseif upgrades:match("2/4 x Range") then
  21.         return 2
  22.     elseif upgrades:match("3/4 x Range") then
  23.         return 3
  24.     elseif upgrades:match("4/4 x Range") then
  25.         return 4
  26.     elseif upgrades:match("0/4 x Range") then
  27.         return 0
  28.     end
  29. end
  30.  
  31. Size = getRange() * 16
  32.  
  33. function getTranslation()
  34.     if upgrades:match("1/1 x Translation") then
  35.         return true
  36.     elseif upgrades:match("0/1 x Translation") then
  37.         print("No Translation Upgrade Installed.")
  38.         return false
  39.     end
  40. end
  41.  
  42. function position()
  43.     local laser = peripheral.find("warpdriveLaserCamera")
  44.    
  45.     if not laser then
  46.         print("No Warpdrive Laser Camera detected.")
  47.         return
  48.     end
  49.  
  50.     -- Sets the frequency of the laser to 1420
  51.     laser.beamFrequency(1420)
  52.    
  53.     while true do
  54.         -- Waits for a "laserScanning" event
  55.         local event = os.pullEvent()
  56.        
  57.         -- If event is not a "laserScanning" event, continue the loop
  58.         if event ~= "laserScanning" then
  59.             do continue end
  60.         end
  61.        
  62.         local type, lx, ly, lz, block = laser.getScanResult()
  63.         local fx, fy, fz = shield.getLocalPosition()
  64.                
  65.         shield.translation(lx-fx, ly-fy, lz-fz)
  66.         print("Shield has been adjusted accordingly.")
  67.     end
  68. end
  69.  
  70. -- Call the position function
  71. position()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement