0

I am making a map and I need to testfor the last player alive in the arena. I tried with selectors, but I am not really into this. Can someone help me out?

1
  • use /stats in combination with testfor Commented May 5, 2016 at 15:50

2 Answers 2

0

You can use /testforblock to check the success of a command block.

Repeating > conditional chain > conditional chain

  1. Test for the number of players in the area. The c value is set to 2 to lower the amount of processing that would need to be done (since you only want to know if there are 1 or more players).

    /testfor @a[10,64,10,30,c=2]
    
  2. Conditional. Check the SuccessCount value of the repeating command block. Change X Y Z to the repeating command block's coordinates.

    /testforblock X Y Z minecraft:repeating_command_block -1 {SuccessCount:1}
    
  3. Conditional. Command to run if there was only 1 player.

    /say Finished.
    
2
  • Can you tell me what "10,64,10,30" means? They are coordinates?
    – iDoomfull
    Commented May 5, 2016 at 17:31
  • @iDoomfull Yes, it's the short-hand method of specifying coordinates and a radius. At the beginning of the parameters you can specify just numbers, which represents "x", "y", "z", and "r" in that order. It would be the same as @a[x=10,y=64,z=10,r=30] (and is up to you which you want to use, as the only difference is convenience).
    – Skylinerw
    Commented May 5, 2016 at 18:08
0

Create a scoreboard

/scoreboard objectives add testScoreBoard dummy

Chech for amount of players in radius r

/stats entity @e[type=Player,r=10] set SuccessCount testScoreBoard @p

You can then say something if there are 2 player in range

/execute @p[score_scoreBoardTest_min=2] ~ ~ ~ say 2 players are in range

Reset the scoreboard every tick

/scoreboard players reset testScoreBoard @p

Put all those commands into repeating command blocks.

I'm using @p because i need a placeholder wich i can select with selectors. You can use a ArmorStand tho:

/stats entity @e[type=Player,r=10] set SuccessCount testScoreBoard @e[type=ArmorStand,tag=counter]

/execute @e[tag=counter,score_scoreBoardTest_min=2] ~ ~ ~ say 2 players are in range

/scoreboard players reset testScoreBoard @e[tag=counter]

Hope it helped :)

2
  • You should apply the CommandStats to a command block instead of to players, setting the score of a fake player instead of real players. Since it's a single area that would be preferable over possible complications of players logging out or dying (in which they would change a different player's score instead of their own since you've used @p is the trigger target). But CommandStats in this case is quite overkill.
    – Skylinerw
    Commented May 5, 2016 at 16:15
  • i did not do so much with the stat command, just a quick idea wich came into my mind. Thanks for the correction :) Commented May 5, 2016 at 16:20

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