Is there a way i could give the player a potion effect when they're looking at a certain entity?

Started by MischiefCat591 on

Topic category: Help with MCreator software

Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is there a way i could give the player a potion effect when they're looking at a certain entity?
Sun, 06/30/2024 - 01:59 (edited)

Is there a way i could give the player a potion effect when they're looking at a certain entity?

Edited by MischiefCat591 on Sun, 06/30/2024 - 01:59
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I've done something similar…
Wed, 07/10/2024 - 18:26

I've done something similar for one of my mods, but where the player gives specific entities an effect by looking at them instead.

I Googled how to give a mob an effect by looking at them and used this for reference: https://www.reddit.com/r/MinecraftCommands/comments/146x8wx/how_do_i_give_an_effect_to_the_entity_the_player/

Here's a command for what you're trying to do, though: /execute as @a at @a facing entity @e[type=minecraft:villager] feet positioned ^ ^ ^1 rotated as @a[limit=1] positioned ^ ^ ^-1 if entity @a[distance=..0.075] if entity @e[type=villager,distance=..10] run effect give @s minecraft:glowing 1 0 false

The distance value in "if entity @a[distance=..0.075]" refers to how closely the player must be looking at the mob in order for the effect to trigger. The smaller the value, the smaller the area.

The distance value in "if entity @e[type=villager,distance=..10]" limits how far away the command is able to take effect. Here, it only works within 10 blocks of the entity. If the player looks at a villager from further than 10 blocks away, then nothing will happen.

Just create an onTick procedure for the entity you want and have that command be executed in whatever circumstances you'd like.