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