Advertisement
systox

mobfarmcounter

Feb 19th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.36 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. function initialize()
  4.     prox = sensor.wrap("left")
  5.     output = "back"
  6.     state = {}
  7.     state_old = {}
  8.     pre = 0
  9.     start = true
  10. end
  11.  
  12. function getPigmenCount(sensor_data)
  13.     local count = 0
  14.     if (sensor_data ~= nil) then
  15.         for name, info in pairs(sensor_data) do         --åBCberpråBCfe alle targets
  16.             if (info.Name == "Slime") then      --wenn Zombie Pigman
  17.                 count = count + 1                       --dann erhåB6he
  18.             end
  19.         end
  20.     end
  21.     return count
  22. end
  23.  
  24. function updateState()
  25.     local data = prox.getTargets()
  26.     local st = {}
  27.     st.pigmen = getPigmenCount(data)
  28.     return st
  29. end
  30.  
  31. initialize()
  32. while true do
  33.     state = updateState()
  34.  
  35.     if start then
  36.         start = false
  37.         if state.pigmen == 0 then
  38.             release = true
  39.         end
  40.     end
  41.    
  42.     if (state ~= state_old) then
  43.        
  44.         count = state.pigmen
  45.        
  46.         if count < pre and count < 2 then
  47.             release = true
  48.             print("release!")
  49.         end
  50.        
  51.         if count > pre then
  52.             release = false
  53.         end
  54.  
  55.         if pre ~= count then
  56.             print("pre: "..pre)
  57.             pre = count
  58.             print("setting pre to "..pre)
  59.         end
  60.        
  61.         if release then
  62.             rs.setOutput(output,true)
  63.         else
  64.             rs.setOutput(output,false)
  65.         end
  66.         print(state.pigmen)
  67.     end
  68.     state_old = state
  69.     sleep(0.5)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement