Solved Random teleport : Avoid certains biome (Teams)

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

Status
Not open for further replies.

Aralwen

Active Member
May 26, 2017
164
14
18
25
Hello guys,

I am trying to make that command /rtpteams choose random positions that are not in the blacklist biomes and subsequently teleports the teams to their spawn. What I did, except that sometimes the player falls on a blacklisted biome and i don't know where the problem comes from.

My actual skript :

code_language.skript:
command /rtpteams:
    trigger:
        set {_Game.Tp.Blue} to location(random number from -1500 to 1500, 100, random number from -1500 to 1500, world("world"))
        set {_Game.Tp.Red} to location(random number from -1500 to 1500, 100, random number from -1500 to 1500, world("world"))
        loop all players:
            set {searching_for_location.%loop-player%} to true
            while {searching_for_location.%loop-player%} is true:
                remove resistance from the loop-player
                apply resistance 10 to loop-player for 30 seconds
                if biome at {_Game.Tp.Blue} and {_Game.Tp.Red} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    if {Game.Team::%loop-player%} is "Blue":
                        teleport loop-player to {_Game.Tp.Blue}
                        set {searching_for_location.%loop-player%} to false
                    if {Game.Team::%loop-player%} is "Red":
                        teleport loop-player to {_Game.Tp.Red}
                        set {searching_for_location.%loop-player%} to false
                    wait 1 tick

Rapid explanations :
- {_Game.Tp.Red} is the location for Red team.
- {_Game.Tp.Blue} is the location for Blue team.

@Donut I tag you because you helped me before, so if you have the time and the urge to take a look :emoji_slight_smile:
Thank's ! :emoji_wink:

Skript Version: 2.2
Skript Author: ?
Minecraft Version: 1.8.8


Errors on Reload : Nothing
Console Errors : Nothing


Troubleshooting:

Have you tried searching the docs? Yes
Have you tried searching the forums ? Yes
 
Line 17 needs to be de-dented 4 spaces.

Line 3 and 4 need to be within the while loop because right now you're just checking the same position over and over again which reminds me that you should probably add fail safe to prevent it from checking coordinates indefinitely (like after 15 seconds if it hasn't found a valid coord then stop the while loop).

However, neither of those issues should affect your actual question so I would suggest splitting it into 2 while loops. One that will find the blue team location and one that will find the red team location. Then once it has found both teleport the players. Also, double check that you're using the correct names for all of the biomes.
 
  • Like
Reactions: Aralwen
Line 17 needs to be de-dented 4 spaces.

Line 3 and 4 need to be within the while loop because right now you're just checking the same position over and over again which reminds me that you should probably add fail safe to prevent it from checking coordinates indefinitely (like after 15 seconds if it hasn't found a valid coord then stop the while loop).

However, neither of those issues should affect your actual question so I would suggest splitting it into 2 while loops. One that will find the blue team location and one that will find the red team location. Then once it has found both teleport the players. Also, double check that you're using the correct names for all of the biomes.

Can you give me an example for 2 teams in code if you have the time and the envy? Otherwise it does not matter you have already helped me so much, thank's :emoji_slight_smile:
 
You should try writing it yourself so you can learn and also are you trying to teleport all of the blue team to one location and all of the red team to one location? If so, you don't need to loop all players. You can just find a valid location for the team then loop all players in that team (you would need to make a list variable with all the team members if you don't have one already) and teleport them to their teams location.
 
You should try writing it yourself so you can learn and also are you trying to teleport all of the blue team to one location and all of the red team to one location? If so, you don't need to loop all players. You can just find a valid location for the team then loop all players in that team (you would need to make a list variable with all the team members if you don't have one already) and teleport them to their teams location.
Okay, I'll see. Thank you ! :emoji_slight_smile:
[doublepost=1496771181,1496725571][/doublepost]
You should try writing it yourself so you can learn and also are you trying to teleport all of the blue team to one location and all of the red team to one location? If so, you don't need to loop all players. You can just find a valid location for the team then loop all players in that team (you would need to make a list variable with all the team members if you don't have one already) and teleport them to their teams location.
Hello @Donut,

I tried to make a code, this one now works niquel for the biomes, but the players being on the same team are not teleported to the same location. Also, for your security system so as not to check indefinitely, i did not understand too much how to set it up

Actual code :

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            set {Game.Team::%arg-player%} to "Red"
            send "&aOK"
        if arg 2 is "blue":
            set {Game.Team::%arg-player%} to "Blue"
            send "&aOK"
          
command /tinfo:
    trigger:
        send "&6You're %{Game.Team::%player%}%"
  

command /tpr:
    trigger:
        loop all players:
            set {searching_for_location.%loop-player%} to true
            while {searching_for_location.%loop-player%} is true:
                set {_Game.Tp.Red} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                set {_Game.Tp.Blue} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                remove resistance from the loop-player
                apply resistance 10 to loop-player for 30 seconds
                if biome at {_Game.Tp.Red} and {_Game.Tp.Blue} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Red}:
                        if loop-block is air:
                            set {_RandomLocation.Red} to location of loop-block
                            if {Game.Team::%loop-player%} is "Red":
                                teleport loop-player to {_RandomLocation.Red}
                                set {searching_for_location.%loop-player%} to false
                    loop blocks above {_Game.Tp.Blue}:
                        if loop-block is air:
                            set {_RandomLocation.Blue} to location of loop-block         
                            if {Game.Team::%loop-player%} is "Blue":
                                teleport loop-player to {_RandomLocation.Blue}
                                set {searching_for_location.%loop-player%} to false
                wait 1 tick

Thank's ! :emoji_wink:
 
The players aren't teleporting to the same location because you're finding a new team location for each player (looping all players).

This should work:

code_language.skript:
command /tpr:
    trigger:
        set {searching_for_team_locations} to true
        set {need_red_team_loc} to true
        set {need_blue_team_loc} to true
      
        set {started_searching_for_location} to now #This will be used for the time check
      
        while {searching_for_team_locations} is true:

            set {searching_time} to difference between {started_searching_for_location} and now
            if {searching_time} is greater than 15 seconds: #Or however long you want
                set {searching_for_team_locations} to false
                broadcast "Could not find a valid spawn location!"
      
            if {need_red_team_loc} is true:
                set {_Game.Tp.Red} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Red} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Red}:
                        if loop-block is air:
                            set {RandomLocation.Red} to location of loop-block
                            set {need_red_team_loc} to false
          
            if {need_blue_team_loc} is true:
                set {_Game.Tp.Blue} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Blue} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Blue}:
                        if loop-block is air:
                            set {RandomLocation.Blue} to location of loop-block
                            set {need_blue_team_loc} to false
                          
            if {need_red_team_loc} is false:
                if {need_blue_team_loc} is false:
                    loop {players_on_red_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Red}
                    loop {players_on_blue_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Blue}
                    set {searching_for_team_locations} to false
            wait 1 tick
 
Last edited by a moderator:
  • Like
Reactions: Aralwen
The players aren't teleporting to the same location because you're finding a new team location for each player (looping all players).

This should work:

code_language.skript:
command /tpr:
    trigger:
        set {searching_for_team_locations} to true
        set {need_red_team_loc} to true
        set {need_blue_team_loc} to true
    
        set {started_searching_for_location} to now #This will be used for the time check
    
        while {searching_for_team_locations} is true:

            set {searching_time} to difference between {started_searching_for_location} and now
            if {searching_time} is greater than 15 seconds: #Or however long you want
                set {searching_for_team_locations} to false
                broadcast "Could not find a valid spawn location!"
    
            if {need_red_team_loc} is true:
                set {_Game.Tp.Red} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Red} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Red}:
                        if loop-block is air:
                            set {RandomLocation.Red} to location of loop-block
                            set {need_red_team_loc} to false
        
            if {need_blue_team_loc} is true:
                set {_Game.Tp.Blue} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Blue} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Blue}:
                        if loop-block is air:
                            set {RandomLocation.Blue} to location of loop-block
                            set {need_blue_team_loc} to false
                        
            if {need_red_team_loc} is false:
                if {need_blue_team_loc} is false:
                    loop {players_on_red_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Red}
                    loop {players_on_blue_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Blue}
                    set {searching_for_team_locations} to false
            wait 1 tick

This works perfect, except that the player floats in the air for 15 seconds, he can not move and after the message "Could not find a valid spawn location!" is broadcasted even if the positions have been found

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            add arg-player to {players_on_red_team::*}
            send "&aOK"
        if arg 2 is "blue":
            add arg-player to {players_on_blue_team::*}
            send "&aOK"
            
command /tinfo:
    trigger:
        send "&6You're %{Game.Team::%player%}%"
        send "%{players_on_red_team::*}%"
        send "%{players_on_blue_team::*}%"
        
command /cl:
    trigger:
        clear {players_on_blue_team::*}
        clear {players_on_red_team::*}
        send "&aOK"
    

command /tpr:
    trigger:
        set {searching_for_team_locations} to true
        set {need_red_team_loc} to true
        set {need_blue_team_loc} to true
      
        set {started_searching_for_location} to now #This will be used for the time check
      
        while {searching_for_team_locations} is true:
 
            set {searching_time} to difference between {started_searching_for_location} and now
            if {searching_time} is greater than 15 seconds: #Or however long you want
                set {searching_for_team_locations} to false
                broadcast "Could not find a valid spawn location!"
      
            if {need_red_team_loc} is true:
                set {_Game.Tp.Red} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Red} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Red}:
                        if loop-block is air:
                            set {RandomLocation.Red} to location of loop-block
                            set {need_red_team_loc} to false
          
            if {need_blue_team_loc} is true:
                set {_Game.Tp.Blue} to location(random number from -1500 to 1500, 130, random number from -1500 to 1500, world("world"))
                if biome at {_Game.Tp.Blue} is not desert or desert hills or jungle or jungle hills or mesa or ocean or mushroom island or deep ocean or frozen ocean or frozen river or cold beach or stone beach or ice plains or ice mountains or ice plains spikes:
                    loop blocks above {_Game.Tp.Blue}:
                        if loop-block is air:
                            set {RandomLocation.Blue} to location of loop-block
                            set {need_blue_team_loc} to false
                          
            if {need_red_team_loc} is false:
                if {need_blue_team_loc} is false:
                    loop {players_on_red_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Red}
                    loop {players_on_blue_team::*}: #Add players to this variable when they do the /team command
                        teleport loop-value to {RandomLocation.Blue}
            wait 1 tick
 
Do you have line 38 as "set {searching_for_team_locations} to false" because I added that in after posting it.
You're a genius, i have one last question then I finally leave you quiet xD
Before I used a team system that was not in lists but defined a variable: How do I adapt it to lists? without the need to remove the player from all previous list everytime, is there a way ? And how to detect if the player is in the list?



Skript Before :

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            set {Game.Team::%arg-player%} to "Red"
            send "&aOK"
        if arg 2 is "blue":
            set {Game.Team::%arg-player%} to "Blue"
            send "&aOK"
        if arg 2 is "orange":
            set {Game.Team::%arg-player%} to "Orange"
            send "&aOK"
        if arg 2 is "yellow":
            set {Game.Team::%arg-player%} to "Yellow"
            send "&aOK"
          
on chat:
    if {Game.Team::%player%} is "Red":
        cancel event
        broadcast "&f(All) &c%player% &f» %message%"
    if {Game.Team::%player%} is "Blue":
        cancel event
        broadcast "&f(All) &9%player% &f» %message%"
    if {Game.Team::%player%} is "Orange":
        cancel event
        broadcast "&f(All) &6%player% &f» %message%"
    if {Game.Team::%player%} is "Yellow":
        cancel event
        broadcast "&f(All) &e%player% &f» %message%"


Skript now with new system :

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            add player to {players_on_red_team::*}
            send "&aOK"
        if arg 2 is "blue":
            add player to {players_on_blue_team::*}
            send "&aOK"
        if arg 2 is "orange":
            add player to {players_on_orange_team::*}
            send "&aOK"
        if arg 2 is "yellow":
            add player to {players_on_yellow_team::*}
            send "&aOK"
          
on chat:
    if ... ?
        cancel event
        broadcast "&f(All) &c%player% &f» %message%"
    if ... ?
        cancel event
        broadcast "&f(All) &9%player% &f» %message%"
    if ... ?
        cancel event
        broadcast "&f(All) &6%player% &f» %message%"
    if ... ?
        cancel event
        broadcast "&f(All) &e%player% &f» %message%"
 
Last edited by a moderator:
The easiest way is to just have a normal variable for the player as well as having them in the list.

You have to remove them from their previous list every time though, there's no way around that. However, you don't really need to check what their previous team was, you can just remove them from all the teams since nothing will happen if you remove them from a list that they're not in.. Ex)

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            remove player from {players_on_red_team::*}
            remove player from {players_on_blue_team::*}
            remove player from {players_on_orange_team::*}
            remove player from {players_on_yellow_team::*}
            add player to {players_on_red_team::*}
            set {team.%player%} to "Red"
            send "&aOK"
           
on chat:
    if {team.%player%} is "Red"
        cancel event
        broadcast "&f(All) &c%player% &f» %message%"
 
  • Like
Reactions: Aralwen
The easiest way is to just have a normal variable for the player as well as having them in the list.

You have to remove them from their previous list every time though, there's no way around that. However, you don't really need to check what their previous team was, you can just remove them from all the teams since nothing will happen if you remove them from a list that they're not in.. Ex)

code_language.skript:
command /team [<player>] [<text>]:
    trigger:
        if arg 2 is "red":
            remove player from {players_on_red_team::*}
            remove player from {players_on_blue_team::*}
            remove player from {players_on_orange_team::*}
            remove player from {players_on_yellow_team::*}
            add player to {players_on_red_team::*}
            set {team.%player%} to "Red"
            send "&aOK"
         
on chat:
    if {team.%player%} is "Red"
        cancel event
        broadcast "&f(All) &c%player% &f» %message%"

Okay ! Really thank you for all the help you gave me, good evening ! :emoji_slight_smile:

Solved ~
 
Status
Not open for further replies.