Advertisement
Guest User

feeder

a guest
Dec 17th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. local sensor = peripheral.wrap("right")
  2. local rsSide = "back"
  3. local count = {}
  4. local specie = "Sheep"
  5. local min = 16
  6.  
  7. function enableFeeder()
  8.   rs.SetOutput(rsSide, false)
  9.   print("Feeder enabled.")
  10. end
  11.  
  12. function disableFeeder()
  13.   rs.setOutput(rsSide, true)
  14.   print("Feeder disabled.")
  15. end
  16.  
  17. function reset()
  18.   count=0
  19. end
  20.  
  21. function add()
  22.   count = count +1
  23. end
  24.  
  25. function registerMob(id)
  26.   if pcall(function() mob = sensor.getMobData(id) end) then
  27.     local type = mob.name
  28.     --print(type.." found.")
  29.     if type==specie then
  30.       add()
  31.     end
  32.   else
  33.     print("error fetching fleeing animal.")
  34.   end
  35. end
  36.  
  37. while true do
  38.   reset()
  39.   for i,j in pairs(sensor.getMobIds()) do  
  40.     registerMob(j)
  41.   end
  42.   if count<min then
  43.     print(specie.."s count : "..count.." < "..min)
  44.     enableFeeder()
  45.   else
  46.     print(specie.."s count : "..count.." >= "..min)
  47.     disableFeeder()
  48.   end
  49.   sleep(30)
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement