2

Command Block Help / ~DX

GhostlyFaced 8/21/21 11:52 pm
360
8/23/2021 8:28 pm
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?
Posted by
GhostlyFaced
Level 38 : Artisan Architect
50

  Have something to say?

JoinSign in

10

ISeeGoodStuff
08/22/2021 2:14 am
Level 60 : High Grandmaster Vampire
history
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
2
GhostlyFaced
08/22/2021 3:36 pm
Level 38 : Artisan Architect
That seems like a good idea, but it won't quite work for the scenario I am trying to set up. Thank you!
1
SUPERIONtheKnight
08/22/2021 12:58 am
Level 30 : Artisan System
history
You can set the coordinates with /execute positioned, and yes they can be relative coordinates this way.
/execute positioned x y z run gamemode adventure @a[gamemode=survival,dx=25,dy=25,dz=25]
Hope this helps! :)
2
GhostlyFaced
08/22/2021 3:35 pm
Level 38 : Artisan Architect
history
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]
1
SUPERIONtheKnight
08/22/2021 4:09 pm
Level 30 : Artisan System
history
Try this, should result in no spam. Kind of a hacky solution tbh, but it works! :)
/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 false
Also if you can't leave the either gamemode, just give yourself the admin tag.
/tag @s add admin/tag @s remove admin
2
GhostlyFaced
08/23/2021 8:28 pm
Level 38 : Artisan Architect
Awesome! I wouldn't have thought of that; working like a charm. Thanks again for the help!
1
HoboMaggot
08/22/2021 10:15 pm
Level 55 : Grandmaster Blob
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
3
SUPERIONtheKnight
08/22/2021 10:41 pm
Level 30 : Artisan System
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! :)
3
Giancarlovan
08/22/2021 12:22 am
Level 44 : Master Technomancer
history
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
2
GhostlyFaced
08/22/2021 3:37 pm
Level 38 : Artisan Architect
I hadn't thought about that one, thanks!
2

Welcome