Vai al contenuto

Foto

Sound object randomness


  • Effettua l'accesso per rispondere
Questa discussione ha avuto 4 risposte

#1
kamal_

kamal_
  • Members
  • 5235 Messaggi:

The sound object has a Random property which is stated to make the sound object choose randomly between the various sounds assigned to it. It seems like a great way to have random music for an area, for instance a tavern with some bards playing. It could be used to have the bards start up with a random tune every time the player entered the tavern, which would be great if the player is regularly in the tavern.

 

That would be nice, but it doesn't seem to work in practice. It seems to always play the first sound on the list first. Is there a way to get random selection of sounds with the next sound playing when the first finishes (so the bards start another song after their first one finishes)?



#2
Claudius33

Claudius33
  • Members
  • 256 Messaggi:

You can use the MusicBackgroundChangeDay() and MusicBackgroundChangeNight() functions.

 

MusicBackgroundChangeDay(object oArea, int nTrack)

 

TRACK_xx variables are defined, but unfortunately only a subset (NWN1 and OC I guess), at least there are 4 different tavern musics.

 

However you can find the track number in the ambientmusic 2da file for Motb and SoZ musics

 

For instance OC music mus_tavern1 is number 22, which is exactly the value of TRACK_TAVERN1

int TRACK_TAVERN1           = 22;

 

So looking at the 2da I would assume that MusicBackgroundChangeDay(oArea, 192) sets the music to nx2_mus_tavern_samarach from SoZ (day time)

 

Afterward it's  just a matter of choosing randomly in the OnEnterConnect script. If you want to change the music let's say every 2 minutes, it would be a matter of counting 20 heartbeats.

 

I don't know if an event is raised when a music ends though.


  • kamal_ piace questo

#3
kamal_

kamal_
  • Members
  • 5235 Messaggi:
I have custom sounds of varying length for the bard songs, so I would need some way to detect them ending so I dont start new songs in the middle of old ones.

#4
Claudius33

Claudius33
  • Members
  • 256 Messaggi:

You may use MusicBackgroundStop() after a defined number of heartbeats. Then MusicBackgroundChangeDay/Night() and finally MusicBackgroundPlay() to start the new sound.

 

Of course if your sounds durations are very different, you have to estimate a number of heartbeats for each sound. Cumbersome, but should work.

 

Perhaps someone has figured out a better way.



#5
Jereniva

Jereniva
  • Members
  • 114 Messaggi:

How about having a different sound object placed in the bar, one for each possible order of songs. (Or as many as you have patience to make!)

One sound object has songs in order: 5,3,1,4,2 another has 1,3,4,2,5, and so on.

Set all of these sound objects as inactive in toolset, and use Random with each OnEnter of the party to determine which "set list" the band will play by setting to Active. In the OnExit, set them all inactive again.

If you put enough interval value between songs, it should feel natural enough.

 

EDIT: I think I misunderstood your original question, are you saying it starts with same song every time you enter area and song order is identical each time, even though Random? is checked on the sound object? 

I was playing with that last night getting random song bird sounds to play. It seemed to work correctly for me, but I never paid attention if exiting and re-entering the area.