Posted 21 February 2014 - 07:06 AM
Hello!
I want the turtle to attack a mob (if there is a mob there) until it's dead, then sleep for a second and check again. If there is no mob there it does something else, and if it is a mob there, it will attack again until it's dead and so on…
I have this code:
But what this does, is attack the mob once, then sleep for a second, then attack once and sleep etc. until the mob is dead.
Can someone help me with my problem? :)/>
I want the turtle to attack a mob (if there is a mob there) until it's dead, then sleep for a second and check again. If there is no mob there it does something else, and if it is a mob there, it will attack again until it's dead and so on…
I have this code:
local function attack()
while turtle.attack() do
while turtle.attack() do end
turtle.suck()
sleep(1)
end
end
local function moveForward()
for i = 1,2 do
turtle.forward()
attack()
turtle.turnLeft()
attack()
turtle.turnRight()
turtle.turnRight()
attack()
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
But what this does, is attack the mob once, then sleep for a second, then attack once and sleep etc. until the mob is dead.
Can someone help me with my problem? :)/>