Advertisement
hyndgrinder

detHead

May 9th, 2014
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local _tArgs={...}
  2.  
  3. fuel=turtle.getFuelLevel()
  4. print(os.getComputerID(),": ",os.getComputerLabel())
  5. print ("Fuel Level: ",fuel)
  6. if fuel>0 then
  7.   rednet.open("right")
  8.  
  9. if #_tArgs==2 and _tArgs[1]~=_tArgs[2]then
  10.     pos1=vector.new(textutils.unserialize(_tArgs[1]))
  11.     pos2=vector.new(textutils.unserialize(_tArgs[2]))
  12. else
  13.   pos1=vector.new(gps.locate())
  14.   while turtle.detect()==true do
  15.     turtle.turnRight()
  16.   end
  17.   turtle.forward()
  18.   pos2=vector.new(gps.locate())
  19.   turtle.back()
  20. end
  21.  
  22.   posDelta=pos2-pos1
  23.  
  24. local  dirFile=fs.open("/nav/dir.tab","r")
  25. local dirData=dirFile.readAll()
  26. dirFile.close()
  27. local dirTab=textutils.unserialize(dirData)
  28.  
  29.   if posDelta.x==0 and posDelta.z==-1 then
  30.     direction=2
  31.   elseif posDelta.x==0 and posDelta.z==1 then
  32.     direction=0
  33.   elseif posDelta.x==-1 and posDelta.z==0 then
  34.     direction=1
  35.   elseif posDelta.x==1 and posDelta.z==0 then
  36.     direction=3
  37.   end
  38.  
  39.   print("Current Position: ",pos1)
  40. --  print(pos2)
  41. --  print(posDelta)
  42. --  print(posDelta.x)
  43. --  print(posDelta.z)
  44.   print("Heading: ",dirTab[direction])
  45.   local data={pos1.x,pos1.y, pos1.z, direction}
  46. --  for k, v in pairs (data) do
  47. --    print (v)
  48. --  end
  49.  
  50.   file=fs.open("/nav/gpsCoord","w")
  51.   file.write(textutils.serialize(data))
  52.   file.close()
  53.   return direction
  54. else
  55.   print("No Fuel!")
  56.   i=1
  57.   while fuel==0 do  
  58.     for i=1,16 do
  59.       turtle.select(i)
  60.       refuel=turtle.refuel()
  61.       if refuel==true then
  62.         fuel=turtle.getFuelLevel
  63.       end
  64.       print("refuel: ",refuel)
  65.    
  66.       end
  67.     end
  68.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement