Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.9.4] Problem playing sound when player dies


American2050
 Share

Recommended Posts

I'm having problems playing a sound when the player dies.

 

The sound is registered correctly, the event is registered correctly and getting fired, but for some reason, the sound wont play.

 

I'm not sure what the problem could be here.

 

	@SubscribeEvent
  public void onPlayerDie(PlayerDropsEvent event) {

	World world = event.getEntity().getEntityWorld();
	EntityPlayer player = event.getEntityPlayer();
	BlockPos pos = player.getPosition();

	world.playSound(player, pos, ModSounds.PLAYER_DEAD, SoundCategory.BLOCKS, 1.0F, 1.0F);


}

 

I tried the sound firing in on other events and it works ok, but inside the PlayerDropsEvent it wont do anything.

 

PS: Also tried this, with no success

 

	@SubscribeEvent
  public void onPlayerDie(LivingDeathEvent event) {

	Entity entity = event.getEntity();

	if(entity instanceof EntityPlayer){			

		World world = event.getEntity().getEntityWorld();
		BlockPos pos = entity.getPosition();

	world.playSound((EntityPlayer)entity, pos, ModSounds.PLAYER_DEAD, SoundCategory.BLOCKS, 1.0F, 1.0F);

	}


}

Link to comment
Share on other sites

For a start

PlayerDropsEvent

is not the correct way to detect player death, using

LivingDeathEvent

like you already tried.

 

As for your error: As you can read in the documentation the playSound method you are using will on the server only play the sound to every player BUT the player passed in. On the client it will just play it normally. But since LivingDeathEvent does not fire for the player on the client (it might fire for other players clientside, I am not sure about this) the client will never play the sound. Instead pass

null

for the player.

Link to comment
Share on other sites

Thanks a lot man, it's working perfectly now.

 

Now my question is... Why it's wrong to track when a player dies using the PlayerDropsEvent?

 

Isn't it better to subscribe to an event that will triggers only when a player dies, and not use LivingDeathEvent that gets triggered every time something dies in the game?

 

In my head it makes sense using PlayerDropsEvent better over LivingDeathEvent but dunno...

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
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.

 Share



×
×
  • Create New...

Important Information

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