Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- function initialize()
- prox = sensor.wrap("left")
- output = "back"
- state = {}
- state_old = {}
- pre = 0
- start = true
- end
- function getPigmenCount(sensor_data)
- local count = 0
- if (sensor_data ~= nil) then
- for name, info in pairs(sensor_data) do --åBCberpråBCfe alle targets
- if (info.Name == "Slime") then --wenn Zombie Pigman
- count = count + 1 --dann erhåB6he
- end
- end
- end
- return count
- end
- function updateState()
- local data = prox.getTargets()
- local st = {}
- st.pigmen = getPigmenCount(data)
- return st
- end
- initialize()
- while true do
- state = updateState()
- if start then
- start = false
- if state.pigmen == 0 then
- release = true
- end
- end
- if (state ~= state_old) then
- count = state.pigmen
- if count < pre and count < 2 then
- release = true
- print("release!")
- end
- if count > pre then
- release = false
- end
- if pre ~= count then
- print("pre: "..pre)
- pre = count
- print("setting pre to "..pre)
- end
- if release then
- rs.setOutput(output,true)
- else
- rs.setOutput(output,false)
- end
- print(state.pigmen)
- end
- state_old = state
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement