Solved Play sound in Select screen

Question that is answered or resolved.

dantedevil

Well-known member
I want when open the select screen, the game play the voice of Shao Khan saying:

"CHOOSE YOUR DESTINY"

How I can do that?
 
Solution
Call this function in updated.c main function :

Code:
void selectScreenEvent(){
	int was_in_selectscreen = getlocalvar("was_in_selectscreen");
	if(openborvariant("in_selectscreen")){
		if(was_in_selectscreen == NULL() || !was_in_selectscreen){
			playSound("data/sounds/select_screen.wav");
			setlocalvar("was_in_selectscreen", 1);
		}
	} else {
		if(was_in_selectscreen != NULL() && was_in_selectscreen != 0) setlocalvar("was_in_selectscreen", 0);
	}
}

This should do the trick.

In case you have not the required playSound function :

Code:
void playSound(void file){
	if(!file||file==""){return;}else{}
	void sfx=loadsample(file);
	void vol=openborvariant("effectvol");
	playsample(sfx, 0, vol,vol, 100, 0);
}
Call this function in updated.c main function :

Code:
void selectScreenEvent(){
	int was_in_selectscreen = getlocalvar("was_in_selectscreen");
	if(openborvariant("in_selectscreen")){
		if(was_in_selectscreen == NULL() || !was_in_selectscreen){
			playSound("data/sounds/select_screen.wav");
			setlocalvar("was_in_selectscreen", 1);
		}
	} else {
		if(was_in_selectscreen != NULL() && was_in_selectscreen != 0) setlocalvar("was_in_selectscreen", 0);
	}
}

This should do the trick.

In case you have not the required playSound function :

Code:
void playSound(void file){
	if(!file||file==""){return;}else{}
	void sfx=loadsample(file);
	void vol=openborvariant("effectvol");
	playsample(sfx, 0, vol,vol, 100, 0);
}
 
Solution
Thanks Piccolo!

I update my updated.c with your script:

Code:
#include "data/scripts/anititle.c"
#include "data/scripts/story/story_define.h"
#include "data/scripts/story.c"
#include "data/scripts/gettick.c"


void zoom()
{
   void vscreen = openborvariant("vscreen");
   int maxz=openborvariant("PLAYER_MAX_Z")+1000;
   int zoom_value=getglobalvar("zoomvalue");
   int zoom_x=getglobalvar("zoomx");
   int zoom_y=getglobalvar("zoomy");
   void ent=getglobalvar("zoomentity");
   int px=getentityproperty(ent,"x") +  zoom_x - openborvariant("xpos");
   int py=getentityproperty(ent,"z") + zoom_y - openborvariant("ypos") - getentityproperty(ent,"a");
   void zoom_scr = getglobalvar("zoomscreen");
   if(!zoom_scr){
      zoom_scr = allocscreen(openborvariant("hResolution"),openborvariant("vResolution"));
      setglobalvar("zoomscreen",zoom_scr);
   }
   clearscreen(zoom_scr);

   //draw what we need 
   drawspriteq(zoom_scr,0,openborconstant("MIN_INT"),maxz,0,0);
   //setup drawMethod
   changedrawmethod(NULL(),"reset",1);
   changedrawmethod(NULL(),"enabled",1);
   changedrawmethod(NULL(),"scalex",zoom_value);
   changedrawmethod(NULL(),"scaley",zoom_value);
   changedrawmethod(NULL(),"centerx",px);
   changedrawmethod(NULL(),"centery",py);
   //Draw the resized customized screen to main screen.
   drawscreen(zoom_scr,px,py, maxz+1);
   changedrawmethod(NULL(),"enabled", 0);
   drawspriteq(vscreen, 0, maxz+1,maxz+1, 0, 0);
   drawspriteq(vscreen, 0, maxz+2,openborconstant("MAX_INT"), 0, 0);
   clearspriteq();
}


void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();       
   }
      mainLoop();
}

void mainLoop(){
	void scene=openborvariant("current_scene");
	if(openborvariant("in_level"))
	{
		turnWhite();
		storySystem();
	}
	if(openborvariant("in_titlescreen")){
		if (scene!="data/scenes/intro.txt"){
			inTitleLoop(1);
		}
	}
	else {
		inTitleLoop(0);	
	}
}

void selectScreenEvent(){
	int was_in_selectscreen = getlocalvar("was_in_selectscreen");
	if(openborvariant("in_selectscreen")){
		if(was_in_selectscreen == NULL() || !was_in_selectscreen){
			playSound("data/sounds/chose.wav");
			setlocalvar("was_in_selectscreen", 1);
		}
	} else {
		if(was_in_selectscreen != NULL() && was_in_selectscreen != 0) setlocalvar

("was_in_selectscreen", 0);
	}
}

And now where i put the playsound script and where they declare?
Code:
void playSound(void file){
	if(!file||file==""){return;}else{}
	void sfx=loadsample(file);
	void vol=openborvariant("effectvol");
	playsample(sfx, 0, vol,vol, 100, 0);
}
 
It's best to declare playSound function in another file (dedicated to sound functions) then import or include this file in updated.c to use it. Maybe you already have such a file in your mod.

Anyway you also need to call

Code:
selectScreenEvent();

in updated.c main() or mainLoop() function.
 
Well my friend, first I create the playsound.c, the include in updated.c.
No errors, but the voce file never play.

Here my file updated.c:

Code:
#include "data/scripts/anititle.c"
#include "data/scripts/story/story_define.h"
#include "data/scripts/story.c"
#include "data/scripts/gettick.c"
#include "data/scripts/playsound.c"


void zoom()
{
   void vscreen = openborvariant("vscreen");
   int maxz=openborvariant("PLAYER_MAX_Z")+1000;
   int zoom_value=getglobalvar("zoomvalue");
   int zoom_x=getglobalvar("zoomx");
   int zoom_y=getglobalvar("zoomy");
   void ent=getglobalvar("zoomentity");
   int px=getentityproperty(ent,"x") +  zoom_x - openborvariant("xpos");
   int py=getentityproperty(ent,"z") + zoom_y - openborvariant("ypos") - getentityproperty(ent,"a");
   void zoom_scr = getglobalvar("zoomscreen");
   if(!zoom_scr){
      zoom_scr = allocscreen(openborvariant("hResolution"),openborvariant("vResolution"));
      setglobalvar("zoomscreen",zoom_scr);
   }
   clearscreen(zoom_scr);

   //draw what we need 
   drawspriteq(zoom_scr,0,openborconstant("MIN_INT"),maxz,0,0);
   //setup drawMethod
   changedrawmethod(NULL(),"reset",1);
   changedrawmethod(NULL(),"enabled",1);
   changedrawmethod(NULL(),"scalex",zoom_value);
   changedrawmethod(NULL(),"scaley",zoom_value);
   changedrawmethod(NULL(),"centerx",px);
   changedrawmethod(NULL(),"centery",py);
   //Draw the resized customized screen to main screen.
   drawscreen(zoom_scr,px,py, maxz+1);
   changedrawmethod(NULL(),"enabled", 0);
   drawspriteq(vscreen, 0, maxz+1,maxz+1, 0, 0);
   drawspriteq(vscreen, 0, maxz+2,openborconstant("MAX_INT"), 0, 0);
   clearspriteq();
}

void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();       
   }
      mainLoop();
}

void mainLoop(){
	void scene=openborvariant("current_scene");
	if(openborvariant("in_level"))
	{
		turnWhite();
		storySystem();
	}
	if(openborvariant("in_titlescreen")){
		if (scene!="data/scenes/intro.txt"){
			inTitleLoop(1);
		}
	}
	else {
		inTitleLoop(0);	
	}
}

void selectScreenEvent(){
	int was_in_selectscreen = getlocalvar("was_in_selectscreen");
	if(openborvariant("in_selectscreen")){
		if(was_in_selectscreen == NULL() || !was_in_selectscreen){
			playSound("data/sounds/choose.wav");
			setlocalvar("was_in_selectscreen", 1);
		}
	} else {
		if(was_in_selectscreen != NULL() && was_in_selectscreen != 0) setlocalvar("was_in_selectscreen", 0);
	}
}

What did I miss?
 
You missed the last part of my last post.

selectScreenEvent is declared but not called.

Just paste this

Code:
selectScreenEvent();

at the start or the end of either the main or the mainLoop function.
 
Declare like this and not work:

Code:
void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();       
   }
      mainLoop();
}

void mainLoop(){
	void scene=openborvariant("current_scene");
	if(openborvariant("in_level"))
	{
		turnWhite();
		storySystem();
	}
	if(openborvariant("in_titlescreen")){
		if (scene!="data/scenes/intro.txt"){
			inTitleLoop(1);
		}
	}
	else {
		inTitleLoop(0);	
	}
                selectScreenEvent();   
}
 
dantedevil said:
Declare like this and not work:

Code:
void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();       
   }
      mainLoop();
}

void mainLoop(){
	void scene=openborvariant("current_scene");
	if(openborvariant("in_level"))
	{
		turnWhite();
		storySystem();
	}
	if(openborvariant("in_titlescreen")){
		if (scene!="data/scenes/intro.txt"){
			inTitleLoop(1);
		}
	}
	else {
		inTitleLoop(0);	
	}
                selectScreenEvent();   
}

You mean it crashes or it doesn't play the sound ? If the later, are you sure "data/sounds/choose.wav" exists ?

Everything seems good to me now.

If it still doesn't work you can check Illu's mod.
 
Back
Top Bottom