Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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
9{
10 pl.voicescript = NULL;
11}
12
13void target_voicescript_use(entity this, entity actor, entity trigger)
14{
15 if(this.active != ACTIVE_ACTIVE)
16 return;
17 if(actor.voicescript != this)
18 {
19 actor.voicescript = this;
20 actor.voicescript_index = 0;
21 actor.voicescript_nextthink = time + this.delay;
22 }
23}
24
26{
27 entity vs;
28 float i, n, dt;
29
30 vs = pl.voicescript;
31 if(!vs)
32 return;
33 if(vs.active != ACTIVE_ACTIVE)
34 {
35 pl.voicescript = NULL;
36 return;
37 }
38 if(vs.message == "")
39 return;
40 if (!IS_PLAYER(pl))
41 return;
42 if(game_stopped)
43 return;
44
45 if(time >= pl.voicescript_voiceend)
46 {
47 if(time >= pl.voicescript_nextthink)
48 {
49 // get the next voice...
50 n = tokenize_console(vs.message);
51
52 if(pl.voicescript_index < vs.cnt)
53 i = pl.voicescript_index * 2;
54 else if(n > vs.cnt * 2)
55 i = ((pl.voicescript_index - vs.cnt) % ((n - vs.cnt * 2 - 1) / 2)) * 2 + vs.cnt * 2 + 1;
56 else
57 i = -1;
58
59 if(i >= 0)
60 {
61 play2(pl, strcat(vs.netname, "/", argv(i), ".wav"));
62 dt = stof(argv(i + 1));
63 if(dt >= 0)
64 {
65 pl.voicescript_voiceend = time + dt;
66 pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random());
67 }
68 else
69 {
70 pl.voicescript_voiceend = time - dt;
71 pl.voicescript_nextthink = pl.voicescript_voiceend;
72 }
73
74 pl.voicescript_index += 1;
75 }
76 else
77 {
78 pl.voicescript = NULL; // stop trying then
79 }
80 }
81 }
82}
83
88
89spawnfunc(target_voicescript)
90{
91 // netname: directory of the sound files
92 // message: list of "sound file" duration "sound file" duration, a *, and again a list
93 // foo1 4.1 foo2 4.0 foo3 -3.1 * fool1 1.1 fool2 7.1 fool3 9.1 fool4 3.7
94 // Here, a - in front of the duration means that no delay is to be
95 // added after this message
96 // wait: average time between messages
97 // delay: initial delay before the first message
98
99 float i, n;
101 this.active = ACTIVE_ACTIVE;
102 this.reset = target_voicescript_reset;
103
104 n = tokenize_console(this.message);
105 this.cnt = n / 2;
106 for(i = 0; i+1 < n; i += 2)
107 {
108 if(argv(i) == "*")
109 {
110 this.cnt = i / 2;
111 ++i;
112 }
113 precache_sound(strcat(this.netname, "/", argv(i), ".wav"));
114 }
115}
116#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
string netname
Definition powerups.qc:20
float cnt
Definition powerups.qc:24
string message
Definition powerups.qc:19
float delay
Definition items.qc:17
#define IS_PLAYER(s)
Definition player.qh:243
float game_stopped
Definition stats.qh:81
float time
#define use
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
#define tokenize_console
float stof(string val,...)
float random(void)
string precache_sound(string sample)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
void play2(entity e, string filename)
Definition all.qc:116
#define spawnfunc(id)
Definition spawnfunc.qh:96
entity voicescript
Definition voicescript.qc:3
float voicescript_voiceend
Definition voicescript.qc:6
void target_voicescript_next(entity pl)
void target_voicescript_clear(entity pl)
Definition voicescript.qc:8
void target_voicescript_use(entity this, entity actor, entity trigger)
void target_voicescript_reset(entity this)
float voicescript_index
Definition voicescript.qc:4
float voicescript_nextthink
Definition voicescript.qc:5