Jump to content

LivingAttackEvent


ashtonr12

Recommended Posts

ok so i want to know how to get the attacking entity,

 

Proof i have tried xD

i have seen related things such as damagesource & livingattackevent, i cant figure out how to use these, all the examples i see of living attack event are doing things to the player, not the entity attacking the player. also all instances of dmg source i have found only work with entity not entitylivingbase which is what the entityzombie, entitySkele, etc come under.

I have also found some stuff to do with event.entityliving but you cant use the getEntity(); function with this, so i am stuck.

 

I know how to use the entity once i have a name for it, but i also need to check the item the player is holding, i think i know how to do this too but for this the dmg source has to be a player, not a mob, so HALP xD

 

INSHORT

i want to make the entity attacking the player(if the player is holding sword x) take damage.

 

 

Use examples, i have aspergers.

Examples make sense to me.

Link to comment
Share on other sites

DamageSource has a method getSourceOfDamage() that returns the Entity causing the damage.

 

Use it like this in your LivingAttackEvent:

if (event.entity instanceof EntityPlayer)
{
// Now you've got the player that is being attacked by something
EntityPlayer player = (EntityPlayer) event.entity;

if (event.source.getSourceOfDamage() != null && event.source.getSourceOfDamage() instanceof EntityZombie)
{
EntityZombie zombie = (EntityZombie) event.source.getSourceOfDamage();

// now you've got the zombie that's attacking the player, do what you'd like to it
}
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.