SHARE
TWEET

test.lua

neo34rd Mar 24th, 2019 (edited) 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top