1 #include "target_music.qh"
3 void TargetMusic_Advance()
5 // run AFTER all the thinks!
9 if(music_target && time < music_target.lifetime)
13 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise)
16 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
24 e.state = bound(0, e.state + frametime / e.fade_time, 1);
32 e.state = bound(0, e.state - frametime / e.fade_rate, 1);
36 vol = e.state * e.volume * autocvar_bgmvolume;
40 sound(e, CH_BGM_SINGLE, e.noise, vol, ATTEN_NONE); // restart
42 sound(e, CH_BGM_SINGLE, "", vol, ATTEN_NONE);
46 music_trigger = world;
49 bgmtime = getsoundtime(best, CH_BGM_SINGLE);
51 bgmtime = gettime(GETTIME_CDTRACK);
54 void Net_TargetMusic()
57 float vol = ReadByte() / 255.0;
58 float fai = ReadByte() / 16.0;
59 float fao = ReadByte() / 16.0;
60 float tim = ReadByte();
61 string noi = ReadString();
64 for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); )
72 e.enttype = ENT_CLIENT_TRIGGER_MUSIC;
79 e.noise = strzone(noi);
80 precache_sound(e.noise);
81 sound(e, CH_BGM_SINGLE, e.noise, 0, ATTEN_NONE);
82 if(getsoundtime(e, CH_BGM_SINGLE) < 0)
84 dprintf("Cannot initialize sound %s\n", e.noise);
86 e.noise = string_null;
100 cvar_settemp("music_playlist_index", "-1"); // don't use playlists
101 localcmd("cd stop\n"); // just in case
108 e.lifetime = time + tim;
113 void Ent_TriggerMusic_Think()
115 if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world))
117 music_trigger = self;
119 self.nextthink = time;
122 void Ent_TriggerMusic_Remove()
125 strunzone(self.noise);
126 self.noise = string_null;
129 void Ent_ReadTriggerMusic()
134 self.origin_x = ReadCoord();
135 self.origin_y = ReadCoord();
136 self.origin_z = ReadCoord();
140 self.modelindex = ReadShort();
143 self.mins_x = ReadCoord();
144 self.mins_y = ReadCoord();
145 self.mins_z = ReadCoord();
146 self.maxs_x = ReadCoord();
147 self.maxs_y = ReadCoord();
148 self.maxs_z = ReadCoord();
153 self.maxs_x = ReadCoord();
154 self.maxs_y = ReadCoord();
155 self.maxs_z = ReadCoord();
158 self.volume = ReadByte() / 255.0;
159 self.fade_time = ReadByte() / 16.0;
160 self.fade_rate = ReadByte() / 16.0;
161 string s = self.noise;
163 strunzone(self.noise);
164 self.noise = strzone(ReadString());
167 precache_sound(self.noise);
168 sound(self, CH_BGM_SINGLE, self.noise, 0, ATTEN_NONE);
169 if(getsoundtime(self, CH_BGM_SINGLE) < 0)
171 dprintf("Cannot initialize sound %s\n", self.noise);
172 strunzone(self.noise);
173 self.noise = string_null;
178 setorigin(self, self.origin);
179 setsize(self, self.mins, self.maxs);
181 self.think = Ent_TriggerMusic_Think;
182 self.nextthink = time;