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))
10 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) == "")
19 tokenize_console(actor.(sample));
23 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
25 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) == "*")
38 var .string sample = GetVoiceMessageSampleField(substring(this.noise, 1, -1));
39 if(GetPlayerSoundSampleField_notFound)
41 else if(actor.(sample) == "")
45 tokenize_console(actor.(sample));
49 snd = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
51 snd = strcat(argv(0), ".wav"); // randomization
56 _sound(this, CH_TRIGGER_SINGLE, snd, VOL_BASE * this.volume, this.atten);
57 if(this.spawnflags & (SPEAKER_LOOPED_ON + SPEAKER_LOOPED_OFF))
58 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 & SPEAKER_LOOPED_ON)
69 if(this.use == target_speaker_use_on)
70 target_speaker_use_on(this, NULL, NULL);
72 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
74 if(this.use == target_speaker_use_off)
75 target_speaker_use_off(this, NULL, NULL);
79 spawnfunc(target_speaker)
81 // TODO: "*" prefix to sound file name
82 // TODO: wait and random (just, HOW? random is not a field)
84 precache_sound (this.noise);
86 if(!this.atten && (this.spawnflags & SPEAKER_GLOBAL))
88 LOG_WARN("target_speaker uses legacy spawnflag GLOBAL (BIT(2)), please set atten to -1 instead");
95 this.atten = ATTEN_NORM;
97 this.atten = ATTEN_STATIC;
99 else if(this.atten < 0)
107 if(this.spawnflags & SPEAKER_ACTIVATOR)
108 this.use = target_speaker_use_activator;
109 else if(this.spawnflags & SPEAKER_LOOPED_ON)
111 target_speaker_use_on(this, NULL, NULL);
112 this.reset = target_speaker_reset;
114 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
116 this.use = target_speaker_use_on;
117 this.reset = target_speaker_reset;
120 this.use = target_speaker_use_on;
122 else if(this.spawnflags & SPEAKER_LOOPED_ON)
124 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);
127 else if(this.spawnflags & SPEAKER_LOOPED_OFF)
129 objerror(this, "This sound entity can never be activated");
133 // Quake/Nexuiz fallback
134 ambientsound (this.origin, this.noise, VOL_BASE * this.volume, this.atten);