Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- teleport.lua
- local redstone = peripheral.find("redstone")
- local command = peripheral.find("command")
- function getRandomDirection()
- local directions = {
- {1, 0}, -- East
- {-1, 0}, -- West
- {0, 1}, -- North
- {0, -1}, -- South
- }
- return directions[math.random(1, #directions)]
- end
- function isDryLand(x, y, z)
- local block = command.getBlockInfo(x, y, z)
- local dryBlocks = {
- "minecraft:grass_block",
- "minecraft:dirt",
- "minecraft:stone",
- "minecraft:sand"
- }
- for _, b in ipairs(dryBlocks) do
- if block.name == b then
- return true
- end
- end
- return false
- end
- function teleportPlayer()
- local player = command.listPlayers()[1]
- if player then
- local posX, posY, posZ = player.position.x, player.position.y, player.position.z
- local direction = getRandomDirection()
- local newX, newZ = posX + 5 * direction[1], posZ + 5 * direction[2]
- -- Ensure the player is teleported to dry land
- while not isDryLand(newX, posY, newZ) do
- direction = getRandomDirection()
- newX, newZ = posX + 5 * direction[1], posZ + 5 * direction[2]
- end
- -- Teleport the player to the new location
- command.run("tp " .. player.name .. " " .. newX .. " " .. posY .. " " .. newZ)
- end
- end
- while true do
- if redstone.getInput("front") then
- teleportPlayer()
- end
- os.sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement