Xonotic
voicescript.qc
Go to the documentation of this file.
1 #include "voicescript.qh"
2 #ifdef SVQC
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
7 
8 void target_voicescript_clear(entity pl)
9 {
10  pl.voicescript = NULL;
11 }
12 
13 void target_voicescript_use(entity this, entity actor, entity trigger)
14 {
15  if(actor.voicescript != this)
16  {
17  actor.voicescript = this;
18  actor.voicescript_index = 0;
19  actor.voicescript_nextthink = time + this.delay;
20  }
21 }
22 
23 void target_voicescript_next(entity pl)
24 {
25  entity vs;
26  float i, n, dt;
27 
28  vs = pl.voicescript;
29  if(!vs)
30  return;
31  if(vs.message == "")
32  return;
33  if (!IS_PLAYER(pl))
34  return;
35  if(game_stopped)
36  return;
37 
38  if(time >= pl.voicescript_voiceend)
39  {
40  if(time >= pl.voicescript_nextthink)
41  {
42  // get the next voice...
43  n = tokenize_console(vs.message);
44 
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;
49  else
50  i = -1;
51 
52  if(i >= 0)
53  {
54  play2(pl, strcat(vs.netname, "/", argv(i), ".wav"));
55  dt = stof(argv(i + 1));
56  if(dt >= 0)
57  {
58  pl.voicescript_voiceend = time + dt;
59  pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random());
60  }
61  else
62  {
63  pl.voicescript_voiceend = time - dt;
64  pl.voicescript_nextthink = pl.voicescript_voiceend;
65  }
66 
67  pl.voicescript_index += 1;
68  }
69  else
70  {
71  pl.voicescript = NULL; // stop trying then
72  }
73  }
74  }
75 }
76 
77 spawnfunc(target_voicescript)
78 {
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
86 
87  float i, n;
88  this.use = target_voicescript_use;
89 
90  n = tokenize_console(this.message);
91  this.cnt = n / 2;
92  for(i = 0; i+1 < n; i += 2)
93  {
94  if(argv(i) == "*")
95  {
96  this.cnt = i / 2;
97  ++i;
98  }
99  precache_sound(strcat(this.netname, "/", argv(i), ".wav"));
100  }
101 }
102 #endif
entity() spawn
string netname
Definition: powerups.qc:20
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float cnt
Definition: powerups.qc:24
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float delay
Definition: subs.qh:38
string message
Definition: powerups.qc:19
#define NULL
Definition: post.qh:17
#define tokenize_console
Definition: dpextensions.qh:24
#define use
Definition: csprogsdefs.qh:50
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9