Last active
August 2, 2016 19:20
-
-
Save mightystoosh/da41d449af56d4bf5000ddf32afb8542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--attack droid | |
gist_id = "da41d449af56d4bf5000ddf32afb8542" | |
current_name = "attack" | |
check_counter = 1000 | |
function my_print(message) | |
print(message) | |
rednet.open("right") | |
rednet.send(61,message) | |
end | |
function attack_loop() | |
while check_for_mob_or_player() do | |
my_print("ATTACK!!") | |
turtle.attack() | |
end | |
turtle.turnLeft() | |
while check_for_mob_or_player() do | |
my_print("ATTACK!!") | |
turtle.attack() | |
end | |
turtle.turnLeft() | |
while check_for_mob_or_player() do | |
my_print("ATTACK!!") | |
turtle.attack() | |
end | |
turtle.turnLeft() | |
while check_for_mob_or_player() do | |
my_print("ATTACK!!") | |
turtle.attack() | |
end | |
turtle.turnLeft() | |
while check_for_mob_or_player() do | |
my_print("ATTACK!!") | |
turtle.attack() | |
end | |
end | |
function check_for_mob_or_player() | |
local l = turtle.inspect() | |
if not l and not turtle.forward() then --#No block in front and can't move forward. | |
my_print("Mob/player detected in front.") | |
return true | |
end | |
return false | |
end | |
function search_and_destroy() | |
if turtle.forward() then | |
my_print("Chugging on forward...") | |
else | |
if turtle.detect() and not check_for_mob_or_player() then | |
turtle.turnLeft() | |
end | |
end | |
end | |
function readAll(file) | |
local f = io.open(file, "rb") | |
local content = f:read("*all") | |
f:close() | |
return content | |
end | |
count = 0 | |
while(true) do | |
count = count + 1 | |
if turtle.getFuelLevel() < 600 then | |
my_print("low on fuel.... refueling") | |
turtle.refuel() | |
end | |
if check_for_mob_or_player() then --#No block in front and can't move forward. | |
my_print("ATTACK!!") | |
turtle.attack() | |
attack_loop() | |
end | |
search_and_destroy() | |
if count % check_counter == count - math.floor(count/check_counter)*check_counter then | |
shell.run("rm new_file") | |
shell.run("turtlegist get " .. gist_id .. " new_file") | |
if readAll("new_file") == readAll(current_name) then | |
print "files match no need to update. will try again later." | |
else | |
file = io.open("rewriter", "w") | |
file:write("os.sleep(10)\nos.remove(" .. current_name .. ")\nos.rename('new_file','" .. current_name .. "')\nshell.run(bg " .. current_name ..")\n") | |
shell.run("bg rewriter") | |
io.close(file) | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment