Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Set functions first, then do main instructions
- PROTOCOL = "danetos3"
- hostID = nil
- homeX = nil
- homeY = nil
- homeZ = nil
- curX = nil
- curY = nil
- curZ = nil
- job = nil
- function getHostID()
- hostID = rednet.lookup(PROTOCOL)
- if hostID == "nil" then --If the server acknolwedges your request
- print("ERROR0: No DanetOS3 MainServer found!")
- else
- print("MainServer acknowledged.")
- print("HostID: " .. hostID)
- end
- end --END getHostID()
- function getLocation() --Gets the location of this turtle
- curX,curY,curZ = gps.locate(60)
- if curX == nil or curY == nil or curZ == nil then
- print("ERROR1: GPS Location could not be determined.")
- rednet.send(hostID,"ERROR1",PROTOCOL)
- else
- rednet.send(hostID,curX .. " " .. curY .. " " .. curZ,PROTOCOL)
- print("SUCCESS! GPS Coordinates sent to MainServer.")
- end
- end
- function getHome()
- getHostID()
- rednet.send(hostID,"getHome",PROTOCOL)
- sender,message = rednet.receive(PROTOCOL,60)
- local multiMessages = {}
- for w in string.gmatch(message, "%S+") do
- -- multiMessages[#multiMessages+1] = w
- end
- homeX = multiMessages[1]
- homeY = multiMessages[2]
- homeZ = multiMessages[3]
- print("SUCCESS! Got home coordinate information from MainServer!")
- end
- function getJob() --Gets the turtles job from the MainServer
- getHostID()
- rednet.send(hostID,"getJob",PROTOCOL)
- sender,message = rednet.receive(PROTOCOL,60)
- job = message
- print("SUCCESS! Got job information from MainServer!")
- end
- function receiveCommands()
- message = {}
- sender,message = rednet.receive("danetos3")
- if message[1] == "StripMine" then
- shell.run(message[1] .. " " .. message[2] .. " " .. message[3] .. " " .. message[4] .. " " .. message[5])
- elseif message[1] == "update" then
- shell.run("update")
- else
- print("Invalid Command. You sent " .. message[1])
- end
- end
- --MAIN INSTRUCTIONS GO HERE
- shell.run("clear")
- print("DanetOS3 Turtle!")
- rednet.open("right")
- --Wait for commmands, and process them when they come
- while(true) do
- receiveCommands()
- end
RAW Paste Data