I saw a video earlier with a guy who had a wireless melee turtle to hunt down monsters and attack them until dead. Unfortunately there were no links to any code,soo.. thats why I create this post now: have anyone been working with this?
I have build a GPS system, found a program that will tell a turtle to go to a specific coordinate i provide - so far so good. But, I would need a computer to realtime get the current coordinates of a monster and sending it to the turtle - updating it realtime - so that it will move towards the monster and keep hitting it until dead.
Anyone has some good ideas to continue forward in this process? Maybe someone already created something that works? :-)
The program that sends the turtle to a specific coordinate (then nothing else, does not attack or make sure that it faces front to the monster etc)
- – this program is for a turtle and you give it coords and it will go there, just be sure to ahve a gps network set up
- local tArgs = {…}
- local x = tonumber(tArgs[1])
- local y = tonumber(tArgs[2])
- local z = tonumber(tArgs[3])
- local curx, cury, curz, dir
- function getPos()
- return gps.locate(3)
- end
- function getDir()
- local dir, x, y, z
- x, y, z = getPos()
- while not turtle.forward() do
- while not turtle.up() do
- turtle.digUp()
- end
- end
- nx, ny, nz = getPos()
- –print ("New: "..nx..","..ny..","..nz)
- if (x == nx) then
- if (nz > z) then
- dir = 2
- else
- dir = 0
- end
- else
- if (nx > x) then
- dir = 3
- else
- dir = 1
- end
- end
- return dir
- end
- function setDir(toDir)
- while toDir ~= dir do
- turtle.turnLeft()
- if dir == 3 then
- dir = 0
- else
- dir = dir+1
- end
- end
- end
- function moveX()
- distxx = x - curx
- –print(distx)
- if (x > curx) then
- setDir(3)
- else
- setDir(1)
- end
- distx = math.abs(distx)
- –print(distx)
- for i = 1, distx do
- while not turtle.forward() do
- while not turtle.up() do
- turtle.digUp()
- end
- end
- end
- end
- function moveZ()
- distz = z - curz
- if (z < curz) then
- setDir(0)
- else
- setDir(2)
- end
- distz = math.abs(distz)
- – print(distz)
- for i = 1, distz do
- while not turtle.forward() do
- while not turtle.up() do
- turtle.digUp()
- end
- end
- end
- end
- function moveY()
- disty = y - cury
- disty = math.abs(disty)
- if (y < cury) then
- for i = 1, disty do
- while not turtle.down() do
- turtle.digDown()
- end
- end
- else
- for i = 1, disty do
- while not turtle.up() do
- turtle.digUp()
- end
- end
- end
- end
- if not x or not y or not z then
- print("Must supply X Y Z")
- exit()
- end
- rednet.open("right")
- –print (x..","..y..","..z)
- dir = getDir()
- curx, cury, curz = getPos()
- distx = x - curx
- disty = y - cury
- distz = z - curz
- –print (" Current: "..curx..","..cury..","..curz)
- –print ("Distance: ",, distx,,",".. disty..","..distz)
- moveX()
- curx, cury, curz = getPos()
- moveZ()
- curx, cury, curz = getPos()
- moveY()
- curx, cury, curz = getPos()
- print("Current: "..curx..","..cury..","..curz)