sinkir

FlyingTurtle

Feb 27th, 2021 (edited)
439
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pastebin get gDJQ15HN startup
  2.  
  3. left = function()
  4.     return turtle.turnLeft()
  5. end
  6.  
  7. right = function()
  8.     return turtle.turnRight()
  9. end
  10.  
  11. up = function()
  12.     return turtle.up()
  13. end
  14.  
  15. down = function()
  16.     return turtle.down()
  17. end
  18.  
  19. back = function()
  20.     return turtle.back()
  21. end
  22.  
  23. go = function()
  24.     return turtle.forward()
  25. end
  26.  
  27. fuel = function()
  28.     return turtle.getFuelLevel()
  29. end
  30.  
  31. select = function(id)
  32.     return turtle.select(id)
  33. end
  34.  
  35. count = function(id)
  36.     return turtle.getItemCount(id)
  37. end
  38.  
  39. move = function(id, nb)
  40.     return turtle.transferTo(id, nb)
  41. end
  42.  
  43. --coucou coucou- -------------------------------------------
  44. function testFuel()
  45.     if(fuel() < 100)then
  46.         print('Plus de coco, test de refuel')
  47.         j = 1
  48.         if (count(j)>0) then
  49.             select(j)
  50.         end
  51.         flagstop = false
  52.         while(flagstop == false)do
  53.             if(count(j)>0 and turtle.refuel(3)==true)then
  54.                 print('refuel 3, slot '..j)
  55.                 return true
  56.             end
  57.             if(j==16)then
  58.                 print('imposible de refuel, exit')
  59.                 return false
  60.             end
  61.             j=j+1
  62.             if(count(j)>0) then
  63.                 select(j)
  64.             end
  65.         end
  66.     end
  67. end
  68.  
  69. function httpGet()
  70.     local request
  71.     request = http.get("http://192.168.1.18:88/ctrl.php")
  72.     txt = request.readAll()
  73.     request.close()
  74.     return txt;
  75. end
  76.  
  77. function init()
  78.     return testFuel();
  79. end
  80.  
  81. stop=false
  82. if(init()==false) then
  83.     stop=true
  84. end
  85.  
  86. while(stop==false)do
  87.     testFuel()
  88.     order = httpGet()
  89.     if(order=="Forward") then
  90.         for i = 1, 10 do
  91.             go()
  92.         end
  93.     end
  94.     if(order=="Up") then
  95.         up()
  96.     end
  97.     if(order=="Left") then
  98.         left()
  99.     end
  100.     if(order=="Stop") then
  101.         print("Stop")
  102.         sleep(10)
  103.     end
  104.     if(order=="Right") then
  105.         right()
  106.     end
  107.     if(order=="Half Turn") then
  108.         right()
  109.         right()
  110.     end
  111.     if(order=="Back") then
  112.         for i = 1, 10 do
  113.             back()
  114.         end
  115.     end
  116.     if(order=="Down") then
  117.         down()
  118.     end
  119.    
  120.     sleep(1)
  121. end
  122. print('End')
  123. if(fuel() == 0) then
  124.   print('Ya plus de coco mon coco !')
  125. end
RAW Paste Data