Say I want to have a command that applies to everyone on a server except 2 people. Is there a target selector for that?
In order to do an all-but target selector, you need to add an exclamation point (!) before the name of the thing excluded from the command.
For example, the command
would return true if there is a player other than the player with the name IfThenElse online when the command is executed. In order to modify this command, simply replace the name IfThenElse with a different username.
With the all-but you can make an effective entity clearer:
This would kill all entities (minecarts, mobs, dropped items) except for players.
However, since you can only select one all-but name, the scoreboard must be used.
Start by using the command
/scoreboard objectives add testnot dummy
and setting testnot to 1 on players you don't want to be effected by whatever command:
/scoreboard players set IfThenElse testnot 1
Replace IfThenElse with a username. Then you can run a command with the target selector
@a[score_testnot=0], which would effect everyone but the players who had their testnot score set to 1.
I'm going to be surprised if I got the command syntax right. Edit as needed.
Normal target selectors cannot select 2 specific people, the solution is to use a scoreboard to mark the players.
/scoreboard objectives add Selector dummy
/scoreboard players set @a[name=<Name of Target>] Selector 1 //One of these commands per person /scoreboard players set @a[score_Selector_min!=1] Selector 0
@a[score_Selector=0] to select non selected
So from what people have said and some of my own research here's the easiest way to do this:
Set up a scoreboard, called ExcludeSelection for example:
/scoreboard objectives add ExcludeSelection dummy
Set the players you want to exclude to 1 in this scoreboard:
/scoreboard players set <username> ExcludeSelection 1(do this for every player you want to exclude)
Add 0 to all player's scores (basically this adds players not on the scoreboard to the scoreboard without messing up existing values):
scoreboard players add @a 0(in a loop, perhaps a setblock clock)
And then to select all players except the ones you want to exclude, just use:
I personally am using this to prevent anyone except the co-owners of the server (moi and my friend) from using creative mode. Just because I feel like it, here's what I think I'm going to do in addition to the first four steps.
In a setblock clock, I'll put
tell @a[score_ExcludeSelection=0,m=1] You are not allowed to use creative mode. in one command block, and in another,
gamemode @a[score_ExcludeSelection=0,m=1] survival.