Advertisement
drpepper240

camforcefield v1

Apr 13th, 2024 (edited)
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local cam, fp1, fp2
  2. local tryWrap = true
  3. local wl = {"drPepper"}
  4.  
  5. while tryWrap do
  6.     if not cam then
  7.         local sides = peripheral.getNames()
  8.         for _, side in pairs(sides) do
  9.             if peripheral.getType(side) == "warpdriveCamera" then
  10.                 cam = peripheral.wrap(side)
  11.                 print("Wrapped warpdriveCamera on " .. side .. " side")
  12.             end
  13.         end
  14.     end
  15.  
  16.     if not fp1 then
  17.         if peripheral.getType("top") == "warpdriveForceFieldProjector" then
  18.             fp1 = peripheral.wrap("top")
  19.             print("Wrapped warpdriveForceFieldProjector 1")
  20.         end
  21.     end
  22.  
  23.     if not fp2 then
  24.         if peripheral.getType("bottom") == "warpdriveForceFieldProjector" then
  25.             fp2 = peripheral.wrap("bottom")
  26.             print("Wrapped warpdriveForceFieldProjector 2")
  27.         end
  28.     end
  29.  
  30.     if not cam or not fp1 or not fp2 then
  31.         sleep(2)
  32.     else
  33.         tryWrap = false
  34.     end
  35. end
  36.  
  37. --TODO set params for the peripherals
  38. local doEnable = false
  39.  
  40. while true do
  41.     local rCnt = cam.getResultsCount()
  42.    
  43.     doEnable = rCnt > 0
  44.     if not doEnable then
  45.         print(textutils.formatTime(os.time("local")), "Disabling...")
  46.         fp1.enable(false)
  47.         fp2.enable(false)
  48.     end
  49.    
  50.     for i_r = 0, rCnt-1 do
  51.         local ok, entityType, entityName = cam.getResult(i_r)
  52.         if ok then
  53.             print(textutils.formatTime(os.time("local")), entityName)
  54.             for _, name in pairs(wl) do
  55.                 if entityName == name then
  56.                     doEnable = false
  57.                     print("found " .. name)
  58.                 end
  59.             end
  60.         end
  61.     end
  62.    
  63.     if doEnable then
  64.         print("Firing...")
  65.         if not fp1.enable() then
  66.             fp1.enable(true)
  67.         end
  68.         --fp2.enable(true)
  69.         sleep(10)
  70.     else
  71.         sleep(0.5)
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement