4

Say I want to have a command that applies to everyone on a server except 2 people. Is there a target selector for that?

0

3 Answers 3

1

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

/testfor @a[name=!IfThenElse]

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:

/kill @e[type=!Player]

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.

4
  • 2 people, not 1
    – Moddl
    Commented Aug 24, 2015 at 3:54
  • @ModDL Would adding another name=! not work? Commented Aug 24, 2015 at 3:55
  • Nope, one per command
    – Moddl
    Commented Aug 24, 2015 at 3:56
  • Well, oops. I'll change my answer on that case. Commented Aug 24, 2015 at 3:56
0

Normal target selectors cannot select 2 specific people, the solution is to use a scoreboard to mark the players.

Setup:

/scoreboard objectives add Selector dummy

Clock:

/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

Selector:

@a[score_Selector=0] to select non selected
6
  • Do players automatically get added to the Selector scoreboard as having a score of 0?
    – spelchekr
    Commented Aug 24, 2015 at 4:56
  • Just reminded me that i needed to add them to the scoreboard
    – Moddl
    Commented Aug 24, 2015 at 5:02
  • So why not just use @a[score_Selector_min!=1]in the first place? Also, what's _min do?
    – spelchekr
    Commented Aug 24, 2015 at 14:02
  • _min means the minimum amount of score they need, and well i guess you can do it with a _min=!1
    – Moddl
    Commented Aug 24, 2015 at 20:01
  • So @a[score_someVariable_min=1] is basically how to do @a[score_someVariable>=1], right?
    – spelchekr
    Commented Aug 25, 2015 at 2:16
0

So from what people have said and some of my own research here's the easiest way to do this:

  1. Set up a scoreboard, called ExcludeSelection for example:

    /scoreboard objectives add ExcludeSelection dummy

  2. 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)

  3. 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)

  4. And then to select all players except the ones you want to exclude, just use:

    @a[score_ExcludeSelection=0]

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.