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) == "*")
11 var .string sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1));
12 if(GetPlayerSoundSampleField_notFound)
14 else if(activator.(sample) == "")
18 tokenize_console(activator.(sample));
22 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
24 snd = strcat(argv(0), ".wav"); // randomization
29 msg_entity = activator;
30 soundto(MSG_ONE, self, CH_TRIGGER, snd, VOL_BASE * self.volume, self.atten);
32 void target_speaker_use_on()
35 if(substring(self.noise, 0, 1) == "*")
37 var .string sample = GetVoiceMessageSampleField(substring(self.noise, 1, -1));
38 if(GetPlayerSoundSampleField_notFound)
40 else if(activator.(sample) == "")
44 tokenize_console(activator.(sample));
48 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
50 snd = strcat(argv(0), ".wav"); // randomization
55 _sound(self, CH_TRIGGER_SINGLE, snd, VOL_BASE * self.volume, self.atten);
56 if(self.spawnflags & 3)
57 self.use = target_speaker_use_off;
59 void target_speaker_use_off()
61 sound(self, CH_TRIGGER_SINGLE, SND_Null, VOL_BASE * self.volume, self.atten);
62 self.use = target_speaker_use_on;
64 void target_speaker_reset(entity this)
66 if(this.spawnflags & 1) // LOOPED_ON
68 if(this.use == target_speaker_use_on)
69 target_speaker_use_on();
71 else if(this.spawnflags & 2)
73 if(this.use == target_speaker_use_off)
74 target_speaker_use_off();
78 spawnfunc(target_speaker)
80 // TODO: "*" prefix to sound file name
81 // TODO: wait and random (just, HOW? random is not a field)
83 precache_sound (self.noise);
85 if(!self.atten && !(self.spawnflags & 4))
88 self.atten = ATTEN_NORM;
90 self.atten = ATTEN_STATIC;
92 else if(self.atten < 0)
100 if(self.spawnflags & 8) // ACTIVATOR
101 self.use = target_speaker_use_activator;
102 else if(self.spawnflags & 1) // LOOPED_ON
104 target_speaker_use_on();
105 self.reset = target_speaker_reset;
107 else if(self.spawnflags & 2) // LOOPED_OFF
109 self.use = target_speaker_use_on;
110 self.reset = target_speaker_reset;
113 self.use = target_speaker_use_on;
115 else if(self.spawnflags & 1) // LOOPED_ON
117 ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten);
120 else if(self.spawnflags & 2) // LOOPED_OFF
122 objerror("This sound entity can never be activated");
126 // Quake/Nexuiz fallback
127 ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten);