3 // TODO add a way to do looped sounds with sound(); then complete this entity
4 void target_speaker_use_off(entity this, entity actor, entity trigger);
5 void target_speaker_use_activator(entity this, entity actor, entity trigger)
7 if (!IS_REAL_CLIENT(actor)) {
11 if (substring(this.noise, 0, 1) == "*") {
12 var.string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
13 if (GetPlayerSoundSampleField_notFound) {
15 } else if (actor.(sample) == "") {
18 tokenize_console(actor.(sample));
22 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
24 snd = strcat(argv(0), ".wav"); // randomization
31 soundto(MSG_ONE, this, CH_TRIGGER, snd, VOL_BASE * this.volume, this.atten);
33 void target_speaker_use_on(entity this, entity actor, entity trigger)
36 if (substring(this.noise, 0, 1) == "*") {
37 var.string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
38 if (GetPlayerSoundSampleField_notFound) {
40 } else if (actor.(sample) == "") {
43 tokenize_console(actor.(sample));
47 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
49 snd = strcat(argv(0), ".wav"); // randomization
55 _sound(this, CH_TRIGGER_SINGLE, snd, VOL_BASE * this.volume, this.atten);
56 if (this.spawnflags & 3) {
57 this.use = target_speaker_use_off;
60 void target_speaker_use_off(entity this, entity actor, entity trigger)
62 sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASE * this.volume, this.atten);
63 this.use = target_speaker_use_on;
65 void target_speaker_reset(entity this)
67 if (this.spawnflags & 1) { // LOOPED_ON
68 if (this.use == target_speaker_use_on) {
69 target_speaker_use_on(this, NULL, NULL);
71 } else if (this.spawnflags & 2) {
72 if (this.use == target_speaker_use_off) {
73 target_speaker_use_off(this, NULL, NULL);
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(this.noise);
86 if (!this.atten && !(this.spawnflags & 4)) {
88 this.atten = ATTEN_NORM;
90 this.atten = ATTEN_STATIC;
92 } else if (this.atten < 0) {
101 if (this.spawnflags & 8) { // ACTIVATOR
102 this.use = target_speaker_use_activator;
103 } else if (this.spawnflags & 1) { // LOOPED_ON
104 target_speaker_use_on(this, NULL, NULL);
105 this.reset = target_speaker_reset;
106 } else if (this.spawnflags & 2) { // LOOPED_OFF
107 this.use = target_speaker_use_on;
108 this.reset = target_speaker_reset;
110 this.use = target_speaker_use_on;
112 } else if (this.spawnflags & 1) { // LOOPED_ON
113 ambientsound(this.origin, this.noise, VOL_BASE * this.volume, this.atten);
115 } else if (this.spawnflags & 2) { // LOOPED_OFF
116 objerror(this, "This sound entity can never be activated");
118 // Quake/Nexuiz fallback
119 ambientsound(this.origin, this.noise, VOL_BASE * this.volume, this.atten);