Minecraft – Need help with some Commands

minecraft-commandsminecraft-java-editionminecraft-java-edition-server

I'm starting a new server with few friends and we're stuck with making "safe zones" and "only X team zones".

We have a survival map where there are 4 teams (Red, Purple, Yellow and Green), but with some "safe areas" that cannot be destroyed and also are not PvP allowed. I used those commands:

gamemode adventure @a[r=40,m=0]
gamemode survival @a[rm=41,r=42,m=2]

This actually works, but people can still PvP in this area (40×40 blocks), which we don't want them to…

Also, we want that only one team can enter certain areas, and the other get teleported to the spawn (x=-237, y=71, z=222).

The last thing we want is to make a "PvP reward" system. Each time someone kill a player from another team, he will receive 2 emeralds. Obviously, we don't want that people on the same team can hit each other, so we will need a command for that.

I hope you guys can help us, we are really new in commands-block, making all our tries not working.

Thanks for all your help.

Best Answer

To prevent PVP, you'd want to give weakness to players, as this is the most effective method, because, if done correctly, it won't actually make a player go red.

Command:

/effect @a[r=20] weakness 2 127

The 2 seconds is to make sure a player loses their weakness when they step out the safe zone. You might be able to lower this to 1 second.

To teleport players in a radius:

/tp @a[r=20,team=!Red] X Y Z

This command assumes that players which must not be teleported are on the scoreboard team Red.

To prevent combat between the same team:

/scoreboard teams option Red friendlyfire false

This can be used for all the teams by replacing Red with the other team's name.

Remember, you will need to setup scoreboard teams if you haven't already

More info: http://minecraft.gamepedia.com/Scoreboard

Also, check out http://minecraft.gamepedia.com/Commands#Target_selector_variables for information regarding selecting players in a certain X1 Y1 Z1 to X2 Y2 Z2 area, if using a radius is too inaccurate for you.

To give two emeralds to a player, check out this question: Can you use /testfor to detect the death of a player?

The one thing you'd need to change is change

/testfor @a[score_hasDied_min=1]

to

/give @a[score_hasDied_min=1] emerald 2

(untested, I will test in a couple hours)