Game Development Community

Prepare to fight sound.

by Mark Junior · in Torque Game Engine · 10/29/2006 (1:33 am) · 18 replies

Hi, im trying to put so that when the client (player) enters the game (the mission) it will play a prepare to fight! sound. though im having dificultys... its not working. in console.log it sais that syntax error on line 229 in game.cs server side... so i had a look on both line 228 and 229 heres the code there was on that function:


function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);

// Setup game parameters, the onConnect method currently starts
// everyone with a 0 score.
%this.score = 0;

// Create a player object.
%this.spawnPlayer();
if (%this.spawnPlayer()); // if the player spawns it will play the prepare to fight sound
PrepareToFight;
}


is this in the correct syntax? i loaded my sound profile in the beggining of game.cs too.

any help apreciated.

EDIT: Oh yes and if this is in the wrong place. then tell me cause i want it to be played when the player spawns in the mission.

#1
10/29/2006 (5:37 am)
You shouldn't need the if statement.

//Create a player object
%this.spawnPlayer();
 alxPlay(YourMusicProfile);
}

Oh, and [ code ] [ /code ] tags work great. :)
#2
10/29/2006 (6:55 am)
Hehe just didnt use it cause last time it didnt work, (didnt bother :) ) Thanks for the info!
#3
10/29/2006 (7:01 am)
Hmm... its not working :( is this because of the way i loaded my music profile? heres how i loaded it beggining of game.cs:
datablock AudioProfile(PrepareToFight)
{
filename = "~/data/sound/prepare1.wav";
description = AudioClose2d;
preload = true;
};

gonna check console.log in a sec.

EDIT: Console log doesnt have any errors :O.
#4
10/29/2006 (7:03 am)
Or does it have to be .ogg?
#5
10/29/2006 (8:53 am)
Put it on the client side and then make a function in the game.cs on the client side. Call it from the server with a command to client.

Good example is starter.racing.

look at these files:

client/scripts/audioProfiles.cs
new AudioProfile(AudioGoBeep)
{
	filename = "~/data/sound/beep2.wav";
	description = "AudioGui";
	preload = true;
};

client/scripts/game.cs
function clientCmdGameStart(%seq)
{
	// Display the GO bitmap and play a sound
	counter.setBitmap("starter.racing/client/ui/go.png");
	alxPlay(AudioGoBeep);
	// Remove the GO after a second.
	counter.schedule(1000, setVisible, false);
}

and finally:

server/scripts/game.cs
function startRace()
{
   // Inform the client we're starting up
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'GameStart');
#6
10/29/2006 (9:26 am)
Hmm... interesting ill test that out.
#7
10/29/2006 (9:34 am)
Is there such thing as this audio description?: AudioClose2d?
#8
10/29/2006 (10:02 am)
Aha... i did what you said mb but it seems i have a error on line 41 in audioprofiles in client side heres the code of the audioprofile:

new AudioProfile(PrepareToFight)
{
   filename= "~/data/sound/prepare1.wav";
   description = "AudioClose2d";
        

}

anyhelp apreciated.
#9
10/29/2006 (10:40 am)
You missed the ; on the end of }

new AudioProfile(PrepareToFight)
{
filename= "~/data/sound/prepare1.wav";
description = "AudioClose2d";

};
#10
10/29/2006 (10:47 am)
Thanks
ill test that out sec.
#11
10/29/2006 (10:49 am)
This isnt working do i need to preload?
#12
10/29/2006 (8:50 pm)
I would say yes, but I don't know for sure.

If you set it up like that it should work, I cant really help without seeing your code.
#13
10/30/2006 (5:05 am)
Well ok heres my game.cs what i needed to add to it...:

// Inform the client we're starting up
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');

// Other client specific setup..
%cl.score = 0;
}
that tells to call the function in the client side to the server side then theres client sides audioprofile.cs:

new AudioProfile(PrepareToFight)
{
filename= "~/data/sound/prepare1.wav";
description = "AudioClose2d";


};
that tells to load the sound. then to playthesound function in client sides game.cs:

function clientCmdGameStart(%seq)
{
PlayerListGui.zeroScores();
alxPlay(PrepareToFight);
}

well theres my code all ive done... hope you can help now :).

EDIT: well again i didnt bother the [code] tags ;P.
#14
10/30/2006 (6:52 am)
One thing I left out was Audio Descriptions... you can look up the description for AudioGui and try to use something simular, I dont have the code in front on me right now. It points the description where u have 'AudioClose2d' in your code... change it to a name to use (they must match). Also I dont know offhand what audio types are available for the 'type' field below.

it looks something like:

new AudioDescription ( AudioGui )
{
   volume = 1.0;  // full volume
    isLooping = false;
    is3D = false;
    type = $SOMEAUDIOTYPE;
}

edit:
I'm not sure if description is an option or if it is always needed. You can try commenting out the description field in your AudioProfile and see if that works also.
#15
10/30/2006 (7:00 am)
So do i create the audio description and the audioprofile?
#16
10/30/2006 (9:24 am)
Yeah try that or try deleting the description field from the AudioProfile.

new AudioProfile(PrepareToFight)
{
filename= "~/data/sound/prepare1.wav";
};

if that doesnt work make the description and add it back in.
#17
10/30/2006 (10:09 am)
Ok ill try that.
#18
10/30/2006 (7:02 pm)
I got this to work:

At the end of startGame() in server/game.cs I added a schedule:

schedule(5000, 0, "startSound");
}

Then a new function startSound:
function startSound()
{
   // Tell the client to count.
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'PlayStartSound');
   }
}

PlayStartSound is in client/game.cs
function clientCmdPlayStartSound()
{
	alxPlay(AudioGameStart);
}

and AudioGameStart is in client/audioProfiles.cs

// Game Start FX
new AudioProfile(AudioGameStart)
{
   filename = "~/data/sound/Crossbow_explosion.ogg";
   description = "AudioGui";
	preload = true;
};

This works, but it calls it while the map is loading... you can call it someplace else of course wherever you choose.

glad we finally figured that one out.