1 #include "voicescript.qh"
3 .entity voicescript; // attached voice script
4 .float voicescript_index; // index of next voice, or -1 to use the randomized ones
5 .float voicescript_nextthink; // time to play next voice
6 .float voicescript_voiceend; // time when this voice ends
8 void target_voicescript_clear(entity pl)
10 pl.voicescript = NULL;
13 void target_voicescript_use(entity this, entity actor, entity trigger)
15 if(actor.voicescript != this)
17 actor.voicescript = this;
18 actor.voicescript_index = 0;
19 actor.voicescript_nextthink = time + this.delay;
23 void target_voicescript_next(entity pl)
38 if(time >= pl.voicescript_voiceend)
40 if(time >= pl.voicescript_nextthink)
42 // get the next voice...
43 n = tokenize_console(vs.message);
45 if(pl.voicescript_index < vs.cnt)
46 i = pl.voicescript_index * 2;
47 else if(n > vs.cnt * 2)
48 i = ((pl.voicescript_index - vs.cnt) % ((n - vs.cnt * 2 - 1) / 2)) * 2 + vs.cnt * 2 + 1;
54 play2(pl, strcat(vs.netname, "/", argv(i), ".wav"));
55 dt = stof(argv(i + 1));
58 pl.voicescript_voiceend = time + dt;
59 pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random());
63 pl.voicescript_voiceend = time - dt;
64 pl.voicescript_nextthink = pl.voicescript_voiceend;
67 pl.voicescript_index += 1;
71 pl.voicescript = NULL; // stop trying then
77 spawnfunc(target_voicescript)
79 // netname: directory of the sound files
80 // message: list of "sound file" duration "sound file" duration, a *, and again a list
81 // foo1 4.1 foo2 4.0 foo3 -3.1 * fool1 1.1 fool2 7.1 fool3 9.1 fool4 3.7
82 // Here, a - in front of the duration means that no delay is to be
83 // added after this message
84 // wait: average time between messages
85 // delay: initial delay before the first message
88 this.use = target_voicescript_use;
90 n = tokenize_console(this.message);
92 for(i = 0; i+1 < n; i += 2)
99 precache_sound(strcat(this.netname, "/", argv(i), ".wav"));