2 .entity voicescript; // attached voice script
3 .float voicescript_index; // index of next voice, or -1 to use the randomized ones
4 .float voicescript_nextthink; // time to play next voice
5 .float voicescript_voiceend; // time when this voice ends
7 void target_voicescript_clear(entity pl)
9 pl.voicescript = world;
12 void target_voicescript_use()
14 if(activator.voicescript != self)
16 activator.voicescript = self;
17 activator.voicescript_index = 0;
18 activator.voicescript_nextthink = time + self.delay;
22 void target_voicescript_next(entity pl)
37 if(time >= pl.voicescript_voiceend)
39 if(time >= pl.voicescript_nextthink)
41 // get the next voice...
42 n = tokenize_console(vs.message);
44 if(pl.voicescript_index < vs.cnt)
45 i = pl.voicescript_index * 2;
46 else if(n > vs.cnt * 2)
47 i = ((pl.voicescript_index - vs.cnt) % ((n - vs.cnt * 2 - 1) / 2)) * 2 + vs.cnt * 2 + 1;
53 play2(pl, strcat(vs.netname, "/", argv(i), ".wav"));
54 dt = stof(argv(i + 1));
57 pl.voicescript_voiceend = time + dt;
58 pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random());
62 pl.voicescript_voiceend = time - dt;
63 pl.voicescript_nextthink = pl.voicescript_voiceend;
66 pl.voicescript_index += 1;
70 pl.voicescript = world; // stop trying then
76 spawnfunc(target_voicescript)
78 // netname: directory of the sound files
79 // message: list of "sound file" duration "sound file" duration, a *, and again a list
80 // foo1 4.1 foo2 4.0 foo3 -3.1 * fool1 1.1 fool2 7.1 fool3 9.1 fool4 3.7
81 // Here, a - in front of the duration means that no delay is to be
82 // added after this message
83 // wait: average time between messages
84 // delay: initial delay before the first message
87 self.use = target_voicescript_use;
89 n = tokenize_console(self.message);
91 for(i = 0; i+1 < n; i += 2)
98 precache_sound(strcat(self.netname, "/", argv(i), ".wav"));