#how to make entities execute an event when they've been hit with a projectile,

1 messages · Page 1 of 1 (latest)

wraith ember
#

basically I want to make it so when I hit a entity with a projectile that entity will execute a command, (and ONLY the entity that was hit) although I'm not sure how to do this

vale tulipBOT
#
Thanks for asking your question!

Once you have finished, please close your thread.

steel orchid
#

You can have an on_hit event on your projectile, that runs an execute command to run whatever it is that you want on the entity. If you're wanting to detect all projectiles though, there's some things you could do with damage sensors on the entity checking for specific sources, which would probably work out better, less janky and more consistent. You should be able to detect the entity type that caused damage, and then run an event with your command in it.

wraith ember
steel orchid
#

I-Frames?

#

Item frames?

wraith ember
#

immunity frames

steel orchid
#

It might be. I don't know exactly what you want to achieve.

#

There are a lot of solutions, but they're all contextual.

wraith ember
#

basically I want to make a custom health with scoreboards, because I'm trying to make a health system for my project that doesn't rely on minecraft's i-frames

steel orchid
#

Ah, alright. You'll want to have the events running from the projectile in that case. Let me find some more links.

#

This means you'll need to have this on all projectiles though, vanilla and custom.

wraith ember
#

not using any vanilla projectiles in my project

#

also pvp is not apart of my project, only pve

steel orchid
#

Alrighty. That's less work for you then.
Ah, so you're familiar with the projectile component then, right?

wraith ember
#

sort of

steel orchid
#

The best way of handling this is to trigger an event on the projectile's target. It should be pretty consistent. The event with the command will be then be in your entity file, and won't have any chance of being weird if you have a group of entities are huddled in a group around the entity that gets hit.

wraith ember
#

still not sure what code exactly I need to add

steel orchid
#

Well, I don't know what you have at the moment, so I couldn't tell you.

wraith ember
#

"on_hit": {
"remove_on_hit": {
},
"impact_damage": {
"damage": 0,
"knockback": false,
"semi_random_diff_damage": false,
"destroy_on_hit": false
},
"definition_event":{
"affect_projectile": true,
"event_trigger":{
"event": "pvz:peahit",
"target": "self"
}
},
"arrow_effect": {}
},

#

that

steel orchid
#

Are you prepared to add events to all of your entities so that they can have the command run using non-jank methods?

wraith ember
#

by entities do you mean projectiles or actuall mobs

steel orchid
#

mobs

wraith ember
#

I can probably do either

#

not too many mobs in my project so

steel orchid
#
"on_hit": {
    "remove_on_hit": {},
    "impact_damage": {
        "damage": 0,
        "knockback": false,
        "semi_random_diff_damage": false,
        "destroy_on_hit": false
    },
    "definition_event": {
        "affect_projectile": false,
        "affect_target": true,
        "event_trigger": {
            "event": "pvz:peahit"
        }
    },
    "arrow_effect": {}
}

You'll use this on your projectile, it should trigger any event named "pvz:peahit" on the entity that it hits.
But you'll need to create this event in each of your mobs.
Are you familiar with running commands from events?

wraith ember
#

"affect_affect_target"?

steel orchid
#

shit

#

corrected

wraith ember
#

k

#

so I basically remove the "target": "self"

steel orchid
#

Yeah, you don't need it in most cases.

#

It defaults to self

wraith ember
#

yea doesn't seem to work

wraith ember
#

@steel orchid yea I did Everything you told me too and it's not working, I tried running a command that makes the entity take damage and it works but the projectile for some reason just can't seem to do it