Sound coding questions


(P4nth3r) #1

Hi, it’s me again with a few stupid coding questions.
I’ve been trying my ass of for this but I just don’t get it to work.

Ok we start of simple (atleast I thought it should be simple)
Here is what I wanted it to do:

I wanted to let’s say:

	cgs.media.noAmmoSound =			trap_S_RegisterSound( "sound/weapons/misc/fire_dry.wav", qfalse );

This to have multiple sounds that could be used for it (so if you have a “dry fire” you don’t hear the same click everytime. (don’t ask me why, but this is just an example)

So I looked at some of the other code and came up with this:

	for( i = 0; i < 2; i++ ) {
	cgs.media.noAmmoSound =			trap_S_RegisterSound(va( "sound/weapons/misc/fire_dry%i.wav", qfalse );
                    }

That didn’t work, really right (he only played the second sound and not the first.
So I noticed at some other examples that the had this [i] behind the cgs.media.noAmmoSound

So I tried this but now I get errors that he can’t build the code =(

I looked at some of the code that uses the [i] but I couldn’t figure out why they DID work but mine did not.
How Do I fix this???

Second problem

I wanted those sounds (some of them, like the land_hurt etc.) to be different per team.
Well I looked and I looked and tried and tried but couldn’t figure out how to make it happen.

(hope all this isn’t to complicated to do)

Can somebody help me?

Thnx & Greetz Panther aka Way2evil


(kamikazee) #2

I’d sugest looking on some basic course of C coding.
Square brackets ‘[ ]’ mean that you want to use the variable in front of it as a list.

Problem is: this variable is not a list, so you can only assign 1 value to it.
Whilst I can read C code and thus most parts of the code, I don’t know where you should put this as I don’t know the structure of the ET code completely. Therefore, I cannot help you anny further at the moment, maybe after I’ve searched in the gamecode.


(P4nth3r) #3

Well for some of the weapons like grenade bouce it directs to something like this in cg_events.c:

		// GRENADES
			if( es->eventParm != FOOTSTEP_TOTAL ) {
				if ( rand() & 1 ) {
					trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.grenadebounce[ es->eventParm ][0] );
				} else {
					trap_S_StartSound( NULL, es->number, CHAN_AUTO,  cgs.media.grenadebounce[ es->eventParm ][1] );
			}

code in cg_main.c:

		cgs.media.grenadebounce[FOOTSTEP_SPLASH][i] = trap_S_RegisterSound( va( "sound/weapons/grenade/bounce_hard%i.wav", i+1 ), qfalse );

But I’m really kinda noob in coding (I only know a little qbasic)

Thnx & greetz Panther aka Way2Evil


(nUllSkillZ) #4

There are some other sounds that have two or more wav files.
Have you searched the source for that?


(P4nth3r) #5

the grenade does that right?? (the bounces)

Or the explosion of airstrikes, but they use more like a numbered code [1] or [2] tried that too, didn’t get it too work =(

Thnx & Greetz Panther aka Way2Evil


(Shanks) #6

Change:

sfxHandle_t 	noAmmoSound;

To:

sfxHandle_t	          noAmmoSound[3];

in cg_local.h


(kamikazee) #7

Problem is: you’ll need to fix all occurences of noAmmoSound to acces it as a list as well.


(P4nth3r) #8

@ -bacon-

Let me get this right, I only need to change let’s say the noAmmoSound into noAmmoSound[3] and then the %i stuff will work?

Thnx & Greetz Panther


(Shanks) #9

That’s not really a problem, it’s more of an annoyance. Besides, it’s what the search function in <insert your IDE here> is for :banana:

@P4nth3r: That’s right, except the line should read:

cgs.media.noAmmoSound[i] =         trap_S_RegisterSound(va( "sound/weapons/misc/fire_dry%i.wav", i), qfalse );

(P4nth3r) #10

Thnx I’ll try that.

Greetz Panther aka Way2Evil


(P4nth3r) #11

Problem is: you’ll need to fix all occurences of noAmmoSound to acces it as a list as well.

So this means I have to change it in cg_event.c too??

Greetz Panther


(kamikazee) #12

I meant that you need to search for noAmmoSound trough the whole client code and fix it. If you don’t, you’ll get build errors anyhow, since you changed the variable’s definition.
You will need to put square brackets there, and adress the sound with a number from 0 to 2.
The numbers come from this definition:

sfxHandle_t             noAmmoSound[3];

It declares a list which can hold 3 items, and must be adressed starting from 0. (So, 0 to 2)

An example use of the startsound function then:

trap_S_StartSound( NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound[0] ); 

(P4nth3r) #13

Hmm I tried this, but it turns my limbo menu into a freak show =(
and it doesn’t work either,I most be doing something wrong =(

Do I need the grenade part of code or the noAmmoSound part??

I’m really confused, I thought this was going to be easy ^^ since ET allready does things like that.
But guess its harder then I though. =(

Can somebody make it REALLY clear for me?? =$

Thnx & Greetz Panther aka Way2Evil


(Jaquboss) #14

cg_local.h:

sfxHandle_t	noAmmoSound;

to

sfxHandle_t	noAmmoSound[2];

cg_main.c:


	cgs.media.noAmmoSound =			trap_S_RegisterSound( "sound/weapons/misc/fire_dry.wav", qfalse );

to


 for( i = 0; i < 2; i++ ) {
   cgs.media.noAmmoSound =         trap_S_RegisterSound(va( "sound/weapons/misc/fire_dry%i.wav", i), qfalse );
                    }

cg_event.c


			trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound );

to


			trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound[rand() % 2] );


(jet Pilot) #15

Think of it like this :
An Array (the ‘list’ variable, in your case, noAmmoSound) is a group of variables that share the same name. The number you assign when you create them is how many share it.

sfxHandle  noAmmoSound[2]; 

means you have 2. (which are 0 and 1, remember, the 1st one is ALWAYS 0) if you try to play noAmmoSound[2] you will get problems, anything from weird bugs to access violation crashes of whatever.

What’s happening in your original code (and in Jaqueboss’s too?) is you’re trying to assign noAmmoSound a value. Bad! depending on your compiler it may or may not assign the value to noAmmoSound[0].
Either way, as you progress through the ‘for’ loop, each iteration reassigns noAmmoSound to the new sound, which will result in only the very last sound being registered. That’s why it was only playing your second sound.

as was stated before, the loading code should look like this :

for( i = 0; i < 2; i++ ) {
   cgs.media.noAmmoSound[i] = trap_S_RegisterSound(va( "sound/weapons/misc/fire_dry%i.wav", i), qfalse );
         } 

(kamikazee) #16

Indeed, he forgot the braces.
BTW: I allready tried to explain the list declaration statement.


(P4nth3r) #17

Thnx guys,

You are life savers (this really got me worked up cause I couldn’t get it to work)

Thnx & greetz Panther


(P4nth3r) #18

ok, I got this now: (added top and bottum codelines to show hwere I put it)

cg_main.c

		speaker->noise = trap_S_RegisterSound( speaker->filename, qfalse );
	}

for( i = 0; i < 2; i++ ) { 
   cgs.media.noAmmoSound[i] = trap_S_RegisterSound(va( "sound/weapons/misc/fire_dry%i.wav", i), qfalse ); 
         } 

	cgs.media.noFireUnderwater =	trap_S_RegisterSound( "sound/weapons/misc/fire_water.wav", qfalse );

cg_local.h

	sfxHandle_t	gibSound;
	sfxHandle_t noAmmoSound[2];
	sfxHandle_t landSound[FOOTSTEP_TOTAL];

cg_event.c

			(es->weapon != WP_MEDKIT))
trap_S_StartSound (NULL, es->number, CHAN_AUTO, cgs.media.noAmmoSound[rand() % 2] );

		if( es->number == cg.snap->ps.clientNum && (

So I did everything you told me to do, (I think) but now my limbo screen looks like this: (freak show)

I don’t know what the **** happends =/
Maybe my computer is cursed??

Help me =(

Thnx & Greetz Panther aka Way2Evil


(P4nth3r) #19

ps. He does play fire_dry0.wav and fire_dry1.wav fine now, but some others sounds don’t play.


(kamikazee) #20

Sure you didn’t do anything wrong whilst experimenting with gibs? This can be awkward to debug… :uhoh: