Posted 20 February 2014 - 03:23 PM
Hello!
I'm trying to make the turtle detect if there is a mob, then kill it. Since "turtle.detect()" doesn't work I've tried some other alternatives. The only thing that doesn't work is when it turns left or right it attacks only one time, but I want it to detect if there is a mob to kill, then sleep for a second and then check if there is a mob again. Can someone please help me? :)/>
The code looks like this:
I'm trying to make the turtle detect if there is a mob, then kill it. Since "turtle.detect()" doesn't work I've tried some other alternatives. The only thing that doesn't work is when it turns left or right it attacks only one time, but I want it to detect if there is a mob to kill, then sleep for a second and then check if there is a mob again. Can someone please help me? :)/>
The code looks like this:
local function attack()
if not turtle.forward() then
while turtle.attack() do
while turtle.attack() do end
sleep(1)
end
turtle.forward()
end
end
local function ifAttack()
turtle.attack()
while turtle.attack() do
while turtle.attack() do end
sleep(3)
end
end
local function moveForward()
for i = 1,2 do
turtle.forward()
attack()
turtle.turnLeft()
ifAttack()
turtle.turnRight()
turtle.turnRight()
ifAttack()
turtle.turnLeft()
end
turtle.turnRight()
turtle.turnRight()
end
local function moveBack()
turtle.forward()
attack()
turtle.forward()
attack()
end
while true do
moveForward()
moveBack()
moveForward()
moveBack()
end