Inside3D!
     

Help: 'Dynamic .wav substitution' attempt

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
OneManClan



Joined: 28 Feb 2009
Posts: 62

PostPosted: Fri Mar 19, 2010 2:10 am    Post subject: Help: 'Dynamic .wav substitution' attempt Reply with quote

[DISCLAIMER: I'm still a newbie programmer, so please feel free to 'dumb-down' all explanations.]

Hi guys,

I'm trying to replace a bunch of sounds with alternative sounds depending on the environment, as discussed here.

Doing it in the QuakeC seems to be doing the job nicely, but now I have an issue.

I'm doing this by hijaking the 'sound' function, adding checks, and playing different versions of the wav's, but certain sounds aren't being replaced. My comments in the code:

Code:
void( entity e, float chan, string samp, float vol, float atten ) sound = {

// for testing. This produces an 'cannot sprint to non client' error for projectiles (as expected)
sprint(self,#PRINT_HIGH,samp);
sprint(self,#PRINT_HIGH,"\n");


// if we're underwater
if(e.waterlevel > 2)
{

// works
   if (samp == "player/axhit2.wav") sound_c( e, chan, "player/uw_axhit2.wav", vol, atten);

   else
// works
   if (samp == "weapons/shotgn2.wav") sound_c( e, chan, "weapons/uw_shotgn2.wav", vol, atten);

   else

// works
   if (samp == "weapons/guncock.wav") sound_c (self, #CHAN_WEAPON, "weapons/uw_guncock.wav", 1, #ATTN_NORM);

   else
// works for the firing of the rocket, but *not* for when the rocket projectile hits something - where do I access that sound?
   if (samp == "weapons/sgun1.wav") sound (self, #CHAN_WEAPON, "weapons/uw_sgun1.wav", 1, #ATTN_NORM);
   
   else
// DOESN'T WORK  - plays the normal sound of a gren bouncing
   if (samp == "weapons/bounce.wav") sound_c (self, #CHAN_WEAPON, "weapons/uw_bounce.wav", 1, #ATTN_NORM);   // bounce sound
   
   else
// DOESN'T WORK  - normal grenades make the normal 'throwing' sound, and pipebombs / grenade launcher don't play any throwing sound - silence.... you just hear the subsequent bounce
   if (samp == "weapons/grenade.wav") sound_c (self, #CHAN_WEAPON, "weapons/uw_grenade.wav", 1, #ATTN_NORM);
   
   else
// works
   if (samp == "weapons/ax1.wav") sound_c (self, #CHAN_WEAPON, "weapons/uw_ax1.wav", 1, #ATTN_NORM);
}


Theory 1:
There's some issue with projectile sounds. Maybe they are triggered elsewhere.


Theory 2:
Calls to the 'sound' function are often followed by these 'WriteByte' commands, which I don't understand:

WriteByte (#MSG_BROADCAST, #SVC_TEMPENTITY);
WriteByte (#MSG_BROADCAST, #TE_EXPLOSION);
WriteCoord (#MSG_BROADCAST, self.origin_x);
WriteCoord (#MSG_BROADCAST, self.origin_y);
WriteCoord (#MSG_BROADCAST, self.origin_z);

It looks as if there are two ways to make a sound, and my function can't detect that the alternative 'writebyte' method is being used??


Any help appreciated,


OneManClan
ps. If anyone can think of a clearer way to describe the 'subject' of this thread, please advise
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Fri Mar 19, 2010 2:33 am    Post subject: Reply with quote

tip: in quakeworld, use dprint for server-side debug prints.

e.waterlevel might sound correct... but its not as simple as that. Only players, tossed (including flying/bounce/flymissile), and stepping entities will have the waterlevel field updated.
For any other entity, you will need to do it yourself - by using pointcontents. But this isn't your major issue.

So yeah, those WriteBytes....
SVC_TEMPENTITY: Create a temporary special effect...
TE_EXPLOSION: specifically, create a dynamic light that will fade over time, a particle effect that looks somewhat like an explosion, an explosion sprite (in quakeworld anyway)... and yes... an explosion sound effect.
You then have the 3 axis coord of the explosion effect.
Sorry, but there's nothing in the client that allows you to have the particle effect without the sound. The one workaround I can think of is to kill the normal sound effect (replace it with a 0-length wav) and create two replacement ones, one for air (a copy of the original), one for water, and explicitly play them. But I'm not sure how practical/robust that is for your mod.

Sorry I can't be of more help.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
OneManClan



Joined: 28 Feb 2009
Posts: 62

PostPosted: Fri Mar 19, 2010 4:15 am    Post subject: Reply with quote

Spike wrote:
tip: in quakeworld, use dprint for server-side debug prints.


Thanks, I just tried dprint, and it confirmed that the sounds played are indeed 'weapons/bounce.wav' and 'weapons/grenade.wav'. It seems the lines:

Code:
if (samp == "weapons/bounce.wav")
sound_c (self, #CHAN_WEAPON, "weapons/uw_bounce.wav", 1, #ATTN_NORM);   // bounce sound


and

Code:
if (samp == "weapons/grenade.wav")
sound_c (self, #CHAN_WEAPON, "weapons/uw_grenade.wav", 1, #ATTN_NORM);


aren't working. Here's a breakdown of what's happening, in case someone can see a pattern:

The output is:

<sound wave played> <entity waterlevel>

Throwing a normal grenade underwater (with 3 bounces):
"weapons/grenade.wav" 3 // the 'normal' wav plays
"weapons/bounce.wav" 0 // "
"weapons/bounce.wav" 1 // "
"weapons/bounce.wav" 1 // "

Throwing a grenade launcher grenade underwater (with 3 bounces):
"weapons/bounce.wav" 0 // silence!!!!??
"weapons/bounce.wav" 1 // the 'normal' wav plays
"weapons/bounce.wav" 1 // "
"weapons/bounce.wav" 1 // "

Confused
Spike wrote:

e.waterlevel might sound correct... but its not as simple as that. Only players, tossed (including flying/bounce/flymissile), and stepping entities will have the waterlevel field updated.


I see... Yes, the above test was done underwater, and the grens didn't know, though the initial 'throwing sound' of the regular grenade did know it was underwater.

Spike wrote:
For any other entity, you will need to do it yourself - by using pointcontents.

Quote:

float pointcontents(vector pos)

Returns the contents of the area situated at position pos.
Used to know if an area is in water, in slime or in lava.
Makes use of the BSP tree, and is supposed to be very fast


Ok, so I just tried replacing:

Code:
if(e.waterlevel > 2)

with
Code:
if (pointcontents(e.origin) == #CONTENT_WATER)


And it seems to work just as well... AND the gren *bounces* are working!! Smile .... but the 'throwing' sound issue is still there: 'Above water sound' for throwing normal grens, and silence (!) for the gren launcher, hmmm.

Spike wrote:
But this isn't your major issue.

So yeah, those WriteBytes....
SVC_TEMPENTITY: Create a temporary special effect...
TE_EXPLOSION: specifically, create a dynamic light that will fade over time, a particle effect that looks somewhat like an explosion, an explosion sprite (in quakeworld anyway)... and yes... an explosion sound effect.
You then have the 3 axis coord of the explosion effect.
Sorry, but there's nothing in the client that allows you to have the particle effect without the sound. The one workaround I can think of is to kill the normal sound effect (replace it with a 0-length wav) and create two replacement ones, one for air (a copy of the original), one for water, and explicitly play them. But I'm not sure how practical/robust that is for your mod.

Sorry I can't be of more help.


Thanks heaps, I've already gone further with this than I ever imagined!

I'll keep workin' on it w the gren sound, but the other weapons work surprisingly well.



OneManClan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group