Best way to optimize this skript?

  • 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 comminuty!

    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!

N1coNico

New Member
Oct 7, 2024
3
0
1
20
Any tips.... the loop all players is prob not a good idea to do but me dumb and need help to find a better way please.. thanks

The Idea of this Skript is to limit how high a player can go into the air and teleported them back to build high after they go above a set limit
and auto kill the player is they go below bedrock after a set limit

Code:
# The number of blocks above the build limit a player is allowed to go
options:
    build-limit: 256  # Default Minecraft build limit, adjust if necessary
    height-limit: 30  # Number of blocks above the build limit allowed before being teleported
    bedrock-limit: -5  # Y-coordinate for bedrock layer

# Periodically check for players who are too high or too low
every 1 second:
    loop all players:
        # Check if the player is too high
        if loop-player's y-coordinate > ({@build-limit} + {@height-limit}):
            # Notify the player if they are too high
            send "&cYou are too high in the air! You will be teleported back down." to loop-player
          
            # Teleport the player to the build limit
            set {_teleportLocation} to location at loop-player's x-coordinate, {@build-limit}, loop-player's z-coordinate in loop-player's world
            teleport loop-player to {_teleportLocation}
          
            # Disable flight if the player is flying
            if loop-player is flying:
                set loop-player's flight mode to false

        # Check if the player is too low (below bedrock)
        if loop-player's y-coordinate < {@bedrock-limit}:
            if loop-player is alive:
                # Notify the player and kill them for going too low
                send "&cYou have gone too far below bedrock! You will die now." to loop-player
                kill loop-player
 
i think the best that below

Code:
options:
    build-limit: 256
    height-limit: 30
    bedrock-limit: -5
on player move:
    if player's y-coordinate >= ({@build-limit} + {@height-limit}):
        teleport player to (location at player's x-coordinate, {@build-limit}, player's z-coordinate in player's world)
        set player's flight mode to false
        send "&cYou are too high in the air! You will be teleported back down."
    if player's y-coordinate < {@bedrock-limit}:
        send "&cYou have gone too far below bedrock! You will die now."
        kill player
 
Last edited:
i think the best that below

Code:
options:
    build-limit: 256
    height-limit: 30
    bedrock-limit: -5
on player move:
    if player's y-coordinate >= ({@build-limit} + {@height-limit}):
        teleport player to (location at player's y-coordinate, {@build-limit}, player's z-coordinate in player's world)
        set player's flight mode to false
        send "&cYou are too high in the air! You will be teleported back down."
    if player's y-coordinate < {@bedrock-limit}:
        send "&cYou have gone too far below bedrock! You will die now."
        kill player
notice: 'optimize'
 
notice: 'optimize'
Since the skript is used, this is the case. If more optimization is desired, a plugin is recommended.

Actually, even though the last event is constantly triggered, it is optimized according to the conditions.
 
Since the skript is used, this is the case. If more optimization is desired, a plugin is recommended.

Actually, even though the last event is constantly triggered, it is optimized according to the conditions.
"yeah guys this is way more optimized" *shows code that's 20x less optimized*
 
You can share your codes
code_language.skript:
# The number of blocks above the build limit a player is allowed to go
options:
    build-limit: 256  # Default Minecraft build limit, adjust if necessary
    height-limit: 30  # Number of blocks above the build limit allowed before being teleported
    bedrock-limit: -5  # Y-coordinate for bedrock layer

# Periodically check for players who are too high or too low
every 1 second:
    loop all players:
        # Check if the player is too high
        loop-player is alive
        if loop-player's y-coordinate > ({@build-limit} + {@height-limit}):
            # Notify the player if they are too high
            send "&cYou are too high in the air! You will be teleported back down." to loop-player
          
            # Teleport the player to the build limit
            set {_teleportLocation} to location at loop-player's x-coordinate, {@build-limit}, loop-player's z-coordinate in loop-player's world
            teleport loop-player to {_teleportLocation}
          
            # Disable flight
            set loop-player's flight mode to false

        # Check if the player is too low (below bedrock)
        if loop-player's y-coordinate < {@bedrock-limit}:
            # Notify the player and kill them for going too low
            send "&cYou have gone too far below bedrock! You will die now." to loop-player
            kill loop-player
 
code_language.skript:
# The number of blocks above the build limit a player is allowed to go
options:
    build-limit: 256  # Default Minecraft build limit, adjust if necessary
    height-limit: 30  # Number of blocks above the build limit allowed before being teleported
    bedrock-limit: -5  # Y-coordinate for bedrock layer

# Periodically check for players who are too high or too low
every 1 second:
    loop all players:
        # Check if the player is too high
        loop-player is alive
        if loop-player's y-coordinate > ({@build-limit} + {@height-limit}):
            # Notify the player if they are too high
            send "&cYou are too high in the air! You will be teleported back down." to loop-player
         
            # Teleport the player to the build limit
            set {_teleportLocation} to location at loop-player's x-coordinate, {@build-limit}, loop-player's z-coordinate in loop-player's world
            teleport loop-player to {_teleportLocation}
         
            # Disable flight
            set loop-player's flight mode to false

        # Check if the player is too low (below bedrock)
        if loop-player's y-coordinate < {@bedrock-limit}:
            # Notify the player and kill them for going too low
            send "&cYou have gone too far below bedrock! You will die now." to loop-player
            kill loop-player
Some code but really is it necessary loop-player is alive? Already every player is alive