Luke_Arwolf

Untitled

Apr 11th, 2026 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. local x, y, z = 0, 0, 0
  2. local f = 0
  3. local limite = 5
  4.  
  5. print("Iniciando modo aleatorio...")
  6. print("Raio limite: " .. limite .. " blocos.")
  7.  
  8. while true do
  9. -- Checagem de Combustível!
  10. if turtle.getFuelLevel() == 0 then
  11. print("Alerta: Acabou o combustivel! Coloque carvao e digite 'refuel all'.")
  12. break -- Para o programa
  13. end
  14.  
  15. local acao = math.random(1, 5)
  16.  
  17. if acao == 1 then
  18. local nx, nz = x, z
  19. if f == 0 then nz = nz + 1
  20. elseif f == 1 then nx = nx + 1
  21. elseif f == 2 then nz = nz - 1
  22. elseif f == 3 then nx = nx - 1
  23. end
  24.  
  25. if math.abs(nx) <= limite and math.abs(nz) <= limite then
  26. if turtle.forward() then
  27. x, z = nx, nz
  28. end
  29. else
  30. turtle.turnRight()
  31. f = (f + 1) % 4
  32. end
  33.  
  34. elseif acao == 2 then
  35. if y + 1 <= limite then
  36. if turtle.up() then
  37. y = y + 1
  38. end
  39. end
  40.  
  41. elseif acao == 3 then
  42. if y - 1 >= -limite then
  43. if turtle.down() then
  44. y = y - 1
  45. end
  46. end
  47.  
  48. elseif acao == 4 then
  49. turtle.turnRight()
  50. f = (f + 1) % 4
  51.  
  52. elseif acao == 5 then
  53. turtle.turnLeft()
  54. f = (f - 1) % 4
  55. if f < 0 then f = 3 end
  56. end
  57.  
  58. os.sleep(0.5)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment