Radio that starts randomly

Hello, could someone explain to me how to ensure that with each elimination, 1 radio out of 20 available is launched at random. THANKS.

What do you mean by radio? An audio playback device?

Perhaps make an @editable array of audio playback devices and then use GetRandomInt to randomly pick one to play. Or make a blueprint with all of the audio files in it and have it randomly play one.

This radio

OPTION #1: Place 20 of the audio player devices on your map. Associate each with different sound file. Then make a device to manage randomly playing one. Like this:

my_audio_manager_device := class( creative_device )
{
    @editable AudioPlayers : [] audio_player_device = array{}

    PlayRandom( PlayerAgent:agent ):void=
    {
        AudioPlayersCount := AudioPlayers.Length
        AudioPlayerIndex := GetRandomInt( 0, AudioPlayersCount-1 )

        if( AudioPlayer := AudioPlayers[ AudioPlayerIndex ] )
        {
            AudioPlayer.Play( PlayerAgent ) # only instigator hears it
            # AudioPlayer.Play() # or everyone hears it
        }
    }
}

Drag and drop that onto your map and then configure it in the Outliner.

OPTION #2: Make a blueprint that you put the audio files in and have it randomly play one.

- In content browser make a folder
- Put your audio files in it
- Right click and pick Audio > Sound Cue
- Open the cue file
- Drag and drop the audio files into it
- Add a random node
- Right click the random node and add an input for each audio file
- Hook all the audio files up to the inputs
- Hook the output of the random node into the output node
- Configure or change whatever you want in the blueprint

Then make an audio_player_device on your map. Add the cue file in. When you play it, it will play 1 random sound.

Or something like that.

In regards to eliminations, if you haven’t done so, subscribe to the EliminatedEvent notification for each fort_character.

So, when someone joins the map, do something like this function:

OnPlayerJoined<override>( PlayerAgent:agent ):void =
{
    if( FC := PlayerAgent.GetFortCharacter[] )
    {
        FC.EliminatedEvent().Subscribe(OnPlayerEliminated)
    }
}

In OnPlayerEliminated you would play your random audio.

1 Like

thank you very much

Glad to help!