case ENT_CLIENT_TUBANOTE: Ent_TubaNote(bIsNewEntity); break;
case ENT_CLIENT_WARPZONE: WarpZone_Read(bIsNewEntity); break;
case ENT_CLIENT_WARPZONE_CAMERA: WarpZone_Camera_Read(bIsNewEntity); break;
+ case ENT_CLIENT_TRIGGER_MUSIC: Ent_ReadTriggerMusic(); break;
default:
error(strcat("unknown entity type in CSQC_Ent_Update: ", ftos(self.enttype), "\n"));
break;
// NOTE: Could just do return instead of break...
switch(nTEID)
{
+ case TE_CSQC_TARGET_MUSIC:
+ Net_TargetMusic();
+ bHandled = true;
+ break;
case TE_CSQC_PICTURE:
Net_MapVote_Picture();
bHandled = true;
.float state;
-void Net_AdvanceMusic()
+void TargetMusic_Advance()
{
// run AFTER all the thinks!
entity best, e;
{
// decrease volume
if(e.fade_rate > 0)
- e.state = max(1, e.state - frametime / e.fade_rate);
+ e.state = max(0, e.state - frametime / e.fade_rate);
else
e.state = 0;
}
if(e.state != s0)
+ {
sound(e, CHAN_VOICE, "", e.volume * e.state, ATTN_NONE);
+ }
}
music_trigger = world;
}
void Net_TargetMusic()
{
float vol, fai, fao, tim, id;
- string noi;
+ string noi, s;
entity e;
id = ReadShort();
{
e = spawn();
e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
- if(e.noise)
- strunzone(e.noise);
- e.noise = strzone(noi);
- sound(e, CHAN_VOICE, self.noise, 0, ATTN_NONE);
+ }
+ s = e.noise;
+ if(e.noise)
+ strunzone(e.noise);
+ e.noise = strzone(noi);
+ if(e.noise != s)
+ {
+ precache_sound(e.noise);
+ sound(e, CHAN_VOICE, e.noise, 0, ATTN_NONE);
}
e.volume = vol;
e.fade_time = fai;
void Ent_TriggerMusic_Think()
{
if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
+ {
music_trigger = self;
+ }
self.nextthink = time;
}
void Ent_ReadTriggerMusic()
{
float f;
+ string s;
f = ReadByte();
if(f & 4)
{
self.volume = ReadByte() / 255.0;
self.fade_time = ReadByte() / 16.0;
self.fade_rate = ReadByte() / 16.0;
+ s = self.noise;
if(self.noise)
strunzone(self.noise);
self.noise = strzone(ReadString());
+ if(self.noise != s)
+ {
+ precache_sound(self.noise);
+ sound(self, CHAN_VOICE, self.noise, 0, ATTN_NONE);
+ }
}
+ setorigin(self, self.origin);
+ setsize(self, self.mins, self.maxs);
self.cnt = 1;
self.think = Ent_TriggerMusic_Think;
self.nextthink = time;
// when targetname is not set, THIS ONE is default
void target_music_sendto(float to, float is)
{
+ WriteByte(to, SVC_TEMPENTITY);
WriteByte(to, TE_CSQC_TARGET_MUSIC);
WriteShort(to, num_for_edict(self));
WriteByte(to, self.volume * 255.0 * is);
// when triggered, it is disabled/enabled for everyone
float trigger_music_SendEntity(entity to, float sf)
{
- WriteByte(MSG_ENTITY, TE_CSQC_TARGET_MUSIC);
+ WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
sf &~= 0x80;
if(self.cnt)
sf |= 0x80;