I am making a MC map and need help. I want to make it that when someone uses a certain potion, that same person teleports to a random user on the map. I read another post like this, but I think it was unrelated. I can't use the @p thing because the other players might teleport instead. I know to use the /effect code on command blocks and some other commands.

  • I've been working on this for probably an hour now. Maybe longer, I've lost track. I've solved the issue of specifying the first player using @p[c=n], the problem I'm running into now is the "random other player" part, since /tp Unionhawk Unionhawk is valid.
    – Unionhawk
    Oct 20 '13 at 3:00
  • I'm trying it using experience as an identifier, however, it is only possible to identify players who are inside a certain level range, and cannot identify players who are not a specified level, except at level 0.
    – Unionhawk
    Oct 20 '13 at 3:30

This was a very interesting challenge for me to work out. There are many parts to this problem, which are a lot harder to accomplish than one might think. There's identifying the player with the status effect, and identifying a set of random players who are not them (since /tp Unionhawk Unionhawk is a valid result of /tp @p @r, and does nothing).

But, finally, here is my setup, which works for a bounded number of players on a server. Some of its flaws include only allowing one game to be played on a given server, and using experience level to identify players. As such, /gamerule doMobLoot false must be used, and /gamerule commandBlockOutput false is strongly advised.

enter image description here

So there's quite a lot of things going on here, as you can see. But this is all accomplished using 4 commands and a hopper clock.

The Group 1 command blocks are there to detect when a player has the specified potion effect, remove it, and proceed to the matching Group 2 command block. I used /effect @p[c=n] 4 0 for that one, which removes the mining fatigue effect from player n on the server (going down the list of players on the server). When that command evaluates, the Group 2 command blocks give that player one level of experience using /xp 1L @p[c=n].

From there, the next time the hopper clock pulses, the "Group" 3 (you only need one) command block teleports a player with 1 level or more to a random player without any levels using /tp @p[lm=1] @r[l=0]. When this command evaluates, the "Group" 4 command block clears the experience level of all players using /xp -9999L @a.


All you have to do is (no potions) do /give [your username] 137 1, that gets you a command block. Put this in the command block: /tp @p -522 9 -434

  • 2
    This does not answer the question asked.
    – fredley
    Oct 20 '13 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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