Advertisement
jaklsfjlsak

激光护盾技术验证 集成体v1改

Jul 12th, 2023 (edited)
955
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 jtu7T4Ri conf")
  3.     term.clear()
  4. end
  5. local shield = peripheral.find("warpdriveForceFieldProjector")
  6. local laser = peripheral.find("warpdriveLaserCamera")
  7. local lever = "front" -- format: front,back,left,right,top,bottom ONLY
  8. -- Sets the frequency of the laser to 1420
  9. laser.beamFrequency(1420)
  10.  
  11. -- initial message
  12. print("Control System Online, Toggle Redstone To Toggle Shields, Press C to Configure")
  13.  
  14.  
  15. local _, upgrades = shield.getUpgrades()
  16.  
  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. while true do
  34.     os.sleep(0.5)
  35.     local event, key = os.pullEvent()
  36.     if event == "redstone" then
  37.         local on = redstone.getAnalogInput(lever)
  38.         if on > 6 then
  39.             shield.enable(false)
  40.  
  41.         elseif on < 5 then
  42.             shield.enable(true)
  43.  
  44.         end
  45.     elseif event == "key" then
  46.         -- keys are represented by numbers, the number for 'C' is 46
  47.         if key == 46 then
  48.             print("C key pressed, running 'conf' script...")
  49.             shell.run("conf")
  50.         end
  51.     elseif event == "laserScanning" then
  52.         local type, lx, ly, lz, block = laser.getScanResult()
  53.         local fx, fy, fz = shield.getLocalPosition()
  54.         tx = (lx-fx) / Size
  55.         ty = (ly-fy) / Size
  56.         tz = (lz-fz) / Size
  57.         shield.translation(tx, ty, tz)
  58.     end
  59. end
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement