neo34rd

test.lua

Mar 24th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1.  
  2. sensor = peripheral.wrap("right") ---Sensor always to be placed on the right side of the turtle
  3.  
  4. attackState = false
  5.  
  6. function gotoAttackState()
  7. if attackState then
  8. turtle.attack()
  9. return
  10. else
  11. attackState = true
  12. turtle.down()
  13. end
  14. end
  15.  
  16. function gotoGuardState()
  17. if attackState then
  18. attackState = false;
  19. turtle.up()
  20. else
  21. return
  22. end
  23. end
  24.  
  25. while true do
  26. sleep(0.2)
  27. mobs = sensor.getEntityIds("mob")
  28. if #mobs == 0 then
  29. print("No mobs around me!")
  30. gotoGuardState()
  31. else
  32. print("Mob!")
  33. gotoAttackState()
  34. end
  35. end
Add Comment
Please, Sign In to add comment