#How do you run a command when a player is damaged from another player with a specific tag?

28 messages · Page 1 of 1 (latest)

dense valley
#

The title describes my problem.

Thank you in advance for the help!

noble scrollBOT
#
Thanks for asking your question!

Once you have finished, please close your thread.

normal steppe
#

Use damage sensors

rough heart
#

@dense valley To go into further detail, the minecraft:damage_sensor component can be put in the player's behavior to detect taking damage. In this case we can use it to determine if the damager was a player who has that tag.

#
{
  "components": {
    "minecraft:damage_sensor": {
      "triggers": {
        "on_damage": {
          "filters": {
            "all_of": [
              {
                "test": "is_family",
                "subject": "other",
                "value": "player"
              },
              {
                "test": "has_tag",
                "subject": "other",
                "value": "specific_tag"
              }
            ]
          },
          "event": "on_damage",
          "target": "self"
        }
      }
    }
  },
  "events": {
    "on_damage": {
      // ...
    }
  }
}
#

From there, it depends on if you can use experimental features (Holiday Creator Features). If so, you can use the run_command event response to invoke a command directly:

"event": {
  "on_damage": {
    "run_command": {
      "command": "say Ouch"
    }
  }
}
dense valley
#

Hello again. Your code works perfectly. Thank you very much. I would like now afterwards to add that the player doesn't take any damage.

rough heart
#

@dense valley This can also be done within the damage sensor component. In the trigger object, add "deals_damage": false.

dense valley
#

When I did added it, my code stopped working

#

This is what my code looks like:

                "triggers": {
                  "on_damage": {
                    "filters": {
                        "all_of":[
                            {
                                "test": "is_family",
                                "subject": "other",
                                "value": "player"
                            },
                            {
                                "test": "has_tag",
                                "subject": "other",
                                "value": "specific_tag"
                            }
                        ]
                    },
                        "event": "on_hunter_damage",
                        "target": "self"
                    },
                    "deal_damage": "false"
                }
              }
            },
rough heart
#

Make sure the property is named correctly: deals_damage, and not deal_damage

dense valley
#

Oh

#

My code still doesn't work when I've changed it to 'deals_damage'

rough heart
#

Oh, and there is a difference between the value false, which is a boolean, and the value "false", which is a string

#

Minecraft may not be reading the value correctly because you have quotation marks around it

dense valley
#

Thank you very much!

#

Kind of topic, but do you know how to change the health of the player. I've previously used the attribute command in Java edition, but that isn't available in bedrock it seems

rough heart
#

You can use component groups with the minecraft:health component to modify the max health. Unfortunately you would need hardcode the values you want, as they cannot be set dynamically

dense valley
#

So I can't change it depending on for example an entities score from a scoreboard

rough heart
#

If you hardcoded all of the values of that scoreboard, you could ... but no, setting the max health directly to the score's value is not possible

dense valley
#

Hardcoding it works fine for me. Would I do that using some kind of IF-statement?

rough heart
#

Yes, in whatever medium you are using to trigger those events to set the player's health. In commands that may look like this:

execute if score @s max_hp matches 1 run event entity @s hp_max_1
execute if score @s max_hp matches 2 run event entity @s hp_max_2
execute if score @s max_hp matches 3 run event entity @s hp_max_3
# ...
dense valley
#

How are the hp_max (i.e 'hp_max_1', 'hp_max_2' etc) events setup?

rough heart
#

Nothing too special, they each add their own corresponding component groups. Here's an example:

{
  "component_groups": {
    "hp_max_1": {
      "minecraft:health": {"max": 1}
    },
    "hp_max_2": {
      "minecraft:health": {"max": 2}
    },
    // ...
  },
  "events": {
    "hp_max_1": {
      "add": {
        "component_groups": ["hp_max_1"]
      }
    },
    "hp_max_2": {
      "add": {
        "component_groups": ["hp_max_2"]
      }
    },
    // ...
  }
}
dense valley
#

Can you add a placeholder for a score, that still works together with execute if statements

#
execute if score max_hp max_hp matches 2 run event entity @a hp_max_2
execute if score max_hp max_hp matches 3 run event entity @a hp_max_3
...
#

In this example 'max_hp' is a placeholder for a score, and a scoreboard as well