Advertisement
brickviking

bashed-up TurtleController.lua

May 3rd, 2022
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.61 KB | None | 0 0
  1. -- Controller script
  2. -- Seriously hacked from TurtleController-2.2.4
  3. -- -*-Lua-*-
  4. oldLabel=os.getComputerLabel()
  5. os.setComputerLabel("Remote Controller")
  6. print("")
  7. shell.run("id")
  8. print("")
  9.  
  10. if peripheral.getType("right") == "modem" then
  11.   rednet.open("right")
  12. elseif peripheral.getType("left") == "modem" then
  13.   rednet.open("left")
  14. elseif peripheral.getType("top") == "modem" then
  15.   rednet.open("top")
  16. elseif peripheral.getType("bottom") == "modem" then
  17.   rednet.open("bottom")
  18. elseif peripheral.getType("back") == "modem" then
  19.   rednet.open("back")
  20. elseif peripheral.getType("front") == "modem" then
  21.   rednet.open("front")
  22. end
  23.  
  24. print("What id would you like to connect to?")
  25. l=tonumber(read())
  26.  
  27. print("")
  28. print("Type /list for a list of commands")
  29. print("")
  30.  
  31. repeat
  32.   write("Command : ")
  33.   x=read()
  34.   if x==("/list") then
  35.     term.clear()
  36.     term.setCursorPos(1,1)
  37.     print("R --> refuel (This should work automatically)")
  38.     print("f/l/b/r --> movement for/left/back/right")
  39.     print("u/d/t --> up/down/turn around")
  40.     print("sl/sr ---> step to the left/right and turn")
  41.     print("sal/sar ---> step across to left/right")
  42.     print("x/xu/xd --> dig ahead/up/down")
  43.     print("p/pu/pd --> place ahead/up/down")
  44.     -- print("tunnel --> dig 3x2") -- replaced by fp
  45.     print("fp --> floorplace")
  46.     print("a/au/ad --> attack/up/down")
  47.     print("shutdown --> Shuts down transmitter and receiver")
  48.     print("reboot --> reboots transmitter and receiver")
  49.     print("stop --> Stops using this program")
  50.     print("clear --> Clear Memory after picking up")
  51.     print("AddCommand --> Allows you to add commands")
  52.   elseif x==("AddCommand") then
  53.     print("To set this up you have to go to your turtle")
  54.     rednet.send(l,x)
  55.   elseif x=="fp" then
  56.     repeat
  57.       print("how many blocks?")
  58.       z = tonumber(read())
  59.     until z >=1
  60.     k=tostring(z)
  61.     rednet.send(l,k)
  62.   elseif x=="go" then
  63.     print("remainder of command?")
  64.     k = read()
  65.     rednet.send(l,"go")
  66.     sleep(0.1)
  67.     rednet.send(l,k)
  68.   else
  69.     rednet.send(l,x)
  70.   end
  71.  
  72.   -- now we listen for reply
  73.   sleep(0.00000001)
  74.   y,u=rednet.receive(l)
  75.   print("Received ",u," from ",y)
  76.   if u==("p2") and y==l then
  77.     print("Out of coal and fuel")
  78.   end
  79.   if u==("s") and y==l then
  80.     print("Stopping and shutdown remote")
  81.     print("Stopping local program")
  82.   end
  83.   if u==("p") and y==l then
  84.     print("Incorrect Command")
  85.   elseif u==("Matches") and y==l then
  86.   end
  87.   print("Command Correct")
  88. until
  89.   x==("clear") or x==("stop")
  90.  
  91. if x==("clear") then
  92.   os.setComputerLabel(oldLabel)
  93. end
  94.  
  95. -- end of controller script --
  96.  
  97. -- -*-Lua-*-
  98. -- Turtle script
  99. -- Seriously hacked from TurtleController-2.2.4
  100. if turtle then
  101. print[[---------------------------------------------------
  102. Welcome to RemoteTurtle V2.2.4
  103. ---------------------------------------------------
  104. ]]
  105. end
  106. -- excerpted from CC:Tweaked
  107. local function tokenise(...)
  108.     local sLine = table.concat({ ... }, " ")
  109.     local tWords = {}
  110.     local bQuoted = false
  111.     for match in string.gmatch(sLine .. "\"", "(.-)\"") do
  112.         if bQuoted then
  113.             table.insert(tWords, match)
  114.         else
  115.             for m in string.gmatch(match, "[^ \t]+") do
  116.                 table.insert(tWords, m)
  117.             end
  118.         end
  119.         bQuoted = not bQuoted
  120.     end
  121.     return tWords
  122. end
  123.  
  124. os.setComputerLabel("Remote Turtle")
  125. print("")
  126. shell.run("id")
  127. rednet.open("right")
  128. print("")
  129. print("Id To Receive commands from?")
  130. l=tonumber(read())
  131. repeat
  132.   i,k=rednet.receive()
  133.   z=turtle.getFuelLevel()
  134.   if
  135.     z==0 then
  136.     shell.run("refuel", "all")
  137.     turtle.select(1)
  138.   end
  139.   z=turtle.getFuelLevel()
  140. if
  141.   z==0 then
  142.   rednet.send(l,"p2")
  143. end
  144. if
  145.    l==i and k==("tunnel") then
  146.    -- send back "continue"
  147.      print("Received tunnel, waiting for number")
  148.      i,k=rednet.receive()
  149.    -- needs to be a number - will fall over otherwise
  150.      print("Received ",k," from ", i)
  151.      g=tonumber(k)
  152.      if l==i and g>0 then
  153. -- do the tunnel 3x2
  154. -- abc
  155. -- def
  156.      for m=1,g do
  157.     turtle.attack()  --clear first block e
  158.     turtle.forward() -- e
  159.     turtle.attackUp() -- eb
  160.     turtle.turnLeft()
  161.     turtle.attack() -- ed
  162.     turtle.forward() -- d
  163.     turtle.attackUp() -- da
  164.     turtle.back() -- e
  165.     turtle.turnRight()
  166.     turtle.turnRight()
  167.     turtle.attack() -- ef
  168.     turtle.forward() -- f
  169.     turtle.attackUp() -- fc
  170.     turtle.back() -- e
  171.     turtle.turnLeft()
  172.      end
  173.    else -- g ~= number
  174.       print("Incorrect message format")
  175.       sleep(0.2)
  176.       rednet.send(l,"p")
  177.    end
  178. elseif
  179.    l==i and k==("go") then
  180.    sleep(0.1)
  181.    i,k=rednet.receive()
  182.    g=tokenise(k)
  183.    print("Got back ",g," from ",i)
  184.    shell.run("go", unpack(g))
  185. elseif
  186.   l==i and k==("R") then
  187.   shell.run("refuel")
  188. elseif
  189.   l==i and k==("f") then
  190.    turtle.forward()
  191. elseif
  192.    l==i and k==("b") then
  193.    turtle.back()
  194. elseif
  195.   l==i and k==("l") then
  196.   turtle.turnLeft()
  197. elseif
  198.   l==i and k==("r") then
  199.   turtle.turnRight()
  200. elseif
  201.   l==i and k==("u") then
  202.   turtle.up()
  203. elseif
  204.   l==i and k==("d") then
  205.   turtle.down()
  206. elseif
  207.   l==i and k==("t") then
  208.   turtle.turnRight()
  209.   turtle.turnRight()
  210. elseif
  211.   l==i and k==("sl") then
  212.   turtle.turnLeft()
  213.   turtle.forward()
  214.   turtle.turnLeft()
  215. elseif
  216.   l==i and k==("sr") then
  217.   turtle.turnRight()
  218.   turtle.forward()
  219.   turtle.turnRight()
  220. elseif
  221.   l==i and k==("sal") then
  222.   turtle.turnLeft()
  223.   turtle.forward()
  224.   turtle.turnRight()
  225. elseif
  226.   l==i and k==("sar") then
  227.   turtle.turnRight()
  228.   turtle.forward()
  229.   turtle.turnLeft()
  230. elseif
  231.   l==i and k==("x") then
  232.    turtle.dig()
  233. elseif
  234.   l==i and k==("xu") then
  235.   turtle.digUp()
  236. elseif
  237.   l==i and k==("xd") then
  238.   turtle.digDown()
  239. elseif
  240.    l==i and k==("p") then
  241.    turtle.place()
  242. elseif
  243.    l==i and k==("pu") then
  244.    turtle.placeUp()
  245. elseif
  246.    l==i and k==("pd") then
  247.    turtle.placeDown()
  248. elseif
  249.    l==i and k==("slot") then
  250.    turtle.select(1)
  251. elseif
  252.    l==i and tonumber(k)~=nil then
  253.    print("floorplace ",k)
  254.   shell.run("floorplace",k) -- should place floors for k blocks
  255. elseif
  256.   l==i and k==("clear") then
  257.   os.setComputerLabel("")
  258. elseif
  259.   l==i and k==("a") then
  260.   turtle.attack()
  261. elseif
  262.   l==i and k==("au") then
  263.   turtle.attackUp()
  264. elseif
  265.   l==i and k==("ad") then
  266.   turtle.attackDown()
  267. elseif
  268.   l==i and k==("reboot") then
  269.   os.reboot()
  270. elseif
  271.   l==i and k==("shutdown") then
  272.    os.shutdown()
  273. elseif
  274.    l==i and k==("stop") then
  275.    print("Stopping program")
  276.    rednet.send(l,"s")
  277.    sleep(0.1)
  278.    os.shutdown()
  279. elseif
  280.   l==i and k==(cmd1) then
  281.   turtle[cmd1e]()
  282. elseif
  283.   l==i and k==(cmd2) then
  284.   turtle[cmd2e]()
  285. elseif
  286.   l==i and k==(cmd3) then
  287.   turtle[cmd3e]()
  288. elseif
  289.  
  290.   l==i and k==("AddCommand") then
  291.   print("Which command do you want to change? 1/2/3")
  292.   cwhat=read()
  293.   print("for the question :What do you want to execute? you answer has to be what would fill in the blank spot: turtle.[BLANK SPOT]()")
  294.  
  295.   if cwhat == ("1") then
  296.         print("What do you want to type to to execute")
  297.  
  298.         cmd1=read()  
  299.         print("What do you want to execute?")
  300.         cmd1e=read()
  301.   elseif
  302.         chwat == ("2") then
  303.         print("What do you want to type to execute?")
  304.         cmd2=read()
  305.         print("What do you want to execute?")
  306.         cmd2e=read()
  307.   elseif
  308.         chwat == ("3") then
  309.         print("What do you want to type to execute?")
  310.         cmd3=read()
  311.         print("What do you want to execute?")
  312.         cmd3e=read()
  313.   end
  314.  
  315.  
  316. else
  317.   sleep(0.2)
  318.   print("Doesn't match")
  319.   rednet.send(l,"p")
  320. end
  321. sleep(0.2)
  322. rednet.send(l,"Matches")
  323.  
  324. until
  325. l==i and k==("stop") or l==i and k==("clear")
  326.  
  327. -- end of turtle script --
  328.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement