Advertisement
NanoBob

Remote Turtle V3.0

Jun 6th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.47 KB | None | 0 0
  1. function welcomeMessage ()
  2.     shell.run("clear")
  3.     if turtle then
  4.         if term.isColor() then
  5.             term.setTextColor(colors.lime)
  6.         end
  7.         print[[---------------------------------------
  8.         Welcome to NanoTurtle V3.0
  9.         ---------------------------------------]]
  10.     else
  11.         if term.isColor() then
  12.             term.setTextColor(colors.lime)
  13.         end
  14.         print[[---------------------------------------------------
  15.         Welcome to NanoTurtle V3.0
  16.         ---------------------------------------------------
  17.         ]]
  18.     end
  19.         if term.isColor() then
  20.         term.setTextColor(colors.white)
  21.     end
  22. end
  23.  
  24. function firstQuestion()
  25.     welcomeMessage()
  26.     print("Do you want to transmit or receive from this device?")
  27.     input=read()
  28.     if input=="receive" then
  29.         receiving=true
  30.         os.setComputerLabel("Remote Turtle")
  31.         secondQuestion(receiving)
  32.     elseif input=="transmit" then
  33.         receiving=false
  34.         os.setComputerLabel("Remote Transmitter")
  35.         secondQuestion(receiving)
  36.     else
  37.         print("Incorrect Input!")
  38.         firstQuestion()
  39.     end
  40. end
  41.  
  42. function secondQuestion(receiving)
  43.     welcomeMessage()
  44.     shell.run("id")
  45.     for id, side in pairs(rs.getSides()) do
  46.         if peripheral.getType(side) == "modem" then
  47.                 rednet.open(side)
  48.         end
  49.     end
  50.     print("")
  51.     print("Which ID would you like to link to?")
  52.     otherID=tonumber(read())
  53.     if receiving==true then
  54.         receiveFunction()
  55.     elseif receiving==false then
  56.         transmitFunction()
  57.     end
  58. end
  59.  
  60. function receiveFunction()
  61.     welcomeMessage()
  62.     print("Awaiting signals...")
  63.     running=true
  64.     while running do
  65.         id,message=rednet.receive()
  66.         if id==otherID then
  67.             firstSpace=string.find(message," ")
  68.             if firstSpace~=nil then
  69.                 command=string.sub(1,firstSpace-1)
  70.                 timesToExecute=tonumber(string.gsub(message,command.." ",""))
  71.             else
  72.                 command=message
  73.                 timesToExecute=1
  74.             end
  75.             turtleFunction(command,timesToExecute)
  76.         end
  77.     end
  78. end
  79.  
  80. function turtleFunction(command,timesToExecute)
  81.     for i=1,timesToExecute do
  82.         if turtle.getFuelLevel() <200 then
  83.             shell.run("refuel")
  84.         end
  85.         if command=="r" then
  86.             shell.run("refuel")
  87.         elseif command=="w" then
  88.             turtle.forward()
  89.         elseif command=="a" then
  90.             turtle.turnLeft()
  91.             turtle.forward()
  92.         elseif command=="s" then
  93.             turtle.turnRight()
  94.             turtle.turnRight()
  95.             turtle.forward()
  96.         elseif command=="d" then
  97.             turtle.turnRight()
  98.             turtle.forward()
  99.         elseif command=="q" then   
  100.             turtle.up()
  101.         elseif command=="z" then   
  102.                 turtle.down()
  103.         elseif command=="x" then
  104.             turtle.dig()
  105.         elseif command=="xup" then
  106.             turtle.digUp()
  107.         elseif command=="xdown" then
  108.             turtle.digDown()
  109.         elseif command=="turnLeft" then
  110.             turtle.turnLeft()
  111.         elseif command=="turnRight" then
  112.             turtle.turnRight()
  113.         elseif command=="clear" then
  114.             os.setComputerLabel("")
  115.             running=false
  116.         elseif command=="f" then
  117.             turtle.attack()
  118.         elseif command=="fup" then
  119.             turtle.attackUp()
  120.         elseif command=="fdown" then
  121.             turtle.attackDown()
  122.         elseif command=="reboot" then
  123.             os.reboot()
  124.         elseif command=="shutdown" then
  125.             os.shutdown()
  126.         elseif command=="addCommand" then
  127.             addCommandFunction()
  128.         elseif command=="stop" then
  129.             running=false
  130.         end
  131.     end
  132. end
  133.  
  134. function addCommandFunction()
  135.  
  136. end
  137. function transmitFunction()
  138.     running=true
  139.     while running do
  140.         welcomeMessage()
  141.         print("")
  142.         print("type 'help' for a list of commands")
  143.         print("")
  144.         write("Command : ")
  145.         command=string.lower(read())
  146.         if command=="help" then
  147.         print("r                  --> refuel (This should be done automaticly)")
  148.         print("w/a/s/d            --> movement")
  149.         print("q/z                --> up/down")
  150.         print("x                  --> dig")
  151.         print("xup                --> dig up")
  152.         print("xdown              --> dig down")
  153.         print("turnleft/turnright --> turn left/ turn right")
  154.         print("f                  --> attack")
  155.         print("fup/fdown          --> attacks up/down")
  156.         print("shutdown           --> Shuts down transmitter and receiver")
  157.         print("reboot             --> reboots transmitter and receiver")
  158.         print("stop               --> Stops using this program")
  159.         print("clear              --> Clear Memory after picking up")
  160.         print("")
  161.         print("Press enter when you wish to return to controlling the turtle.")
  162.         input=read()
  163.         --print("addCommand --> Allows you to add commands")
  164.         elseif command=="addcommand" then
  165.             --NYI
  166.         elseif command=="stop" then
  167.             running=false
  168.         else   
  169.             rednet.send(otherID,command)
  170.            
  171.         end
  172.     end
  173. end
  174.  
  175. welcomeMessage()
  176. firstQuestion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement