Hey, I have a question about testfor command blocks.
I currently have one that detects players in a certain scoreboard group. If the testfor is true, I want it to say a certain message that I already have planned out, and if the testfor is false I would like it to say a different msg.
How would I go about making it so it can say two different messages based on it being true or false?
if the test for is true, I need this command block to run:
/tellraw @a[r=30] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"If you need help getting started, ","color":"gray","bold":false},{"selector":"@a[score_PlayerHelper_min=1]","color":"gold"},{"text":" is a player helper. I will let them know you need some help getting started!","color":"gray"}]
and if it is false, this command blocks needs to run:
/tellraw @p ["",{"text":"Server: ","color":"gold","bold":true},{"text":"There are no player helpers online at the moment :(. Try to see if ","color":"gray","bold":false},{"text":"/warp helphub or /faq","color":"gold"},{"text":"can answer your questions! :D","color":"gray"}]
So, now I just need one of the two messages to run if the testfor is true or false.
/tellraw @a[tag=help] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"If you need help getting started, ","color":"gray","bold":false},{"selector":"@a[score_PlayerHelper_min=1]","color":"gold"},{"text":" is a player helper. I will let them know you need some help getting started!","color":"gray"}]
/tellraw @a[tag=!help] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"There are no player helpers online at the moment :(. Try to see if ","color":"gray","bold":false},{"text":"/warp helphub or /faq","color":"gold"},{"text":"can answer your questions! :D","color":"gray"}]
I wrote a data pack that has people in teams. Regular players are in Players and have blue names. MVP players are green. Moderators are red. Operators are light purple. Owner is orange. When a player first starts the game, they're given an intro that explains that if they need help, anyone with a name color other than blue is a good resource.
It also periodically sends out a server message, part of which includes a message about which moderators are online.
Not exactly. In the server I am at there is a group of people called "Player Helpers" (scoreboard: PlayerHelper). What I need it to do is when a new player clicks a certain button, either a message saying "XYZ are player helpers(...)" or "There are no player helpers online(...)". I just don't know how to make a testfor have multiple uses based on true / false.
So, you can have a message be sent to a player that tells them which players are tagged with a specific tag, or are on a specific team. That's easy enough. For instance, I'm using this in 1.13 to tell all players which players are tagged with the AFK tag. It targets the nearest player that is AFK (or no one, if no one is AFK). If it finds an AFK player, it then runs tellraw on everyone. The message that gets sent out will include a list of all players who are AFK. This will never sent out an empty message, as if there are no AFK players, it fails to begin with.
execute at @p[tag=AFK] run tellraw @a [{"color":"dark_purple","italic":true,"text":" AFK Players: "},{"selector":"@a[tag=AFK]"}]
So you could replace it as such
execute at @p[tag=PlayerHelper] run tellraw @a [{"color":"dark_purple","italic":true,"text":" AFK Players: "},{"selector":"@a[tag=PlayerHelper]"}]
Hey, I have a question about testfor command blocks.
I currently have one that detects players in a certain scoreboard group. If the testfor is true, I want it to say a certain message that I already have planned out, and if the testfor is false I would like it to say a different msg.
How would I go about making it so it can say two different messages based on it being true or false?
Thanks
Do not use testfor. Instead use execute. You can use ! in selectors to check if the entity is NOT in this condiction.
For example: /execute @a[team=foo] ~ ~ ~ tellraw @a {"text":"yo this dude is in foo"}
/execute @a[team=!foo] ~ ~ ~ tellraw @a {"text":"this weirdo here surely aint on foo"}
Could execute's work on detecting a leaderboard?
Here is what I currently have:
/testfor @a[score_PlayerHelper_min=1]
if the test for is true, I need this command block to run:
/tellraw @a[r=30] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"If you need help getting started, ","color":"gray","bold":false},{"selector":"@a[score_PlayerHelper_min=1]","color":"gold"},{"text":" is a player helper. I will let them know you need some help getting started!","color":"gray"}]
and if it is false, this command blocks needs to run:
/tellraw @p ["",{"text":"Server: ","color":"gold","bold":true},{"text":"There are no player helpers online at the moment :(. Try to see if ","color":"gray","bold":false},{"text":"/warp helphub or /faq","color":"gold"},{"text":"can answer your questions! :D","color":"gray"}]
So, now I just need one of the two messages to run if the testfor is true or false.
How can I run that into a /execute command?
Anyone able to help?
Instead of the scoreboard objective, use a tag and do what I expained earlier
I guess I don't understand what that is can you explain how I would make what I have into that? Thanks!
Instead of the scoreboard score, tag them https://minecraft.gamepedia.com/Scoreboard#Tags_commands
Then detect the tag with @a[tag=foo,tag=!bar]
/tellraw @a[tag=help] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"If you need help getting started, ","color":"gray","bold":false},{"selector":"@a[score_PlayerHelper_min=1]","color":"gold"},{"text":" is a player helper. I will let them know you need some help getting started!","color":"gray"}]
/tellraw @a[tag=!help] ["",{"text":"Server: ","color":"gold","bold":true},{"text":"There are no player helpers online at the moment :(. Try to see if ","color":"gray","bold":false},{"text":"/warp helphub or /faq","color":"gold"},{"text":"can answer your questions! :D","color":"gray"}]
1.12 or 1.13?
1.12
I wrote a data pack that has people in teams. Regular players are in Players and have blue names. MVP players are green. Moderators are red. Operators are light purple. Owner is orange. When a player first starts the game, they're given an intro that explains that if they need help, anyone with a name color other than blue is a good resource.
It also periodically sends out a server message, part of which includes a message about which moderators are online.
Would this do what you need?
Not exactly. In the server I am at there is a group of people called "Player Helpers" (scoreboard: PlayerHelper). What I need it to do is when a new player clicks a certain button, either a message saying "XYZ are player helpers(...)" or "There are no player helpers online(...)". I just don't know how to make a testfor have multiple uses based on true / false.
anyone?
So, you can have a message be sent to a player that tells them which players are tagged with a specific tag, or are on a specific team. That's easy enough. For instance, I'm using this in 1.13 to tell all players which players are tagged with the AFK tag. It targets the nearest player that is AFK (or no one, if no one is AFK). If it finds an AFK player, it then runs tellraw on everyone. The message that gets sent out will include a list of all players who are AFK. This will never sent out an empty message, as if there are no AFK players, it fails to begin with.
So you could replace it as such