How do I affect a player that is 20 blocks away from me if I am looking in their direction?
Beforehand Note: There are some misconceptions, this covers the original post's question of 'How to apply potion effects in a certain area', for why the post remains in this way. I have gone a bit into how to manipulate Scoreboards as well - if you're into this stuff, read on!
Let's say you wanted to give ol' Ghosty over here an Effect
Well, you'd get to doing that by either acquiring yourself a Suitable Command Line (Press / ) or for the ambitious, a Command Block. Got what you need? Great!
You'll want to use the /effect
command to apply either a Potion(Status) Effect or a Beacon Effect to a player.
(To see a full list of Effects, see here)
For my example, I'll use the Nightvision Effect (from potions).
To target a player, group of players, or entity(ies) - you designate either the @p
, @a
, @r
or @e
Selector (Because, if you were to apply a potion effect on everything, your game would probably crash, 'fatally'!) .
All meaning 'Closest Player', 'All Players', 'Random Player' and 'All Entities' respectively.
If you wanted, you could instead input the Player's Name, so... /effect Ghosty blah blah
, etc
As Night Vision
uses the Effect-ID of 16
, I'd input the command into the terminal / block...
/effect @p 16 …
The elipsis after the 16 represents the duration of time you require your designated player to have the effect for. So, let's say One Minute, being 60 Seconds.
/effect @p 16 60
Right, that's the basics. But what about in a certain range? Wel-hehe, easy!
Applying Effects in a Radius
By the sound of radius, you're probably thinking, "Gosh... this is hard - I'm probably going to be handling radians and that fancy trigonometry stuff...".
Short answer, nope! It's easy: you just have to use the Extended Selector Attribute (It's what I call it) .
All you have to add to your current command, is this...
/effect @p[r=~] 16 60
See that ~
is how many blocks the radius of your area is. Radius , not Diameter.
And it's good to know that: the radius also draws a slight circle around you or the designated coordinate(s), and all blocks touched by the 'invisible-line' or within the circle are marked as within the area .
So you could apply Effects to other unexpected things, keep that in mind!
What's the Final Result?
With all this knowledge and a few close-ups of my 'adorable face', we now know how to apply Effects from Beacons or Potions, in a set area. Heck, individual players even (refer to line 11) .
Our result?
/effect @p[r=5] 16 60
5
is the placeholder number, however, if you want to do it standing behind them - it's perfect. (They won't be able to get away in time before you enter the command - sure, apply a Levitation Effect if you want to, Levitation-Effect-ID: 25
)
Let's take a look at a couple reference images just to be sure.
The command being entered, and eventually activated by a fellow villager.
3rd person perspective without Night Vision.
3rd person perspective with Night Vision.
It's really, not that hard.
Now, according to the Question-Asker's Specifications (This answer is for everyone and is for generality, meaning for everyone), for certain parts such 'looking in certain directions' - I can not devise a solution for, sorry.
But I can however, lead you in the direction of what to do with Scoreboards.
Scoreboards and Relations to /effect
For this, you certainly will need command blocks - as it is the only way forward without bundling up the command into a single-line jumbled-mess or minifying it.
Place a CMD-Block and type in the command:
/testfor @a[r=5,team=Neutral]
The above is assuming that you already have a viable scoreboard system in place, marking 'Neutral' (placeholder name) and 'People' (another placeholder).
If you do not know how to use scoreboards: do a quick internet search, you'll get the hang of it, or maybe test it yourself in your Minecraft World with /scoreboard teams add(/remove) blah
and so on - anyway, you can change the placeholder names to your own. Then either set the Command Block Type to Repeat (and assign the Conditional Part as Unconditional) or attach it to a really fast clock. Example, picture from an earlier post.
Note that the comparator in the super-fast-clock, if you are deciding to build it, has to be set to Subtract-Mode.
Set down a comparator next to your last CMD-Block that you used (the one that you used recently there-of) without changing it to Subtract-Mode.
This should be hooked up to a command block running the /effect
command; which you most likely already know, looking at the above three sections about it. :)
So the result dictates that when a Player within the Neutral Team steps within the radius of the command block, the comparator will activate in turn triggering the second command block. Cool. So, if you were to place it underneath a structure and link it to a certain effect, you could possibly create a haunted house or a future-tech-y house and such with shining lights that set fire to your retinas... so and so.
What's the Final-Final Result?
Well, you now know how to manipulate Scoreboard Technology (or should do, if this confuses you - give it another skim over) and using it to apply Effects to players. If you were to do mobs, it'd be a whole new level; psst... @e[type=mobHere] id time
, have fun!
I hope this has helped you fellow Minecraftians and or Intermediate Command/Redstone-ers.