Safe teleport

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Kiri

Active Member
Jan 28, 2017
54
2
1
Skript Version: Latest skript from bensku
Skript Author: Bensku
Minecraft Version: 1.11
---
Full Code:
None


How would I go about to make sure players aren't teleported in mid air, lava, etc?
 
If you have the location the player is going to teleport to, you can:
  • Check the block below the location (if that block is lava, air, tnt, etc, don't teleport)
  • Check block in a radius of 3 or 4 around the location (if at least one of those blocks is lava, tnt, etc, don't teleport)
  • etc.
For example, you can do something like:
code_language.skript:
        set {_teleLoc} to {_teleRequest.loc}
        if block below {_teleLoc} is lava or air or tnt:
            message "&cNowhere to stand!" to player
            stop
        loop blocks in radius 3 of {_teleLoc}:
            if loop-block is tnt or lava:
                message "&cThat area isn't safe!" to player
                stop
        teleport player to {_teleLoc}
 
If you have the location the player is going to teleport to, you can:
  • Check the block below the location (if that block is lava, air, tnt, etc, don't teleport)
  • Check block in a radius of 3 or 4 around the location (if at least one of those blocks is lava, tnt, etc, don't teleport)
  • etc.
For example, you can do something like:
code_language.skript:
        set {_teleLoc} to {_teleRequest.loc}
        if block below {_teleLoc} is lava or air or tnt:
            message "&cNowhere to stand!" to player
            stop
        loop blocks in radius 3 of {_teleLoc}:
            if loop-block is tnt or lava:
                message "&cThat area isn't safe!" to player
                stop
        teleport player to {_teleLoc}

would there be a way to "look" for safe position to teleport to?
 
Something like this:
code_language.skript:
loop blocks in radius 100 around player: #or however big of a radius you want to look for safe locs in
    if loop-block is air:
        if the block above loop-block is air: #so they don't suffocate
            if the block below loop-block is not air: #make sure it's not midair
                if the block below loop-block is not lava: #make sure they don't fall in lava
                    set {_loc} to loop-block's location
                    add {_loc} to {list_of_safe_locs::*}

#then to choose a random safe loc and teleport the player to it:
set {_teleport_loc} to random element of {list_of_safe_locs::*}
teleport player to {_teleport_loc}
 
Something like this:
code_language.skript:
loop blocks in radius 100 around player: #or however big of a radius you want to look for safe locs in
    if loop-block is air:
        if the block above loop-block is air: #so they don't suffocate
            if the block below loop-block is not air: #make sure it's not midair
                if the block below loop-block is not lava: #make sure they don't fall in lava
                    set {_loc} to loop-block's location
                    add {_loc} to {list_of_safe_locs::*}

#then to choose a random safe loc and teleport the player to it:
set {_teleport_loc} to random element of {list_of_safe_locs::*}
teleport player to {_teleport_loc}
That will freeze your server for a couple seconds, no bueno
 
That will freeze your server for a couple seconds, no bueno
True. something like this maybe
code_language.skript:
while {searching_for_loc} is true:
    set {_x} to random integer between 1 and 1000
    set {_y} to random integer between 1 and 100
    set {_z} to random integer between 1 and 1000
    set {_loc} to location at {_x}, {_y}, {_z}
    set {_block} to block at {_loc}
    if {_block} is air:
        if the block above {_block} is air:
            if the block below {_block} is not air:
                if the block below {_block} is not lava:
                    set {teleport_loc} to {_loc}  
                    set {searching_for_loc} to false     
    wait a tick
 
Status
Not open for further replies.