Advertisement
Guest User

PortableSensor

a guest
Oct 20th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. sensor = peripheral.wrap("left")
  2. modemw = peripheral.wrap("right")
  3.  
  4. local function moveto(dirant,diratu)
  5.  
  6. if dirant == "norte" then
  7.   if diratu == "leste" then
  8.   turtle.turnRight()
  9.   elseif diratu == "oeste" then
  10.   turtle.turnLeft()
  11.   elseif diratu == "sul" then
  12.   turtle.turnRight()
  13.   turtle.turnRight()
  14.   end
  15. elseif dirant == "leste" then
  16.   if diratu == "sul" then
  17.   turtle.turnRight()
  18.   elseif diratu == "norte" then
  19.   turtle.turnLeft()
  20.   elseif diratu == "oeste" then
  21.   turtle.turnRight()
  22.   turtle.turnRight()
  23.   end
  24. elseif dirant == "sul" then
  25.   if diratu == "oeste" then
  26.   turtle.turnRight()
  27.   elseif diratu == "leste" then
  28.   turtle.turnLeft()
  29.   elseif diratu == "norte" then
  30.   turtle.turnRight()
  31.   turtle.turnRight()
  32.   end
  33. elseif dirant == "oeste" then
  34.   if diratu == "norte" then
  35.   turtle.turnRight()
  36.   elseif diratu == "sul" then
  37.   turtle.turnLeft()
  38.   elseif diratu == "leste" then
  39.   turtle.turnRight()
  40.   turtle.turnRight()
  41.   end
  42. end
  43.  
  44. if turtle.detect() == true then
  45. turtle.equipRight()
  46. turtle.dig()
  47. turtle.equipRight()
  48. end
  49.  
  50. turtle.forward()
  51.  
  52. end
  53.  
  54.  
  55. local function glassradar()
  56.  
  57.   pnames = sensor.getPlayerNames()
  58.   mobids = sensor.getMobIds()
  59.   numnames = #pnames
  60.   numids = #mobids
  61.   tabinfo={}
  62.  
  63.  
  64.   for n=1,numnames do
  65.  
  66.     pinfo = sensor.getPlayerData(pnames[n])
  67.    
  68.     a=((n*3)-2)
  69.     b=((n*3)-1)
  70.     c=(n*3)
  71.    
  72.     infoposi = pinfo["position"]
  73.     posx = tonumber(infoposi["x"])
  74.     posy = tonumber(infoposi["z"])
  75.  
  76.     aposx = math.floor(posx+0.5)
  77.    
  78.     aposy = math.floor(posy+0.5)
  79.  
  80.     xdotcc = (aposx + 24)
  81.     ydotcc = (aposy + 24)
  82.  
  83.     if xdotcc > 47 then xfinal = "47"
  84.     elseif xdotcc < 1 then xfinal = "1"
  85.     else xfinal = tostring(xdotcc)
  86.     end
  87.  
  88.     if ydotcc > 47 then yfinal = "47"
  89.     elseif ydotcc < 1 then yfinal= "1"
  90.     else yfinal = tostring(ydotcc)
  91.     end
  92.    
  93.     if pnames[n] == "TorakWolf" then
  94.     cor = "w"
  95.     else
  96.     cor = "r"
  97.     end
  98.    
  99.     tabinfo[a] = cor
  100.     tabinfo[b] = xfinal
  101.     tabinfo[c] = yfinal
  102.  
  103.   end
  104.  
  105.    for h=1,numids do
  106.  
  107.     mobinfo = sensor.getMobData(mobids[h])
  108.    
  109.     d=(((h*3)-2)+numnames*3)
  110.     e=(((h*3)-1)+numnames*3)
  111.     f=((h*3)+(numnames*3))
  112.    
  113.     infoposi = mobinfo["position"]
  114.     posx = tonumber(infoposi["x"])
  115.     posy = tonumber(infoposi["z"])
  116.  
  117.     aposx = math.floor(posx+0.5)
  118.    
  119.     aposy = math.floor(posy+0.5)
  120.  
  121.     xdotcc = (aposx + 24)
  122.     ydotcc = (aposy + 24)
  123.  
  124.     if xdotcc > 47 then xfinal = "47"
  125.     elseif xdotcc < 1 then xfinal = "1"
  126.     else xfinal = tostring(xdotcc)
  127.     end
  128.  
  129.     if ydotcc > 47 then yfinal = "47"
  130.     elseif ydotcc < 1 then yfinal= "1"
  131.     else yfinal = tostring(ydotcc)
  132.     end
  133.    
  134.     if mobinfo["type"] == "Zombie" or mobinfo["type"] == "Skeleton" or mobinfo["type"] == "Spider"then
  135.     cor = "o"
  136.     else
  137.     cor = "g"
  138.     end
  139.    
  140.     tabinfo[d] = cor
  141.     tabinfo[e] = xfinal
  142.     tabinfo[f] = yfinal
  143.    
  144.    
  145.   end
  146.    
  147.   msgfinalser = textutils.serialize(tabinfo)
  148.   modemw.transmit(1310,1,msgfinalser)
  149.   sleep(0.3)
  150.  
  151. end
  152.  
  153.  
  154. direcao = "norte"
  155.  
  156. term.clear()
  157. term.setCursorPos(1,1)
  158. print("Insert Your Nickname / Insira Seu Nome de Jogador")
  159. nickname = io.read()
  160.  
  161. term.clear()
  162. term.setCursorPos(1,1)
  163. print("Insert the Turtle Height / Insira a Altura da Turtle")
  164. altura = tonumber(io.read())
  165.  
  166. term.clear()
  167. term.setCursorPos(1,1)
  168. print("Following"..nickname.." / Seguindo "..nickname)
  169.  
  170.  
  171. while 1 == 1 do
  172. posicao = "naoconferida"
  173. yourinfo = sensor.getPlayerData(nickname)
  174.  
  175.  
  176. xpronto = math.floor((tonumber(yourinfo["position"]["x"]))+0.5)
  177. zpronto = math.floor((tonumber(yourinfo["position"]["z"]))+0.5)
  178. ypronto = math.floor(((tonumber(yourinfo["position"]["y"]))+0.5)+altura)
  179.  
  180.   if ypronto > 0 then
  181.     if turtle.detectUp() == true then
  182.         turtle.equipRight()
  183.         turtle.digUp()
  184.         turtle.equipRight()
  185.         end
  186.   turtle.up()
  187.  
  188.   elseif ypronto < 0 then
  189.     if turtle.detectDown() == true then
  190.         turtle.equipRight()
  191.         turtle.digDown()
  192.         turtle.equipRight()
  193.         end
  194.   turtle.down()
  195.  
  196.   elseif ypronto == 0 then
  197.    
  198.         if zpronto > 0 then
  199.     moveto(direcao,"sul")
  200.         direcao = "sul"
  201.        
  202.         elseif zpronto < 0 then
  203.         moveto(direcao,"norte")
  204.         direcao = "norte"
  205.        
  206.           elseif zpronto == 0 then
  207.          
  208.           if xpronto > 0 then
  209.           moveto(direcao,"leste")
  210.           direcao = "leste"
  211.          
  212.           elseif xpronto < 0 then
  213.           moveto(direcao,"oeste")
  214.           direcao = "oeste"
  215.          
  216.           elseif xpronto == 0 then
  217.           posicao = "conferida"
  218.          
  219.           end
  220.          
  221.         end
  222.        
  223.   end
  224.  
  225.   if posicao == "conferida" then
  226.   glassradar()
  227.   end
  228.  
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement