Changing Music in a scene

Currently viewing this thread:

jik

Knight
I was looking at the operations, and the play_track operation seems to allow a fade out into a new track:

play_track                      = 601 # (play_track,<track_id>, [options]), # 0 = default, 1 = fade out current track, 2 = stop current track

Has anyone gotten this to work?  I can't even get this operation to play a track, thought the play_cue_track operation will start the music, again, I can't get it to switch to another track.
 

Keedo420

Knight at Arms
I have used it to make the minstrel npcs in my mod play the mods music tracks either randomly or chosen by the player from either dialogue options or from the camp menu (if a minstrel is in the player's party). It works fine for me.
This is how I did it in dialogue:
  [anyone, "minstrel_play_random", [],
  "Here's a little song I wrote. You might want to sing it note for note.", "close_window", [(call_script, "script_play_random_song")]],
  [anyone, "minstrel_play_prechoose", [],
  "Here's a list of the songs I can play.", "minstrel_play_choose", []],
  [anyone|plyr, "minstrel_play_choose", [],
  "Bright Morning Stars Are Rising.", "close_window", [(play_track, "track_outdoor_beautiful_land", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Sweet Kate.", "close_window", [(play_track, "track_calm_night_1", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Sweet Was The Song The Virgin Sang.", "close_window", [(play_track, "track_tavern_1", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Beside A Fountain.", "close_window", [(play_track, "track_tavern_2", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Go Crystal Tears.", "close_window", [(play_track, "track_travel_neutral", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Weep O Mine Eyes.", "close_window", [(play_track, "track_travel_nord", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "The Lowest Trees Have Tops.", "close_window", [(play_track, "track_travel_rhodok", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "All Pleasure Is Of This Condition.", "close_window", [(play_track, "track_travel_swadian", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "As Matchless Beauty.", "close_window", [(play_track, "track_uncertain_homestead", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Bourree.", "close_window", [(play_track, "track_town_neutral", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "My Heart And Tongue Were Twins.", "close_window", [(play_track, "track_town_khergit", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Fly Not So Fast My Dear.", "close_window", [(play_track, "track_town_nord", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "If My Complaints.", "close_window", [(play_track, "track_town_rhodok", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "The Witches' Dance.", "close_window", [(play_track, "track_town_swadian", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "The Silver Swan.", "close_window", [(play_track, "track_town_vaegir", 1)]],
  [anyone|plyr, "minstrel_play_choose", [],
  "Never mind. I want to ask you something else.", "minstrel_pretalk", []],

And it's basically the same in scripts:
  ("play_random_song",
  [(store_random_in_range, ":random_song", 0, 15),
    (try_begin),
  (eq, ":random_song", 0),
  (play_track, "track_outdoor_beautiful_land", 1),
    (else_try),
  (eq, ":random_song", 1),
  (play_track, "track_calm_night_1", 1),
    (else_try),
  (eq, ":random_song", 2),
  (play_track, "track_tavern_1", 1),
    (else_try),
  (eq, ":random_song", 3),
  (play_track, "track_tavern_2", 1),
    (else_try),
  (eq, ":random_song", 4),
  (play_track, "track_travel_neutral", 1),
    (else_try),
  (eq, ":random_song", 5),
  (play_track, "track_travel_nord", 1),
    (else_try),
  (eq, ":random_song", 6),
  (play_track, "track_travel_rhodok", 1),
    (else_try),
  (eq, ":random_song", 7),
  (play_track, "track_travel_swadian", 1),
    (else_try),
  (eq, ":random_song", :cool:,
  (play_track, "track_uncertain_homestead", 1),
    (else_try),
  (eq, ":random_song", 9),
  (play_track, "track_town_neutral", 1),
    (else_try),
  (eq, ":random_song", 10),
  (play_track, "track_town_khergit", 1),
    (else_try),
  (eq, ":random_song", 11),
  (play_track, "track_town_nord", 1),
    (else_try),
  (eq, ":random_song", 12),
  (play_track, "track_town_rhodok", 1),
    (else_try),
  (eq, ":random_song", 13),
  (play_track, "track_town_swadian", 1),
    (else_try),
  (eq, ":random_song", 14),
  (play_track, "track_town_vaegir", 1),
(try_end),
  ]),

 

jik

Knight
Here's my script, but it only works the first time.  It won't change tracks at all.  As you can see by the commented lines, I've tried a few things:

("fight_music",
[(store_random_in_range,":this_track",zf_track_1,zf_track_end), ##Pick a random track from the list
#(stop_all_sounds,1),
#(play_track,":this_track", 1), ## 0 = default, 1 = fade out current track, 2 = stop current track
(play_cue_track,":this_track"),
(display_message,"@Changing Music Tracks...",0xffff33),
]
),

Now, this is mid scene, not jumping to a dialog or a camp menu.  Have you done it with a key trigger or something else that doesn't break into the scene?
 

Keedo420

Knight at Arms
I have not done it with a trigger, no. When you say it only works the first time, is the "Changing Music Tracks..." message still being displayed even though it isn't changing tracks? If not I'd look at the trigger itself and check the first three settings:
Code:
# 1) Check interval: How frequently this trigger will be checked
# 2) Delay interval: Time to wait before applying the consequences of the trigger
#    After its conditions have been evaluated as true.
# 3) Re-arm interval. How much time must pass after applying the consequences of the trigger for the trigger to become active again.
#    You can put the constant ti_once here to make sure that the trigger never becomes active again after it fires once.

Otherwise, I'm not sure why it wouldn't work after the initial track change.
 

jik

Knight
Well, a bit to report, the tracks are about 4 minutes long, so I think the cue_track thing lines up the tracks.  My trigger is called every 10 seconds (for testing), but the music plays out till the end.  So I tried to survive in the mission for over 4 minutes and at that point a new track played.  I do get the display message, so I know the script is running.

I just made 2 test camp menus.  1 to call my script (changed the call back to play_track) and 1 to (stop_all_sounds, 1).


[EDIT]

ok, it seems to be working now, kind of...  Here is all the code involved:
(script)
("fight_music",
[(store_random_in_range,":this_track",zf_track_1,zf_track_end), ##Pick a random track from the list
#(stop_all_sounds,1),
(play_track,":this_track", 1), ## 0 = default, 1 = fade out current track, 2 = stop current track
(display_message,"@Changing Music Tracks...",0xffff33),
]
),

(triggers)
(0, 0, ti_once, [],  ###Sets variables
[(assign, ":z_count",0),
(val_add,"$searched",1), ##increment the searched time (in hours)
(store_mul,":z_count",25,"$searched"), ##Every hour adds (25+25xhours) more zombies !!!CHANGE THE 5 BACK TO 25!!!
(val_add,":z_count",25), ##!!!CHANAGE THE 5s back to 25!!!!#########
            (assign, "$max_zombies", ":z_count"), ##should have an equation based on hours searched ("$searched") for max number
(assign, "$zombies_spawned", 0),
(assign, "$zombies_killed", 0),
#(play_cue_track,"track_z_fight_1"),
(call_script,"script_fight_music"),
    ]
),


(30,0,0,[], ##Change music after 3.5 mins (210 seconds).
[(call_script,"script_fight_music"),
]
),

So I call the script at the start of the mission, then every 30 seconds, but it seems that the track starts to play then fades out.

the only other 'sound' trigger would be this:

(1,0,0,[], ##zombie moaning
[(try_for_agents,":zombie"), ##Find a random zombie to make a sound
(agent_get_team  ,":z_team",":zombie"),
(eq,":z_team",1), ##Must be on the zombie team (1)
(agent_is_alive,":zombie"),
(store_random_in_range,":moan",1,100),
(gt,":moan",50), ##Don't always moan
(agent_play_sound,":zombie","snd_zombie_yell"), ##if you do, this is the sound
(try_end),
]
),

Though I don't think it should interfere with the music should it?
 

Keedo420

Knight at Arms
I don't think the agent_play_sound would interfere with the music. Though perhaps there is a conflict with the "combat_music_set_situation_with_culture" script?
 

jik

Knight
Keedo420 said:
I don't think the agent_play_sound would interfere with the music. Though perhaps there is a conflict with the "combat_music_set_situation_with_culture" script?

I didn't add that script to my mission_template (that I know of).  Let me take a look and see if I find it in my stuff...


EDIT:

Nope, not used in my template, nor in the common triggers either.  Also, before adding my music code, there was no music at all...
 

Keedo420

Knight at Arms
I'm not sure what the problem is then. I know that for my minstrels, when the player chooses a song when talking to them in a tavern or from the camp menu, it fades out the current song and then starts the chosen song. And if they choose another song before the current song ends, it still works. Now, when a minstrel is in the player's party, the player can talk to them in battle and ask them to play a song (this does not stop them from fighting though :mrgreen:), however I don't think I've tried asking them more than once in a battle.
 

HokieBT

Grandmaster Knight
M&BWB
I haven't done much with music, besides comment out 95% of it, in my mod.  I think play_cue_track should always start immediately while play_track has some flags as you mentioned (fade out, etc).  I'm currently trying to go through the music file and get rid of all this crap and make a simple music file, so thanks for posting this code, I may try some similar stuff...  anyway, the trigger you posted has the music changing every 30 seconds (30,0,0,[],) not 3.5 minutes, so its going to fade out the current track that is playing and then start again every 30 seconds.  So I'd first suggest changing that trigger to 210 like you have in your comments and see if that fixes it?

edit:  nevermind, just realized you did the 30 seconds for testing....  does it restart every 30 seconds, or just play once and then stop?  I'm thinking its a weird limitation where you can't change the music during a scene after it is set, so once your trigger runs after 30 seconds it is messed up.  If you pass it the 0 flag does it queue it up behind the first one?  So could you do this in your script and just call it ti_once and comment out the 30 second trigger?

Code:
(play_track,"track_1",1),
(play_track,"track_2",0),
(play_track,"track_3",0),
 

jik

Knight
I'm not sure what is happening, but something must be getting in the way.  I think play_cue_track will play the track from start to finish, I was not able to stop it when I used that command (even with the stop_all_sounds operation). 

With the code I have right now, the track plays for about 2 seconds then fades out.  It could be an issue with starting the music before the scene starts ( the first trigger).  I have had issues with other operations when I use a trigger that could start before the scene.  Instead I have put the first music trigger with the spawning of the first zombies (about 5 seconds into the scene).  Testing now...

Still the same thing...  the music plays for about 2 seconds then fades out...  OK, dropping the fade out flag...  Testing....  That didn't work either.

Question ->  How do you start your first song?  Could it be that since there is no music playing that it fades out the current track which is itself (sounds silly but that is what it is doing...)
 

Flanged

Sergeant Knight
Having not much of a clue about operations or triggers, I attempted to add specific music to a scene by attaching it to an object and then hiding the object in the scene.  First of all, I just changed the sound made by the torch to be my chosen music track - obviously this is not a good idea if your mod will actually have lots of torches in it's scenes.

Then I just attached music to stones and placed them where I wanted the track to be heard.

Obviously, this is no good if you also have the game music playing, and the music gets louder the closer the player moves to the object.  It's a very limited and limiting method, but it was the cheap and cheerful way to have a specific track in a specific scene.
 

jik

Knight
Flanged said:
Having not much of a clue about operations or triggers, I attempted to add specific music to a scene by attaching it to an object and then hiding the object in the scene.  First of all, I just changed the sound made by the torch to be my chosen music track - obviously this is not a good idea if your mod will actually have lots of torches in it's scenes.

Then I just attached music to stones and placed them where I wanted the track to be heard.

Obviously, this is no good if you also have the game music playing, and the music gets louder the closer the player moves to the object.  It's a very limited and limiting method, but it was the cheap and cheerful way to have a specific track in a specific scene.

Not a bad idea, especially in missions where being in a certain spot may trigger something.  Can you post a sample?  The fact that my music goes on and off is a real p!$$ off...  What format are your music files?
 

Flanged

Sergeant Knight
It was simple really, probably a bit too simple, since I did this when I was first starting out and haven't refined the process at all. 

I just made an exact copy of a Native scene-prop (the torch in this case) and took out the stuff I didn't need, so it's only function would be to play the looping fire sound it has.

Code:
 ("torch",0,"torch_a","0",
   [
   (ti_on_init_scene_prop,
    [
        (set_position_delta,0,-35,48),
#        (particle_system_add_new, "psys_torch_fire"),
#        (particle_system_add_new, "psys_torch_smoke"),
#       (particle_system_add_new, "psys_torch_fire_sparks"),

        (play_sound, "snd_torch_loop", 0),
        
        (set_position_delta,0,-35,56),
#        (particle_system_add_new, "psys_fire_glow_1"),
#        (particle_system_emit, "psys_fire_glow_1",9000000),
   ]),
   ]),
Then I hid it just under the ground in a scene, and renamed my music track to be the same as the default torch sound - "Fire_Torch_loop3".  Because it counts as a Sound and not Music, it has to go in the Sound folder, and has to be encoded to .Ogg at 44100 Hz, 16-bit, MONO!  Has to be mono rather than stereo for sounds, though music can be stereo... annoying, eh?

It really has to be .Ogg Vorbis as well - I don't know why people keep saying that .mp3 works fine.  It surely don't.

It's easy to add a custom object with the same function of having a looping track attached.  My only custom one is called appt_sound, and uses the arena-ambiance loop because I don't have arenas in my mod.

Code:
("appt_sound",0,"appt_sound","0",   [
   (ti_on_scene_prop_init,
    [
     (set_position_delta,65,0,-7),

     (set_position_delta,70,0,-5),

     (play_sound, "snd_arena_ambiance", 0),
    ]),
   ]),

If you want to see it in action (unimpressive though it may be) you can visit Mad Harry's Club or The Penny Mob HQ in my mod (Gangs of Glasgow) with the Native music turned down, and you'll hear Iggy Pop, or crappy techno in some of the pubs.  How's that for self-promotion?  :grin:

For music the right format is 44100 Hz, 16-bit, Stereo.  For sound it's the same but Mono.  Audacity is the best free editor converter for sound, I reckon.

Hope that helps a bit, but it's not really doing what you're trying to do exactly.

 

jik

Knight
ah...  A bit of cheating.  I guess I can run it as a sound...  I guess I may have to go back and use the culture/situation stuff....
 

dablade

Master Knight
Flanged, people say mp3 works because it does work. We've been using mp3 sound files in TLD for years. And no, they don't have to be 44.1KHz 16-bit, other frequency sample rates work just fine.

I just thouhgt you might like to know about that :wink:
 

Flanged

Sergeant Knight
I don't believe you.

Seriously, though, I struggled for ages trying to get sound to play ingame at first, and it just wouldn't work at all until it was in that particular format.  Maybe it's different for music, or maybe I was just doing something else wrong.

It was a long time ago, and I basically didn't have a clue what I was doing.
 

dablade

Master Knight
Donload TLD for M&B .808 and you can see for yourself, we use lot's of mp3 for sounds there. 22Kh too :wink:

EDIT: I can't really remember right now, but I think you may be right about  it being differebt for music.
 

Flanged

Sergeant Knight
DaBlade said:
Donload TLD for M&B .808 and you can see for yourself, we use lot's of mp3 for sounds there. 22Kh too :wink:

EDIT: I can't really remember right now, but I think you may be right about  it being differebt for music.

I loved TLD for .808.  I still do.  Never realised the sounds were .mp3, but man, what a mod it is!  I don't think a lot of the new mods would be as ambitious as they are without the example set by TLD.  Can't wait for the new version.
 
Top Bottom