How To Change The Gamemode For A Specific Player? - Minecraft Forum

Help Sign In/Register
  • Home
  • Minecraft Forum
  • Minecraft: Java Edition
  • Redstone Discussion and Mechanisms
  • Commands, Command Blocks and Functions
  • How to change the gamemode for a specific player?
  • #1 Jul 31, 2017 herbapou herbapou
    • View User Profile
    • View Posts
    • Send Message
    View herbapou's Profile
    • Stone Miner
    • Join Date: 1/29/2016
    • Posts: 81
    • Member Details

    I want to change the gamemode of a specific player when he enters an area using a command block.

    Not sure how to do it:

    Tried: (not working)

    /gamemode survival @e[m=2,r=20,name=playername] <<=== solved, this works

    /gamemode survival @playername[m=2,r=20]

    Last edited by herbapou: Jul 31, 2017 Rollback Post to Revision RollBack
  • #3 Jul 31, 2017 herbapou herbapou
    • View User Profile
    • View Posts
    • Send Message
    View herbapou's Profile
    • Stone Miner
    • Join Date: 1/29/2016
    • Posts: 81
    • Member Details
    Quote from ShelLuser»

    gamemode survival @a[r=20]

    That would place players within a 20 block range into survival mode.

    indeed. But I want to set the game mode for a specific player. Rollback Post to Revision RollBack
  • #4 Jul 31, 2017 herbapou herbapou
    • View User Profile
    • View Posts
    • Send Message
    View herbapou's Profile
    • Stone Miner
    • Join Date: 1/29/2016
    • Posts: 81
    • Member Details

    ok I solved it.

    The first command I tried works. I had conflicting commands that bug it.

    So this works: It will change playername from gamemode adventure to survival.

    /gamemode survival @e[m=2,r=20,name=playername]

    Rollback Post to Revision RollBack
  • #5 Jul 31, 2017 Talysman Talysman
    • View User Profile
    • View Posts
    • Send Message
    View Talysman's Profile
    • Coal Miner
    • Join Date: 7/19/2017
    • Posts: 108
    • Location: Sacramento Valley area
    • Minecraft: urbeatle
    • Member Details

    I'm trying to figure this out... I would have thought that @p[r=20, name=playername] would have worked, but if it doesn't, maybe you need to do a work-around... put

    gamemode survival playername

    into one function (functions/herbapou/utility/playernamemode.mcfunction ) and

    execute playername ~ ~ ~ summon minecraft:vex ~ ~1 ~ {CustomName:trigger,NoAI:1b,Silent:1,ActiveEffects:[{Id:14,Amplifier:0,Duration:2147483647}]}

    Into another function (I picked the Vex because it naturally despawns after a short while.) Call this one functions/herbapou/utility/playernametrigger.mcfunction.

    Then, at your desired location, have two repeating command blocks:

    /function herbapou:utility/playernamemode if @e[r=20, name="trigger"]

    And:

    /function herbapou:utility/playernametrigger if @p[r=20, m=adventure]

    What this does is it summons a named vex at the named player's location, regardless of whether the player is nearby, any time any player at all enters the area, then the other block checks if a vex with that name exists within the area, which only happens if the player is in the area. If there is a vex with that name, the player's game mode is changed.

    I suppose this could be compacted. But someone else is going to have to figure it out.

    Rollback Post to Revision RollBack
  • #7 Aug 1, 2017 Vindicar Vindicar
    • View User Profile
    • View Posts
    • Send Message
    View Vindicar's Profile
    • Redstone Miner
    • Join Date: 11/1/2010
    • Posts: 532
    • Minecraft: Vindicar
    • Member Details
    Quote from herbapou»

    ok I solved it.

    The first command I tried works. I had conflicting commands that bug it.

    So this works: It will change playername from gamemode adventure to survival.

    /gamemode survival @e[m=2,r=20,name=playername]

    Except it will also work for ANY entity with the same name, like a nametagged mob. I suggest you use @a selector instead of @e. Rollback Post to Revision RollBack
  • #8 Aug 1, 2017 herbapou herbapou
    • View User Profile
    • View Posts
    • Send Message
    View herbapou's Profile
    • Stone Miner
    • Join Date: 1/29/2016
    • Posts: 81
    • Member Details
    Quote from Vindicar» Except it will also work for ANY entity with the same name, like a nametagged mob. I suggest you use @a selector instead of @e.
    thanks Rollback Post to Revision RollBack
  • To post a comment, please login.
Posts Quoted: Reply Clear All Quotes
  • Home
  • Minecraft Forum
  • Minecraft: Java Edition
  • Redstone Discussion and Mechanisms
  • Commands, Command Blocks and Functions
  • How to change the gamemode for a specific player?
Previous Thread Jump to Forum Next Thread

Tag » How To Put A Player In Survival Mode