Page 1 of 1

switching between sounds

Posted: Mon Aug 11, 2008 5:15 am
by creekmonkey
Is it possible to switch between different sounds in a lowlevel command?

I have a vehicle that operates in lowlevel commands
accelerates when spacebar is pressed
brakes when B is pressed..............exct.

I was hoping to have a sound for acceleration, one for full speed, one for braking and deceleration.
I tried using

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

which kind of works....except i see no way of stopping accelerate.wav.
Am I overlooking something or is this not possible?

Re: switching between sounds

Posted: Wed Aug 13, 2008 4:22 am
by steven8
creekmonkey wrote:Is it possible to switch between different sounds in a lowlevel command?

I have a vehicle that operates in lowlevel commands
accelerates when spacebar is pressed
brakes when B is pressed..............exct.

I was hoping to have a sound for acceleration, one for full speed, one for braking and deceleration.
I tried using

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

which kind of works....except i see no way of stopping accelerate.wav.
Am I overlooking something or is this not possible?
I am not a scripter, but maybe: How about saying if the speed is greater than 1 or less than ten, play accelerate, else if speed is less than one, play no sound?

Re: switching between sounds

Posted: Wed Aug 13, 2008 4:32 am
by creekmonkey
My problem is the sounds are overlapping, once my wav file starts it doesnt stop until finished no matter what i try. It seems ther is no LowLevel command to stop sounds.

Im sure there is probably some way to make acceptable vehicle sounds, I just cant get it to work. Maybe Juutis, QOD, bernie or one of the other scripting gurus have had some luck with this.

Re: switching between sounds

Posted: Wed Aug 13, 2008 4:40 am
by steven8
Shoot. :(

Re: switching between sounds

Posted: Wed Aug 13, 2008 10:49 am
by Juutis
Oh ya, I now I get your problem. I came up with a couple of possible solutions:

1.) Make the sounds very short.

2.) Add a timer so a new sound can only start when the old is finished. So for example if your sounds are 2 seconds long:

Code: Select all

if(soundtimer < time)
{

if(IsKeyDown(46))
{
if(speed<10)
{
PlaySound("accelerate.wav");
}

else
{
if(speed>10)
{
PlaySound("fullspeed.wav");
}
}
}

soundtimer = time + 2;
}
3.) I don't know if this works but using the AudioSource3D entity is one option. If turning the trigger for the entity off stops the sound immediately, it would work. But you'll have to test this yourself.

Re: switching between sounds

Posted: Thu Aug 14, 2008 12:02 am
by creekmonkey
I was able to get the sounds fairly close using the audiosource3d.
It took a lot of ugly scripting, but it works.
4 triggers
4 audiosorce3d entities
and a ton of SetEventState(char *Trigger, bool State ).
The sounds are not the best but its way closer than I was.