2
Command Block Help / ~DX
Command wizards, I beseech thee!
I'm trying to make an area that upon entering your gamemode turns to adventure if you were in survival and on leaving the opposite happens. I know of several ways to do this, but for my requirements I need it to be a rectangular area and relative to the command block's position. This is one of the commands I have on a repeat block:
/gamemode adventure @a[gamemode=survival,x=~,y=~,z=~,dx=25,dy=25,dz=25]
It works if it is given a definite position instead of the ~ ~ ~, but I need it relative. Is there a way to make this work?
I'm trying to make an area that upon entering your gamemode turns to adventure if you were in survival and on leaving the opposite happens. I know of several ways to do this, but for my requirements I need it to be a rectangular area and relative to the command block's position. This is one of the commands I have on a repeat block:
/gamemode adventure @a[gamemode=survival,x=~,y=~,z=~,dx=25,dy=25,dz=25]
It works if it is given a definite position instead of the ~ ~ ~, but I need it relative. Is there a way to make this work?
10
You can try executing the player and detecting if a block on a specific y level is beneath them although this would cancel out a specific block to use in a specific y coordinate outside the area cause it would execute it unless the command block inside unloaded chunks and would require you to fill the y level with that specific block, although with this technique you can have more obscure shapes for to be detected.
/execute as @a[gamemode=survival] at @s if block ~ 1 ~ minecraft:dead_horn_coral_block run gamemode adventure @s
/execute as @a[gamemode=adventure] at @s unless block ~ 1 ~ minecraft:dead_horn_coral_block run gamemode survival @s
/execute as @a[gamemode=survival] at @s if block ~ 1 ~ minecraft:dead_horn_coral_block run gamemode adventure @s
/execute as @a[gamemode=adventure] at @s unless block ~ 1 ~ minecraft:dead_horn_coral_block run gamemode survival @s
That seems like a good idea, but it won't quite work for the scenario I am trying to set up. Thank you!
You can set the coordinates with /execute positioned, and yes they can be relative coordinates this way.
Hope this helps! :)
/execute positioned x y z run gamemode adventure @a[gamemode=survival,dx=25,dy=25,dz=25]Hope this helps! :)
That works perfectly! Now I just need to think of a more elegant solution to getting them back into survival after leaving.
My current methods have been the /gamemode survival @a[gamemode=adventure,distance=25..] or /gamemode survival @a[gamemode=adventure] and just on a slower clock, but that fills up your chat feed with gamemode changes while within the adventure area.
Does something like this sound like it would work in the syntax?
/execute positioned ~ ~ ~ unless entity @s[dx=25,dy=25,dz=25] run gamemode survival @s[gamemode=adventure]
My current methods have been the /gamemode survival @a[gamemode=adventure,distance=25..] or /gamemode survival @a[gamemode=adventure] and just on a slower clock, but that fills up your chat feed with gamemode changes while within the adventure area.
Does something like this sound like it would work in the syntax?
/execute positioned ~ ~ ~ unless entity @s[dx=25,dy=25,dz=25] run gamemode survival @s[gamemode=adventure]
Try this, should result in no spam. Kind of a hacky solution tbh, but it works! :)
If you are still receiving spam, try disabling the commandBlockOutput and logAdminCommands gamerules.
EDIT: See HoboMaggot's reply below regarding logAdminCommands.
Also if you can't leave the either gamemode, just give yourself the admin tag.
/tag @a[tag=inBox] remove inBox/execute positioned x y z run tag @a[tag=!inBox,tag=!admin,dx=25,dy=25,dz=25] add inBox/gamemode adventure @a[gamemode=!adventure,tag=inBox,tag=!admin]/gamemode survival @a[gamemode=!survival,tag=!inBox,tag=!admin]If you are still receiving spam, try disabling the commandBlockOutput and logAdminCommands gamerules.
EDIT: See HoboMaggot's reply below regarding logAdminCommands.
/gamerule commandBlockOutput false/gamerule logAdminCommands falseAlso if you can't leave the either gamemode, just give yourself the admin tag.
/tag @s add admin/tag @s remove adminAwesome! I wouldn't have thought of that; working like a charm. Thanks again for the help!
Assuming they're using cmd blocks/datapacks, there's no need to disable logAdminCommands, as it is the game executing the commands, not the player
Hmm, interesting. Something must have changed in more recent updates. Appreciate the information!
There was a reason to disable it in the past though. In older versions of the game(like 1.8), it will fill your output log with unnecessary text, just like commandBlockOutput, but worse in that it was hidden! No idea how I missed that it was changed, but that change is for the better IMO! :)
There was a reason to disable it in the past though. In older versions of the game(like 1.8), it will fill your output log with unnecessary text, just like commandBlockOutput, but worse in that it was hidden! No idea how I missed that it was changed, but that change is for the better IMO! :)
It's been a while since I've last worked with commands but you could try an approach using
/execute as @a[gamemode=survival,x=~,y=~,z=~,dx=25,dy=25,dz=25] run gamemode adventure
Not sure if it would work but you could try it :)
Update:
Apparently relative coordinates for target selectors haven't been added to Java yet (it's on Bedrock though)
A workaround is to summon some invincible, invisible armor stand relatively, with a certain tag
Then execute as the armorstand
/execute as @a[gamemode=survival,x=~,y=~,z=~,dx=25,dy=25,dz=25] run gamemode adventure
Not sure if it would work but you could try it :)
Update:
Apparently relative coordinates for target selectors haven't been added to Java yet (it's on Bedrock though)
A workaround is to summon some invincible, invisible armor stand relatively, with a certain tag
Then execute as the armorstand
I hadn't thought about that one, thanks!
