Advertisement
PaffcioStudio

Turtle - Budowa wiezy GPS

Feb 2nd, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.19 KB | None | 0 0
  1.  
  2.  
  3.     --GPS Tower Builder Version-1.3 , Made By bigbaddevil7.
  4.      
  5.      
  6.     local tArgs = {...}
  7.     hasTower = tArgs[1]
  8.     Ypos = tonumber(tArgs[2])
  9.     Zpos = tonumber(tArgs[3])
  10.     face = tonumber(tArgs[4])
  11.     direction = ""
  12.      
  13.     function faceNorth()
  14.             if face == 1 then
  15.                     turtle.turnRight()
  16.             elseif face == 3 then
  17.                     turtle.turnLeft()
  18.             elseif face == 0 then
  19.                     turtle.turnRight()
  20.                     turtle.turnRight()
  21.             end
  22.     end
  23.      
  24.     function placeComputer(num)
  25.       turtle.select(1)
  26.       turtle.place()  
  27.       turtle.up()
  28.       turtle.select(2)
  29.       turtle.place()
  30.       turtle.down()
  31.       turtle.down()
  32.       turtle.select(3)
  33.       turtle.place()
  34.       turtle.select(4)
  35.       turtle.drop()
  36.       print("Uploading Cords to Comp: "..num)
  37.       transfer(num)
  38.       turtle.up()
  39.       sleep(0.5)
  40.       comp = peripheral.wrap("front")
  41.       comp.turnOn()
  42.       turtle.down()
  43.       turtle.suck()
  44.       turtle.select(3)
  45.       turtle.dig()
  46.       turtle.up()
  47.       sleep(3)
  48.       comp.reboot()
  49.     end
  50.      
  51.     function transfer(Cnum)
  52.     handler = fs.open("disk/startup", "w")
  53.       handler.writeLine("fs.move(\"disk/GPS\", \"startup\")")
  54.     handler.close()
  55.     file = fs.open("disk/GPS", "w")
  56.             if Cnum == 1 then
  57.                     file.writeLine("shell.run(\"gps\",\"host\","..C1x..","..C1y..","..C1z..")")
  58.             elseif Cnum == 2 then
  59.                     file.writeLine("shell.run(\"gps\",\"host\","..C2x..","..C2y..","..C2z..")")
  60.             elseif Cnum == 3 then
  61.                     file.writeLine("shell.run(\"gps\",\"host\","..C3x..","..C3y..","..C3z..")")
  62.             elseif Cnum == 4 then
  63.                     file.writeLine("shell.run(\"gps\",\"host\","..C4x..","..C4y..","..C4z..")")
  64.             end
  65.             file.close()
  66.     end
  67.      
  68.      
  69.     function writeScreen()
  70.             term.clear()
  71.             term.setCursorPos(1,2)
  72.             if face == 0 then
  73.                     direction = "South"
  74.             elseif face == 1 then
  75.                     direction = "West"
  76.             elseif face == 2 then
  77.                     direction = "North"
  78.             elseif face == 3 then
  79.                     direction = "East"
  80.             end
  81.             print("X="..Xpos.." : Y="..Ypos..": Z="..Zpos.." : Facing = "..direction)
  82.             color(colors.orange)
  83.             moveUp = 246 - Ypos -- change to 246
  84.             --print("Blocks to move up: "..moveUp + 1)
  85.             print("Placement Grid Cords:")
  86.             color(colors.cyan)
  87.             print("==================================")
  88.             C1x = Xpos + 5
  89.             C1y = 249 --change 249
  90.             C1z = Zpos
  91.             color(colors.orange)
  92.             print("Computer 1: "..C1x.." : 250 : "..C1z)
  93.             C2x = Xpos - 5
  94.             C2y = 249 --change 249
  95.             C2z = Zpos
  96.             print("Computer 2: "..C2x.." : 250 : "..C2z)  
  97.             C3x = Xpos
  98.             C3y = 246 -- change 246
  99.             C3z = Zpos + 5
  100.             print("Computer 3: "..C3x.." : 247 : "..C3z)
  101.             C4x = Xpos
  102.             C4y = 246 -- change 246
  103.             C4z = Zpos - 5
  104.             print("Computer 4: "..C4x.." : 247 : "..C4z)
  105.             color(colors.cyan)
  106.             print("==================================")
  107.             color(colors.orange)
  108.             print("Press \"ENTER\" to start building")
  109.     end
  110.      
  111.     function prepScreen()
  112.             term.clear()
  113.             term.setCursorPos(1, 2)
  114.             color(colors.orange)
  115.             print("The Program Requires")
  116.             color(colors.cyan)
  117.             print("==================================")
  118.             color(colors.orange)
  119.             print("Slot 1: 4 Computers")
  120.             print("Slot 2: 4 Wireless Modems")
  121.             print("Slot 3: 1 Disk Drive")
  122.             print("Slot 4: 1 Floppy Disk")
  123.             if turtle.getFuelLevel() < 1000 or turtle.getFuelLevel() ~= "unllimited" then
  124.               print("Slot 5: Fuel")
  125.             else
  126.               print("")
  127.             end
  128.             color(colors.cyan)
  129.             print("==================================")
  130.             color(colors.orange)
  131.             print("Press \"ENTER\" to start building")
  132.     end
  133.      
  134.     function fillFuel()
  135.             if turtle.getFuelLevel() < 1000 or turtle.getFuelLevel ~= "unlimited" then
  136.                     turtle.select(5)
  137.                     turtle.refuel()
  138.             end
  139.     end
  140.      
  141.     function work()
  142.             for i = 10, 0, -1 do
  143.               term.clear()
  144.               term.setCursorPos(1,2)
  145.               print("Please Stand Clear Of Turtle")
  146.               print("Starting in: "..i)
  147.               sleep(1)
  148.             end
  149.              
  150.             print("Turning to face North...")
  151.             faceNorth()
  152.             print("Climbing to height of tower...")
  153.             for i = 1, moveUp do
  154.               while not turtle.up() do
  155.                     if turtle.digUp() then
  156.                             print("Mined a block in my way.")
  157.                     elseif turtle.attackUp() then
  158.                             print("Attacked a mob in my way")
  159.                     end
  160.               end
  161.             end
  162.             for i = 1, 6 do
  163.               turtle.back()
  164.             end
  165.              
  166.             --sleep(2)
  167.             print("Placing Computer 3")
  168.             placeComputer(3)
  169.             turtle.up()
  170.             turtle.up()
  171.              
  172.             for i = 1, 12 do
  173.               turtle.forward()
  174.             end
  175.             turtle.turnRight()
  176.             turtle.turnRight()
  177.             turtle.down()
  178.             turtle.down()
  179.             --sleep(2)
  180.             print("Placing computer 4")
  181.             placeComputer(4)
  182.             turtle.up()
  183.             turtle.up()
  184.             turtle.up()
  185.             for i = 1, 5 do
  186.               turtle.forward()
  187.             end
  188.             turtle.turnLeft()
  189.             for i = 1, 5 do
  190.               turtle.forward()
  191.             end
  192.             turtle.turnRight()
  193.             --sleep(2)
  194.             print("Placing Computer 1")
  195.             placeComputer(1)
  196.             turtle.turnRight()
  197.             for i = 1, 10 do
  198.               turtle.forward()
  199.             end
  200.             turtle.turnLeft()
  201.             --sleep(2)
  202.             print("Placing computer 2")
  203.             placeComputer(2)
  204.             turtle.turnLeft()
  205.             for i = 1, 5 do
  206.               turtle.forward()
  207.             end
  208.             turtle.turnRight()
  209.             turtle.forward()
  210.             turtle.turnRight()
  211.             turtle.turnRight()
  212.             print("Heading back to start postion")
  213.             for i = 0, moveUp + 2 do
  214.               turtle.down()
  215.             end
  216.     end
  217.      
  218.     function getFace()
  219.     for i = 10, 0, -1 do
  220.        term.clear()
  221.        term.setCursorPos(1,1)
  222.        print("Stand Away From The Turtle So It Can Get It's Face.")
  223.        print("It Will Attack Mobs/Players!")
  224.        print("==================================")
  225.        print("Time Until it moves: "..i)
  226.        sleep(1)
  227.     end
  228.     while not turtle.forward() do
  229.             if turtle.dig() then
  230.                     print("Mined a block in my way.")
  231.                     sleep(1)
  232.             elseif turtle.attack() then
  233.                     print("Attacked a mob in my way")
  234.             end
  235.     end
  236.     local xpos2, ypos2, zpos2 = gps.locate()
  237.     while not turtle.back() do
  238.             print("There is something in my way behind me")
  239.             sleep(1)
  240.     end
  241.       if xpos2 > Xpos then
  242.         face = 3
  243.       elseif zpos2 < Zpos then
  244.         face = 2
  245.       elseif zpos2 > Zpos then
  246.         face = 0
  247.       elseif xpos2 < Xpos then
  248.         face = 1
  249.       end
  250.       return face
  251.     end
  252.      
  253.     function color(color)
  254.             term.setTextColor(color)
  255.     end
  256.      
  257.     function getCords()
  258.     Xpos, Ypos, Zpos = gps.locate()
  259.       if not Xpos then
  260.         print("Could Not Get Location")
  261.         return false
  262.       end
  263.     return Xpos, Ypos, Zpos
  264.     end
  265.      
  266.      
  267.     function cleanup()
  268.             print("==================================")
  269.             print("Running Final Cordinate Check")
  270.     local x, y, z = gps.locate()
  271.       if x ~= Xpos or y ~= Ypos or z ~= Zpos then
  272.         print("Chack Failed")
  273.         print("Make sure you entered your cords correctly")
  274.         print("Check the towers, Check for any obstruction")
  275.         print("If that all is in check then I messed up =(")
  276.       else
  277.         print("Check Succeded, your tower is running")  
  278.       end
  279.     end
  280.      
  281.     if #tArgs == 4 then
  282.             Xpos = tonumber(tArgs[1])
  283.             prepScreen()
  284.      
  285.             while true do
  286.         even, param1 = os.pullEvent()
  287.             if param1 == 28 then
  288.                     break
  289.             end
  290.             end
  291.      
  292.             fillFuel()
  293.             writeScreen()
  294.            
  295.             while true do
  296.             even, param1 = os.pullEvent()
  297.             if param1 == 28 then
  298.                     break
  299.             end
  300.             end
  301.             work()
  302.             cleanup()
  303.     elseif #tArgs == 1 then
  304.             if tArgs[1] == "locate" then
  305.                     if getCords() then
  306.                     prepScreen()
  307.                     while true do
  308.                             even, param1 = os.pullEvent()
  309.                             if param1 == 28 then
  310.                                     break
  311.                             end
  312.                             end
  313.                     end
  314.             fillFuel()
  315.         getFace()
  316.         writeScreen()
  317.             while true do
  318.                     even, param1 = os.pullEvent()
  319.                     if param1 == 28 then
  320.                             break
  321.                     end
  322.                     end
  323.             work()
  324.             cleanup()
  325.             elseif tArgs[1] == "help" then
  326.                     term.clear()
  327.                     term.setCursorPos(1,1)
  328.                     color(colors.cyan)
  329.                     print("Usage for maunally inputing cords are: tower <Xpos>, <Ypos>, <Zpos>, <Face>")
  330.                     term.setTextColor(colors.orange)
  331.                     print("The Face is the direction you are facing. It is the number under you Zpos in F3")
  332.                     color(colors.cyan)
  333.                     print("It is best to stand on the turtle and give it the cords that are in the () ")
  334.                     color(colors.orange)
  335.                     print("Usage for locating using another tower is: tower locate")
  336.                     color(colors.cyan)
  337.                     print("It will use an existing tower to get its cordinates")
  338.                     color(colors.white)
  339.             else
  340.             print("Invalid Parameters")
  341.             print("Enter: tower <Xpos>, <Ypos>, <Zpos>, <Face>")
  342.             print("Enter: tower locate (if you already have a hosting GPS tower)")
  343.             print("Enter: tower help for more information")
  344.             end
  345.     else
  346.         print("Please Enter: tower <X>, <Y>, <Z>, <F>")
  347.         print("Or Enter: tower locate (if you already have a hosting GPS tower)")
  348.         print("Example : tower 100 -100 200 1")
  349.         print("F is the face under the Z cord in F3")
  350.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement