]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/target_music.qc
75f77acf53b77beb9e0fc9274dcabec0f8c3307c
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / target_music.qc
1 .float lifetime;
2 // values:
3 //   volume
4 //   noise
5 //   targetname
6 //   lifetime
7 //   fade_time
8 //   fade_rate
9 // when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0)
10 // when targetname is not set, THIS ONE is default
11 void target_music_sendto(float to, float is)
12 {
13         WriteByte(to, SVC_TEMPENTITY);
14         WriteByte(to, TE_CSQC_TARGET_MUSIC);
15         WriteShort(to, num_for_edict(self));
16         WriteByte(to, self.volume * 255.0 * is);
17         WriteByte(to, self.fade_time * 16.0);
18         WriteByte(to, self.fade_rate * 16.0);
19         WriteByte(to, self.lifetime);
20         WriteString(to, self.noise);
21 }
22 void target_music_reset()
23 {
24         if(self.targetname == "")
25                 target_music_sendto(MSG_ALL, 1);
26 }
27 void target_music_use()
28 {
29         if(!activator)
30                 return;
31         msg_entity = activator;
32         target_music_sendto(MSG_ONE, 1);
33 }
34 void spawnfunc_target_music()
35 {
36         self.use = target_music_use;
37         self.reset = target_music_reset;
38         if(!self.volume)
39                 self.volume = 1;
40         if(self.targetname == "")
41                 target_music_sendto(MSG_INIT, 1);
42         else
43                 target_music_sendto(MSG_INIT, 0);
44 }
45 // values:
46 //   volume
47 //   noise
48 //   targetname
49 //   fade_time
50 // spawnflags:
51 //   1 = START_OFF
52 // when triggered, it is disabled/enabled for everyone
53 float trigger_music_SendEntity(entity to, float sf)
54 {
55         WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
56         sf &~= 0x80;
57         if(self.cnt)
58                 sf |= 0x80;
59         WriteByte(MSG_ENTITY, sf);
60         if(sf & 4)
61         {
62                 WriteCoord(MSG_ENTITY, self.origin_x);
63                 WriteCoord(MSG_ENTITY, self.origin_y);
64                 WriteCoord(MSG_ENTITY, self.origin_z);
65         }
66         if(sf & 1)
67         {
68                 if(self.model != "null")
69                 {
70                         WriteShort(MSG_ENTITY, self.modelindex);
71                         WriteCoord(MSG_ENTITY, self.mins_x);
72                         WriteCoord(MSG_ENTITY, self.mins_y);
73                         WriteCoord(MSG_ENTITY, self.mins_z);
74                         WriteCoord(MSG_ENTITY, self.maxs_x);
75                         WriteCoord(MSG_ENTITY, self.maxs_y);
76                         WriteCoord(MSG_ENTITY, self.maxs_z);
77                 }
78                 else
79                 {
80                         WriteShort(MSG_ENTITY, 0);
81                         WriteCoord(MSG_ENTITY, self.maxs_x);
82                         WriteCoord(MSG_ENTITY, self.maxs_y);
83                         WriteCoord(MSG_ENTITY, self.maxs_z);
84                 }
85                 WriteByte(MSG_ENTITY, self.volume * 255.0);
86                 WriteByte(MSG_ENTITY, self.fade_time * 16.0);
87                 WriteByte(MSG_ENTITY, self.fade_rate * 16.0);
88                 WriteString(MSG_ENTITY, self.noise);
89         }
90         return 1;
91 }
92 void trigger_music_reset()
93 {
94         self.cnt = !(self.spawnflags & 1);
95         self.SendFlags |= 0x80;
96 }
97 void trigger_music_use()
98 {
99         self.cnt = !self.cnt;
100         self.SendFlags |= 0x80;
101 }
102 void spawnfunc_trigger_music()
103 {
104         if(self.model != "")
105                 setmodel(self, self.model);
106         if(!self.volume)
107                 self.volume = 1;
108         if(!self.modelindex)
109         {
110                 setorigin(self, self.origin + self.mins);
111                 setsize(self, '0 0 0', self.maxs - self.mins);
112         }
113         trigger_music_reset();
114
115         self.use = trigger_music_use;
116         self.reset = trigger_music_reset;
117
118         Net_LinkEntity(self, FALSE, 0, trigger_music_SendEntity);
119 }