fatboychummy

mobKiller.lua

Aug 15th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local time = 30
  2. local rsSide = "top"
  3.  
  4. -- below does not matter, auto-detected.
  5. local esSide = ""
  6.  
  7. local function switch()
  8.   rs.setOutput(rsSide, true)
  9.   os.sleep(0.5)
  10.   rs.setOutput(rsSide, false)
  11.   os.sleep(0.5)
  12. end
  13.  
  14. local function canRunEntitySensor()
  15.   for i, periph in ipairs(peripheral.getNames()) do
  16.     if peripheral.getType(periph) == "manipulator" then
  17.       esSide = periph
  18.       if peripheral.call(esSide, "hasModule", "plethora:sensor") then
  19.         return true
  20.       end
  21.     end
  22.   end
  23.   return false
  24. end
  25.  
  26. local function check()
  27.   local ents = peripheral.call(esSide, "sense")
  28.   for i, entity in ipairs(ents) do
  29.     if entity.x > 0 and entity.x < 2 and entity.z > 0 and entity.z < 2 then
  30.       return true
  31.     end
  32.   end
  33.   return false
  34. end
  35.  
  36.  
  37. local function main()
  38.   local entityCheck = canRunEntitySensor()
  39.   while true do
  40.     if entityCheck then
  41.       print("Checking entities...")
  42.       if check() then
  43.         print("Shooting.")
  44.         switch()
  45.         print("Done.")
  46.       end
  47.       os.sleep(3)
  48.     else
  49.       print("Shooting.")
  50.       switch()
  51.       print("Done. Waiting 30 seconds.")
  52.       os.sleep(30)
  53.     end
  54.   end
  55. end
  56.  
  57. main()
Add Comment
Please, Sign In to add comment