Advertisement
jaklsfjlsak

激光护盾集成v2

Jul 12th, 2023
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local shield = peripheral.find("warpdriveForceFieldProjector")
  2. local laser = peripheral.find("warpdriveLaserCamera")
  3. -- Sets the frequency of the laser to 1420
  4. laser.beamFrequency(1420)
  5.  
  6. local state = true
  7.  
  8. -- initial message
  9. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  10.  
  11. local _, upgrades = shield.getUpgrades()
  12.  
  13. function getRange()
  14.     if upgrades:match("1/4 x Range") then
  15.         return 1
  16.     elseif upgrades:match("2/4 x Range") then
  17.         return 2
  18.     elseif upgrades:match("3/4 x Range") then
  19.         return 3
  20.     elseif upgrades:match("4/4 x Range") then
  21.         return 4
  22.     elseif upgrades:match("0/4 x Range") then
  23.         return 0
  24.     end
  25. end
  26.  
  27. Size = getRange() * 16
  28.  
  29. while true do
  30.     os.sleep(0.5)
  31.     local event, key = os.pullEvent()
  32.     if event == "redstone" then
  33.         if state == true then
  34.             shield.enable(true)
  35.             state = false
  36.         else
  37.             shield.enable(false)
  38.             state = true
  39.         end
  40.     elseif event == "key" then
  41.         -- keys are represented by numbers, the number for 'C' is 46
  42.         if key == 46 then
  43.             print("C key pressed, running 'conf' script...")
  44.             shell.run("conf")
  45.         end
  46.     elseif event == "laserScanning" then
  47.         local type, lx, ly, lz, block = laser.getScanResult()
  48.         local fx, fy, fz = shield.getLocalPosition()
  49.         tx = (lx-fx) / Size
  50.         ty = (ly-fy) / Size
  51.         tz = (lz-fz) / Size
  52.         shield.translation(tx, ty, tz)
  53.     end
  54. end
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement