ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
How to play a sound in the main menu

« Previous 10 events | 1 2 | All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  08:05:31  13 April 2014
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
Messages: 567

---QUOTATION---

function main_menu:OnButton_return_game()


---END QUOTATION---


Putting the stop() argument in that function actually works immediately. I am going to add it when pressing the escape key, as well.
  08:16:44  13 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
May I ask what you are playing in the menu?
  08:48:32  13 April 2014
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
04/13/2014 23:24:09
Messages: 567

---QUOTATION---
May I ask what you are playing in the menu?
---END QUOTATION---


I am creating a dynamic main menu that expands something I saw in OGSE. I've written or modified scripts that change the main menu texture based on the time of day and level that the actor is currently in. A "stereo" audio file then plays while in the main menu to accompany whatever your main menu is portraying.

Example: If the actor is on l01_escape at 1300 hours, and they hit escape to the main menu, this script will load the mm_day_l01_escape texture. Ideally, it would also play audio_day_l01_escape, but I haven't implemented that yet (it currently just plays menu_test _l and _r).

I'd also love to play video instead of display a static texture. Remember how cool it was to see the main menu in Half Life 2 change as you progressed through the story? Not sure how to do this, though.

I took some stuff I saw in OGSE and adapted it. In ui_main_menu.script, I added: http://pastebin.com/E77vXVZJ

Within ui_main_menu.script, I also added: http://pastebin.com/sCqJAdbv

And here is the ui_mm_main.xml file: http://pastebin.com/558ChpQS

I'm currently only using placeholders, but this means you need:
- a "first start" texture for the initial load of the main menu
- a "day" static texture for each level
- a "night" static texture for each level
- a "day" audio track to play for each level
- a "night" audio track to play for each level
  11:15:47  13 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/13/2014 11:26:43
Messages: 319
I'm interested in this.

Your idea of the video in the main menu is pretty cool, a new sound as well. A flyby video of the level which the player currently is seems appropriate to me

For the video in the menu, some menu screens (all of them?) already have spaces on the screen dedicated to display animated stuff. The animation is in fact a video (ogm files in gamedata/textures/ui).

I guess it would be a matter of editing this space and playing the custom video. You could define a config file with one video name and then perhaps copy and then rename the file you want to play to match the name defined in the config file (don't know if I'm being being clear on this...).

IIRC, Far Cry had this in the main menu, a flyby over the first level. It was brilliant IMHO.
  10:56:14  17 April 2014
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
04/17/2014 11:04:01
Messages: 567
I am trying to think of an efficient way to play xxx_l.ogg and xxx_r.ogg files associated with the current level. I have it in my head in theory, but I don't know what the syntax would be.

I am currently using this piece of code to call up the actual video/texture file which is identified in the menu xml file:
function main_menu:__init() super()		
	self.mbox_mode = 0
	self:InitControls()
	self:InitCallBacks()
	-- some protection
	if type(save_prefix) == "string" then
		local new_save_prefix = string.gsub(save_prefix, "%%", "_")
		new_save_prefix = string.lower(new_save_prefix)
		save_prefix = string.gsub(new_save_prefix, "[:<=>?%*\\/;|,]", "_")
		if save_prefix ~= new_save_prefix then
			dbglog("Invalid filename char(s) in save_prefix - using \""..save_prefix.."\"")
		end
	else
		dbglog("Error in save prefix")
		save_prefix = ""
	end
end

function blah blah blah
        xml:InitStatic("mm_night_"..level.name(), self)
end


This is obviously wonderful because it automatically goes and finds the xml sections which reads <mm_night_l01_escape> if you are currently on l01_escape and it is night time. Vice versa if it is day time and you are on l02_garbage. It works great!

Is there a script that is similar in function but can instead be used to call/retrieve/play audio files called mm_night_audio_l01_escape_l and mm_night_audio_l01_escape_r? The naming convention I am using on all audio files for each level are:

mm_time of day_audio_level name_l (where time of day can either be "day" or "night')
mm_time of day_audio_level name_r


I would need it to somehow fit this syntax, as well, as this is how I call those audio files to be played:

mm_night_audio_l01_escape_l = xr_sound.get_safe_sound_object("daemonion\\menu\\mm_night_audio_l01_escape_l")
mm_night_audio_l01_escape_r = xr_sound.get_safe_sound_object("daemonion\\menu\\mm_night_audio_l01_escape_r")

function blah blah
  if (level.present() and db.actor) and menu_test_l:playing() == false then
	mm_night_audio_l01_escape_l:play_at_pos (actor, vector():set(-5, 0, 1), 1, sound_object.s2d)
	mm_night_audio_l01_escape_r:play_at_pos (actor, vector():set(5, 0, 1), 1, sound_object.s2d)
  end



If anyone can help, I would really, really appreciate it
  12:47:47  17 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/17/2014 12:51:20
Messages: 2230
Something like this maybe?


local function is_night()
	local gth = level.get_time_hours()
	return gth < 5 or gth > 19
end
  
local music_left_channel
local music_right_channel
function play_menu_music()
	if not (level.present() and db.actor) then 
		return 
	end 
	
	if (music_left_channel and music_right_channel) then 
		if (music_left_channel:playing() and music_right_channel:playing()) then
			return 
		end
		music_left_channel = nil
		music_right_channel = nil
	end
	
	local sound = "daemonion\\menu\\mm_"
	
	if (is_night() == true) then
		sound = sound .. "night"
	else 
		sound = sound .. "day"
	end 
	
	sound = sound .. "_audio_"..level.name()

	music_left_channel = xr_sound.get_safe_sound_object(sound.."_l")
	music_right_channel = xr_sound.get_safe_sound_object(sound.."_r")

	if (music_left_channel and music_right_channel) then
		music_left_channel:play()
		music_right_channel:play()
	end
end


------------------------
-- call play_menu_music from constructor
------------------------
function main_menu:__init()
	play_menu_music()
end

-------------------------
-- stop menu music and set values nil when exit menu
-------------------------
music_left_channel:stop()
music_right_channel:stop()
music_left_channel = nil
music_right_channel = nil

  20:52:35  19 April 2014
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
 

Message edited by:
Daemonion
04/19/2014 21:11:20
Messages: 567
Thanks, Alundaio, that was super helpful. I have made excellent progress thanks to your example.

Here is my current ui_main_menu.script (http://pastebin.com/fg8UN9X5). I tried to take out a lot of the extra code, but it currently implements these features successfully:

At all times:
1. Determines the current monitor's aspect ratio (wide or not wide)
2. Determines the time of day on the current level (day or night)

On main menu (before new game or game is loaded):
1. Shows a special video/texture on the main menu, which is selected based on screen resolution before a new game or game is loaded (notice aspect ratio: http://i.imgur.com/IUHKyUK.png, http://i.imgur.com/RhvntzG.png, http://i.imgur.com/N57D6Ao.png, http://i.imgur.com/Y1anctu.png)
2. Currently unable to play audio at this point except by changing the menu music file (still working on this)

When accessing main menu during gameplay:
1. Loads up a new main menu texture/video when the main menu is brought up during gameplay
2. Picks texture/video based on time of day (day or night version)
3. Selects and plays stereo audio from files to based on time of day (day or night version) and current level
http://i.imgur.com/P4Yihd8.png, http://i.imgur.com/lB7mhQE.png (I still need to re-size the video in this example in main_menu.xml, very WIP).

This all works at day and night on all levels. I still need to create all of the unique videos for each level, day and night, widescreen and 4:3 version.

The only issue I am having right now is that you have to exit and re-start the game after changing your resolution from 4:3 to wide (or wide to 4:3) in order to see the new texture/video that matches your resolution.

Anyway, I'd be happy to release this as a modder's resource once I am done with it if people are interested.
  22:47:53  19 April 2014
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
Messages: 454

---QUOTATION---
The only issue I am having right now is that you have to exit and re-start the game after changing your resolution
---END QUOTATION---


Here is a quick and dirty modification of your script to make that possible: http://pastebin.com/Rnaa9ZSX
The gist of it is that first, all the background-making stuff is abstracted out into its own function chooseBG. When the function is called, if there's a previous UI element stored in currentBG it turns it off, then makes the appropriate one and stores it. The point of all that is that now you just have to go stick another call to this function right after whatever code changes the screen resolution (or anywhere else you might want to), and it should update itself nicely.
  22:54:34  20 April 2014
profilee-mailreply Message URLTo the Top
Daemonion
All About Audio
(Resident)

 

 
On forum: 09/27/2011
Messages: 567

---QUOTATION---
The only issue I am having right now is that you have to exit and re-start the game after changing your resolution
Here is a quick and dirty modification of your script to make that possible: http://pastebin.com/Rnaa9ZSX
The gist of it is that first, all the background-making stuff is abstracted out into its own function chooseBG. When the function is called, if there's a previous UI element stored in currentBG it turns it off, then makes the appropriate one and stores it. The point of all that is that now you just have to go stick another call to this function right after whatever code changes the screen resolution (or anywhere else you might want to), and it should update itself nicely.
---END QUOTATION---


This is great. I will definitely spend some time implementing this - thank you for the idea.

I also realized (duh!) I forgot to add you to the credits! That has been fixed
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2022 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.