[TFC] Train Event train.sc
Hi,
In custom TFC maps func_trains or func_tracktrains are sometimes used. There is an annoying issue with the sound though. If sound is enabled on the train, the train will fire the event "events/train.sc" which in turn calls EV_TrainPitchAdjust on the client. As the name suggests the function adjust the pitch of the sound depending how fast the train goes. It will also stop the sound when the train stops.
Now this event was never added for TFC and thus the client gets flooded with invalid events "CL_FireEvents: Unknown event 44:events/train.sc" when a train with sound enabled is used. This also causes the sound to never be stopped and if the train is user controlable the sound will be played over itself each time the player stops and starts the train. This makes the sound extremely loud over time.
The issue should be pretty apparent looking at what the function EV_TrainPitchAdjust does, but I created a test map so you can reproduce the issue anyway: http://fs02n4.sendspace.com/dl/b84195b639a283dc66e659a06644e656/5182609551fcc661/s68oc1/TrainTest.bsp
EV_TrainPitchAdjust:
void EV_TrainPitchAdjust( event_args_t *args )
{
int idx;
vec3_t origin;
unsigned short us_params;
int noise;
float m_flVolume;
int pitch;
int stop;
char sz[ 256 ];
idx = args->entindex;
VectorCopy( args->origin, origin );
us_params = (unsigned short)args->iparam1;
stop = args->bparam1;
m_flVolume = (float)(us_params & 0x003f)/40.0;
noise = (int)(((us_params) >> 12 ) & 0x0007);
pitch = (int)( 10.0 * (float)( ( us_params >> 6 ) & 0x003f ) );
switch ( noise )
{
case 1: strcpy( sz, "plats/ttrain1.wav"); break;
case 2: strcpy( sz, "plats/ttrain2.wav"); break;
case 3: strcpy( sz, "plats/ttrain3.wav"); break;
case 4: strcpy( sz, "plats/ttrain4.wav"); break;
case 5: strcpy( sz, "plats/ttrain6.wav"); break;
case 6: strcpy( sz, "plats/ttrain7.wav"); break;
default:
// no sound
strcpy( sz, "" );
return;
}
if ( stop )
{
gEngfuncs.pEventAPI->EV_StopSound( idx, CHAN_STATIC, sz );
}
else
{
gEngfuncs.pEventAPI->EV_PlaySound( idx, origin, CHAN_STATIC, sz, m_flVolume, ATTN_NORM, SND_CHANGE_PITCH, pitch );
}
}
Please fix this as it seems like a 3 minute job. It sure is annoying hearing train sounds loop like that.
I'll fix the client to register the train event
Awesome!