3

I'm creating a game and I need a fill command to have a 50-50 chance of opening one of two gates (Ex. This will be activated when a button is pressed to start game). The obvious choice would to use the @r selector, but I don't know how to apply this to a command block command.

I'm running 1.10.2 and this is only a two player game. (For me and a friend)

1
  • Maybe you find something useful here. This one doesn't even need a command block.
    – dly
    Commented Jul 30, 2016 at 8:19

2 Answers 2

2

An easy way to do this is using a random feature of the game, eg. Dispensers, animal movement, explosions, mob spawning and more. The easiest you can do is:

  1. Fill a dispenser with 2 items - one stackable, one not - a helmet and a dirt block for example.

  2. Put a Weighted Pressure Plate where the Dispenser shoots.

  3. When you power the dispenser, it shoots one of the 2 items. The Pressure Plate will give stronger signal (goes farther) if a helmet (equivalent to a full stack) falls on it then if 1/64th of a stack of dirt falls on it.

  4. Execute a command only if the signal reaches a certain strength.

1
  • 1
    Thanks for the feedback, I hope to find a system that is constant and a bit more reliable though.
    – Jason_
    Commented Jul 31, 2016 at 21:16
0

You can use a "random" number generator by periodically changing the value of a objctive on a fast redstone clock:

(First create the objetcive by /scoreboard objectives add FiftyFifty dummy)

 /scoreboard objectives set @a FiftyFifty 0

 /scoreboard objectives set @a FiftyFifty 1

So the FiftyFifty objective is 50% of the time equal to 1. To trigger your command, you need to constantly run this command (in a repeat command block):

/testfor @a[score_FiftyFifty_min=1]

And if this command returns true, ecexute your command (in a Chain command block)

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