Advertisement
dustojnikhummer

Untitled

Jan 11th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. -- teleport.lua
  2.  
  3. local redstone = peripheral.find("redstone")
  4. local command = peripheral.find("command")
  5.  
  6. function getRandomDirection()
  7. local directions = {
  8. {1, 0}, -- East
  9. {-1, 0}, -- West
  10. {0, 1}, -- North
  11. {0, -1}, -- South
  12. }
  13. return directions[math.random(1, #directions)]
  14. end
  15.  
  16. function isDryLand(x, y, z)
  17. local block = command.getBlockInfo(x, y, z)
  18. local dryBlocks = {
  19. "minecraft:grass_block",
  20. "minecraft:dirt",
  21. "minecraft:stone",
  22. "minecraft:sand"
  23. }
  24. for _, b in ipairs(dryBlocks) do
  25. if block.name == b then
  26. return true
  27. end
  28. end
  29. return false
  30. end
  31.  
  32. function teleportPlayer()
  33. local player = command.listPlayers()[1]
  34. if player then
  35. local posX, posY, posZ = player.position.x, player.position.y, player.position.z
  36. local direction = getRandomDirection()
  37. local newX, newZ = posX + 5 * direction[1], posZ + 5 * direction[2]
  38.  
  39. -- Ensure the player is teleported to dry land
  40. while not isDryLand(newX, posY, newZ) do
  41. direction = getRandomDirection()
  42. newX, newZ = posX + 5 * direction[1], posZ + 5 * direction[2]
  43. end
  44.  
  45. -- Teleport the player to the new location
  46. command.run("tp " .. player.name .. " " .. newX .. " " .. posY .. " " .. newZ)
  47. end
  48. end
  49.  
  50. while true do
  51. if redstone.getInput("front") then
  52. teleportPlayer()
  53. end
  54. os.sleep(1)
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement