2 // TODO add a way to do looped sounds with sound(); then complete this entity
3 void target_speaker_use_off();
4 void target_speaker_use_activator()
6 if (!IS_REAL_CLIENT(activator))
9 if(substring(self.noise, 0, 1) == "*")
12 sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1));
13 if(GetPlayerSoundSampleField_notFound)
14 snd = "misc/null.wav";
15 else if(activator.sample == "")
16 snd = "misc/null.wav";
19 tokenize_console(activator.sample);
23 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
25 snd = strcat(argv(0), ".wav"); // randomization
30 msg_entity = activator;
31 soundto(MSG_ONE, self, CH_TRIGGER, snd, VOL_BASE * self.volume, self.atten);
33 void target_speaker_use_on()
36 if(substring(self.noise, 0, 1) == "*")
39 sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1));
40 if(GetPlayerSoundSampleField_notFound)
41 snd = "misc/null.wav";
42 else if(activator.sample == "")
43 snd = "misc/null.wav";
46 tokenize_console(activator.sample);
50 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
52 snd = strcat(argv(0), ".wav"); // randomization
57 sound(self, CH_TRIGGER_SINGLE, snd, VOL_BASE * self.volume, self.atten);
58 if(self.spawnflags & 3)
59 self.use = target_speaker_use_off;
61 void target_speaker_use_off()
63 sound(self, CH_TRIGGER_SINGLE, "misc/null.wav", VOL_BASE * self.volume, self.atten);
64 self.use = target_speaker_use_on;
66 void target_speaker_reset()
68 if(self.spawnflags & 1) // LOOPED_ON
70 if(self.use == target_speaker_use_on)
71 target_speaker_use_on();
73 else if(self.spawnflags & 2)
75 if(self.use == target_speaker_use_off)
76 target_speaker_use_off();
80 void spawnfunc_target_speaker()
82 // TODO: "*" prefix to sound file name
83 // TODO: wait and random (just, HOW? random is not a field)
85 precache_sound (self.noise);
87 if(!self.atten && !(self.spawnflags & 4))
90 self.atten = ATTEN_NORM;
92 self.atten = ATTEN_STATIC;
94 else if(self.atten < 0)
102 if(self.spawnflags & 8) // ACTIVATOR
103 self.use = target_speaker_use_activator;
104 else if(self.spawnflags & 1) // LOOPED_ON
106 target_speaker_use_on();
107 self.reset = target_speaker_reset;
109 else if(self.spawnflags & 2) // LOOPED_OFF
111 self.use = target_speaker_use_on;
112 self.reset = target_speaker_reset;
115 self.use = target_speaker_use_on;
117 else if(self.spawnflags & 1) // LOOPED_ON
119 ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten);
122 else if(self.spawnflags & 2) // LOOPED_OFF
124 objerror("This sound entity can never be activated");
128 // Quake/Nexuiz fallback
129 ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten);