Rusettsten

DanetOS-Turtle-Main

Nov 29th, 2020 (edited)
525
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Set functions first, then do main instructions
  2. PROTOCOL = "danetos3"
  3. hostID = nil
  4. homeX = nil
  5. homeY = nil
  6. homeZ = nil
  7. curX = nil
  8. curY = nil
  9. curZ = nil
  10. job = nil
  11.  
  12. function getHostID()
  13.     hostID = rednet.lookup(PROTOCOL)
  14.     if hostID == "nil" then --If the server acknolwedges your request
  15.         print("ERROR0: No DanetOS3 MainServer found!")
  16.     else
  17.         print("MainServer acknowledged.")
  18.         print("HostID: " .. hostID)
  19.     end
  20.    
  21. end --END getHostID()
  22.  
  23. function getLocation() --Gets the location of this turtle
  24.     curX,curY,curZ = gps.locate(60)
  25.     if curX == nil or curY == nil or curZ == nil then
  26.         print("ERROR1: GPS Location could not be determined.")
  27.         rednet.send(hostID,"ERROR1",PROTOCOL)
  28.     else
  29.         rednet.send(hostID,curX .. " " .. curY .. " " .. curZ,PROTOCOL)
  30.         print("SUCCESS! GPS Coordinates sent to MainServer.")
  31.     end
  32. end
  33.  
  34. function getHome()
  35.     getHostID()
  36.     rednet.send(hostID,"getHome",PROTOCOL)
  37.     sender,message = rednet.receive(PROTOCOL,60)
  38.     local multiMessages = {}
  39.     for w in string.gmatch(message, "%S+") do
  40.         -- multiMessages[#multiMessages+1] = w
  41.     end
  42.     homeX = multiMessages[1]
  43.     homeY = multiMessages[2]
  44.     homeZ = multiMessages[3]
  45.     print("SUCCESS! Got home coordinate information from MainServer!")
  46. end
  47.  
  48. function getJob() --Gets the turtles job from the MainServer
  49.     getHostID()
  50.     rednet.send(hostID,"getJob",PROTOCOL)
  51.     sender,message = rednet.receive(PROTOCOL,60)
  52.     job = message
  53.     print("SUCCESS! Got job information from MainServer!")
  54. end
  55.  
  56. function receiveCommands()
  57.     message = {}
  58.     sender,message = rednet.receive("danetos3")
  59.    
  60.     if message[1] == "StripMine" then
  61.         shell.run(message[1] .. " " .. message[2] .. " " .. message[3] .. " " .. message[4] .. " " .. message[5])
  62.     elseif message[1] == "update" then
  63.         shell.run("update")
  64.     else
  65.         print("Invalid Command. You sent " .. message[1])
  66.     end
  67.    
  68. end
  69.  
  70. --MAIN INSTRUCTIONS GO HERE
  71.  
  72. shell.run("clear")
  73. print("DanetOS3 Turtle!")
  74. rednet.open("right")
  75.  
  76. --Wait for commmands, and process them when they come
  77. while(true) do
  78.     receiveCommands()
  79. end
  80.  
  81.  
  82.  
RAW Paste Data