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