Play sound wen a player get damaged

I’m new to the Verse field, I’m trying to create a way that allows to play a sound when the player takes damage (generic damage)
Could someone help me, I can’t get the audio play

Hi, I think you forgot the parentheses when you called your “PlayDamagedAaudio” function and passed the agent as parameters on line 43 and 48.

Try this, it should work :

PlayDamagedAaudio(Agent)

thanks but it still doesn’t work

Sorry, I misread your code and understood your request. I’m not sure who you want the audio to be heard by, from your code I assume you want the target to hear it.

To do this, you must retrieve the agent from the target of the “damage_result”:

if (FC := fort_character[DR.Target], TargetAgent := FC.GetAgent[]):
   PlayDamagedAaudio(TargetAgent)

You also need to set the audio player setting: “Can be heard by => Instigator only”

And if you want both players to hear the sound, you can simply play the audio in your “OnPlayerDamaged” function without passing an agent :

AudioDevices1.Play()

and you have to set the audio player to “Can be heard by => everyone”

Hoping to help you

1 Like

You also are using Agent where you have not initialized it, Verse only knows what Agent is in the context of PlayDamagedAudio. I would watch some starter Verse tutorials as variable scope is a very important concept in all of coding, here is a great series:
https://www.youtube.com/watch?v=uVjcBRaeTHU&ab_channel=GraemeBull

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.