how can i make a potion effect that takes one health away per second when you move

Started by colorpinkhearts on

Topic category: Help with modding (Java Edition)

Last seen on 23:48, 16. Sep 2023
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how can i make a potion effect that takes one health away per second when you move

i want to make this as a part of a potion effect that im making but i dont knw how

Last seen on 17:53, 25. Apr 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In order to start designing…
Tue, 05/23/2023 - 19:01

In order to start designing something like this, you want to see what the player's (or another entity's) velocity is as they're moving. On all three axes (x, y, z). You can do this by having your potion effect's on tick procedure trigger print statements that send information to the MCreator console.

Once you know how fast the player is while they're sneaking, walking, sprinting, jumping, etc, you'll know what value you can compare against before causing damage.

There are a couple other things to keep in mind, though:
One being that the player can move with positive or negative velocity depending on the direction they're moving. So you want to get the absolute value of their velocity, not just the velocity by itself.
The other being that the player has a negative Y velocity when standing completely still, to simulate gravity.

In your potion's "On effect active tick" procedure, you can have an if block check to see if the absolute value of the entity's X or Z velocity is greater than 0, or if the absolute value of their Y velocity is greater than 0.08, and if so, deal damage to them.

The absolute block is in the Math tab, inside the "round" block.

If you didn't want your potion to deal damage while the affected entity was sneaking, for example, you could do something like that by changing the X and Z velocity threshold values to something like 0.04 - since the velocity while sneaking reads as ~0.035.

Lastly, I also recommend having your whole procedure restricted by a 'if not Is provided world client-side' check. This prevents a weird de-sync between the server and client where sometimes the game still thinks you have a potion effect, while the timer is at 0, but it still affects you.

Last seen on 23:48, 16. Sep 2023
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how do i find the "is…
Fri, 05/26/2023 - 13:20

how do i find the "is provided with world client-side' block?

Last seen on 17:53, 25. Apr 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can either just use the…
Fri, 05/26/2023 - 14:40

You can either just use the search bar in the top left, or find it near the bottom of the list in "World data".