]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_player.qc
Player sounds: cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
1 #include "cl_player.qh"
2
3 #include "bot/bot.qh"
4 #include "cheats.qh"
5 #include "g_damage.qh"
6 #include "g_subs.qh"
7 #include "miscfunctions.qh"
8 #include "portals.qh"
9 #include "teamplay.qh"
10 #include "weapons/throwing.qh"
11 #include "command/common.qh"
12 #include "../common/animdecide.qh"
13 #include "../common/csqcmodel_settings.qh"
14 #include "../common/deathtypes/all.qh"
15 #include "../common/triggers/subs.qh"
16 #include "../common/playerstats.qh"
17 #include "../lib/csqcmodel/sv_model.qh"
18
19 #include "../common/minigames/sv_minigames.qh"
20
21 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
22 #include "../common/triggers/include.qh"
23
24 #include "weapons/weaponstats.qh"
25
26 #include "../common/animdecide.qh"
27
28 void Drop_Special_Items(entity player)
29 {
30         // called when the player has become stuck or frozen
31         // so objective items aren't stuck with the player
32
33         MUTATOR_CALLHOOK(DropSpecialItems, player);
34 }
35
36 void CopyBody_Think()
37 {SELFPARAM();
38         if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
39         {
40                 self.CopyBody_think();
41                 if(wasfreed(self))
42                         return;
43                 self.CopyBody_nextthink = self.nextthink;
44                 self.CopyBody_think = self.think;
45                 self.think = CopyBody_Think;
46         }
47         CSQCMODEL_AUTOUPDATE(self);
48         self.nextthink = time;
49 }
50 void CopyBody(float keepvelocity)
51 {SELFPARAM();
52         if (self.effects & EF_NODRAW)
53                 return;
54         setself(new(body));
55         self.enemy = this;
56         self.lip = this.lip;
57         self.colormap = this.colormap;
58         self.iscreature = this.iscreature;
59         self.teleportable = this.teleportable;
60         self.damagedbycontents = this.damagedbycontents;
61         self.angles = this.angles;
62         self.v_angle = this.v_angle;
63         self.avelocity = this.avelocity;
64         self.damageforcescale = this.damageforcescale;
65         self.effects = this.effects;
66         self.glowmod = this.glowmod;
67         self.event_damage = this.event_damage;
68         self.anim_state = this.anim_state;
69         self.anim_time = this.anim_time;
70         self.anim_lower_action = this.anim_lower_action;
71         self.anim_lower_time = this.anim_lower_time;
72         self.anim_upper_action = this.anim_upper_action;
73         self.anim_upper_time = this.anim_upper_time;
74         self.anim_implicit_state = this.anim_implicit_state;
75         self.anim_implicit_time = this.anim_implicit_time;
76         self.anim_lower_implicit_action = this.anim_lower_implicit_action;
77         self.anim_lower_implicit_time = this.anim_lower_implicit_time;
78         self.anim_upper_implicit_action = this.anim_upper_implicit_action;
79         self.anim_upper_implicit_time = this.anim_upper_implicit_time;
80         self.dphitcontentsmask = this.dphitcontentsmask;
81         self.death_time = this.death_time;
82         self.pain_finished = this.pain_finished;
83         self.health = this.health;
84         self.armorvalue = this.armorvalue;
85         self.armortype = this.armortype;
86         self.model = this.model;
87         self.modelindex = this.modelindex;
88         self.skin = this.skin;
89         self.species = this.species;
90         self.movetype = this.movetype;
91         self.solid = this.solid;
92         self.ballistics_density = this.ballistics_density;
93         self.takedamage = this.takedamage;
94         self.customizeentityforclient = this.customizeentityforclient;
95         self.uncustomizeentityforclient = this.uncustomizeentityforclient;
96         self.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
97         if (keepvelocity == 1)
98                 self.velocity = this.velocity;
99         self.oldvelocity = self.velocity;
100         self.alpha = this.alpha;
101         self.fade_time = this.fade_time;
102         self.fade_rate = this.fade_rate;
103         //self.weapon = this.weapon;
104         setorigin(self, this.origin);
105         setsize(self, this.mins, this.maxs);
106         self.prevorigin = this.origin;
107         self.reset = SUB_Remove;
108
109         Drag_MoveDrag(this, self);
110
111         if(self.colormap <= maxclients && self.colormap > 0)
112                 self.colormap = 1024 + this.clientcolors;
113
114         CSQCMODEL_AUTOINIT(self);
115         self.CopyBody_nextthink = this.nextthink;
116         self.CopyBody_think = this.think;
117         self.nextthink = time;
118         self.think = CopyBody_Think;
119         // "bake" the current animation frame for clones (they don't get clientside animation)
120         animdecide_load_if_needed(self);
121         animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
122
123         setself(this);
124 }
125
126 void player_setupanimsformodel()
127 {SELFPARAM();
128         // load animation info
129         animdecide_load_if_needed(self);
130         animdecide_setstate(self, 0, false);
131 }
132
133 void player_anim ()
134 {SELFPARAM();
135         int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
136         if(self.deadflag) {
137                 if (!deadbits) {
138                         // Decide on which death animation to use.
139                         if(random() < 0.5)
140                                 deadbits = ANIMSTATE_DEAD1;
141                         else
142                                 deadbits = ANIMSTATE_DEAD2;
143                 }
144         } else {
145                 // Clear a previous death animation.
146                 deadbits = 0;
147         }
148         int animbits = deadbits;
149         if(self.frozen)
150                 animbits |= ANIMSTATE_FROZEN;
151         if(self.movetype == MOVETYPE_FOLLOW)
152                 animbits |= ANIMSTATE_FOLLOW;
153         if(self.crouch)
154                 animbits |= ANIMSTATE_DUCK;
155         animdecide_setstate(self, animbits, false);
156         animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
157
158         .entity weaponentity = weaponentities[0]; // TODO: unhardcode
159         {
160                 if (self.(weaponentity))
161                 {
162                         updateanim(self.(weaponentity));
163                         if (!self.(weaponentity).animstate_override)
164                                 setanim(self.(weaponentity), self.(weaponentity).anim_idle, true, false, false);
165                 }
166         }
167 }
168
169 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
170 {SELFPARAM();
171         float take, save;
172         vector v;
173         Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
174
175         // damage resistance (ignore most of the damage from a bullet or similar)
176         damage = max(damage - 5, 1);
177
178         v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
179         take = v.x;
180         save = v.y;
181
182         if(sound_allowed(MSG_BROADCAST, attacker))
183         {
184                 if (save > 10)
185                         sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
186                 else if (take > 30)
187                         sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
188                 else if (take > 10)
189                         sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
190         }
191
192         if (take > 50)
193                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
194         if (take > 100)
195                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
196
197         self.armorvalue = self.armorvalue - save;
198         self.health = self.health - take;
199         // pause regeneration for 5 seconds
200         self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
201
202         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
203         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
204         self.dmg_inflictor = inflictor;
205
206         if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
207         {
208                 // don't use any animations as a gib
209                 self.frame = 0;
210                 // view just above the floor
211                 self.view_ofs = '0 0 4';
212
213                 Violence_GibSplash(self, 1, 1, attacker);
214                 self.alpha = -1;
215                 self.solid = SOLID_NOT; // restore later
216                 self.takedamage = DAMAGE_NO; // restore later
217                 self.damagedbycontents = false;
218         }
219 }
220
221 void calculate_player_respawn_time()
222 {SELFPARAM();
223         if(g_ca)
224                 return;
225
226         float gametype_setting_tmp;
227         float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
228         float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
229         float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
230         float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
231         float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
232         float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
233
234         float pcount = 1;  // Include myself whether or not team is already set right and I'm a "player".
235         entity pl;
236         if (teamplay)
237         {
238                 FOR_EACH_PLAYER(pl)
239                         if (pl != self)
240                                 if (pl.team == self.team)
241                                         ++pcount;
242                 if (sdelay_small_count == 0)
243                         sdelay_small_count = 1;
244                 if (sdelay_large_count == 0)
245                         sdelay_large_count = 1;
246         }
247         else
248         {
249                 FOR_EACH_PLAYER(pl)
250                         if (pl != self)
251                                 ++pcount;
252                 if (sdelay_small_count == 0)
253                 {
254                         if (g_cts)
255                         {
256                                 // Players play independently. No point in requiring enemies.
257                                 sdelay_small_count = 1;
258                         }
259                         else
260                         {
261                                 // Players play AGAINST each other. Enemies required.
262                                 sdelay_small_count = 2;
263                         }
264                 }
265                 if (sdelay_large_count == 0)
266                 {
267                         if (g_cts)
268                         {
269                                 // Players play independently. No point in requiring enemies.
270                                 sdelay_large_count = 1;
271                         }
272                         else
273                         {
274                                 // Players play AGAINST each other. Enemies required.
275                                 sdelay_large_count = 2;
276                         }
277                 }
278         }
279
280         float sdelay;
281
282         if (pcount <= sdelay_small_count)
283                 sdelay = sdelay_small;
284         else if (pcount >= sdelay_large_count)
285                 sdelay = sdelay_large;
286         else  // NOTE: this case implies sdelay_large_count > sdelay_small_count.
287                 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
288
289         if(waves)
290                 self.respawn_time = ceil((time + sdelay) / waves) * waves;
291         else
292                 self.respawn_time = time + sdelay;
293
294         if(sdelay < sdelay_max)
295                 self.respawn_time_max = time + sdelay_max;
296         else
297                 self.respawn_time_max = self.respawn_time;
298
299         if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
300                 self.respawn_countdown = 10; // first number to count down from is 10
301         else
302                 self.respawn_countdown = -1; // do not count down
303
304         if(autocvar_g_forced_respawn)
305                 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
306 }
307
308 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
309 {SELFPARAM();
310         float take, save, dh, da;
311         int j;
312         vector v;
313         float valid_damage_for_weaponstats;
314         float excess;
315
316         dh = max(self.health, 0);
317         da = max(self.armorvalue, 0);
318
319         if(!DEATH_ISSPECIAL(deathtype))
320         {
321                 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
322                 if(self != attacker)
323                         damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
324         }
325
326         if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
327         {
328                 // tuba causes blood to come out of the ears
329                 vector ear1, ear2;
330                 vector d;
331                 float f;
332                 ear1 = self.origin;
333                 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
334                 ear2 = ear1;
335                 makevectors(self.angles);
336                 ear1 += v_right * -10;
337                 ear2 += v_right * +10;
338                 d = inflictor.origin - self.origin;
339                 if (d)
340                         f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
341                 else
342                         f = 0;  // Assum ecenter.
343                 force = v_right * vlen(force);
344                 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
345                 Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
346                 if(f > 0)
347                 {
348                         hitloc = ear1;
349                         force = force * -1;
350                 }
351                 else
352                 {
353                         hitloc = ear2;
354                         // force is already good
355                 }
356         }
357         else
358                 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
359
360
361         v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
362         take = v.x;
363         save = v.y;
364
365         if(attacker == self)
366         {
367                 // don't reset pushltime for self damage as it may be an attempt to
368                 // escape a lava pit or similar
369                 //self.pushltime = 0;
370                 self.istypefrag = 0;
371         }
372         else if(IS_PLAYER(attacker))
373         {
374                 self.pusher = attacker;
375                 self.pushltime = time + autocvar_g_maxpushtime;
376                 self.istypefrag = self.BUTTON_CHAT;
377         }
378         else if(time < self.pushltime)
379         {
380                 attacker = self.pusher;
381                 self.pushltime = max(self.pushltime, time + 0.6);
382         }
383         else
384         {
385                 self.pushltime = 0;
386                 self.istypefrag = 0;
387         }
388
389         frag_damage = damage;
390         MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, self, force, take, save);
391         take = bound(0, damage_take, self.health);
392         save = bound(0, damage_save, self.armorvalue);
393         excess = max(0, damage - take - save);
394
395         if(sound_allowed(MSG_BROADCAST, attacker))
396         {
397                 if (save > 10)
398                         sound (self, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
399                 else if (take > 30)
400                         sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
401                 else if (take > 10)
402                         sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
403         }
404
405         if (take > 50)
406                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
407         if (take > 100)
408                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
409
410         if (time >= self.spawnshieldtime)
411         {
412                 if (!(self.flags & FL_GODMODE))
413                 {
414                         self.armorvalue = self.armorvalue - save;
415                         self.health = self.health - take;
416                         // pause regeneration for 5 seconds
417                         if(take)
418                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
419
420                         if (time > self.pain_finished)          //Don't switch pain sequences like crazy
421                         {
422                                 self.pain_finished = time + 0.5;        //Supajoe
423
424                                 if(autocvar_sv_gentle < 1) {
425                                         if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
426                                         {
427                                                 if (!self.animstate_override)
428                                                 {
429                                                         if (random() > 0.5)
430                                                                 animdecide_setaction(self, ANIMACTION_PAIN1, true);
431                                                         else
432                                                                 animdecide_setaction(self, ANIMACTION_PAIN2, true);
433                                                 }
434                                         }
435
436                                         if(sound_allowed(MSG_BROADCAST, attacker))
437                                         if((self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || attacker != self) // WEAPONTODO: create separate limit for pain notification with laser
438                                         if(self.health > 1)
439                                         // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
440                                         {
441                                                 if(deathtype == DEATH_FALL.m_id)
442                                                         PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
443                                                 else if(self.health > 75) // TODO make a "gentle" version?
444                                                         PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
445                                                 else if(self.health > 50)
446                                                         PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
447                                                 else if(self.health > 25)
448                                                         PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
449                                                 else
450                                                         PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
451                                         }
452                                 }
453                         }
454
455                         // throw off bot aim temporarily
456                         float shake;
457                         if(IS_BOT_CLIENT(self) && self.health >= 1)
458                         {
459                                 shake = damage * 5 / (bound(0,skill,100) + 1);
460                                 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
461                                 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
462                                 self.v_angle_x = bound(-90, self.v_angle.x, 90);
463                         }
464                 }
465                 else
466                         self.max_armorvalue += (save + take);
467         }
468         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
469         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
470         self.dmg_inflictor = inflictor;
471
472         if (self != attacker) {
473                 float realdmg = damage - excess;
474                 if (IS_PLAYER(attacker)) {
475                         PlayerScore_Add(attacker, SP_DMG, realdmg);
476                 }
477                 if (IS_PLAYER(self)) {
478                         PlayerScore_Add(self, SP_DMGTAKEN, realdmg);
479                 }
480         }
481         
482         bool abot = (IS_BOT_CLIENT(attacker));
483         bool vbot = (IS_BOT_CLIENT(self));
484
485         valid_damage_for_weaponstats = 0;
486         Weapon awep = WEP_Null;
487
488         if(vbot || IS_REAL_CLIENT(self))
489         if(abot || IS_REAL_CLIENT(attacker))
490         if(attacker && self != attacker)
491         if(DIFF_TEAM(self, attacker))
492         {
493                 if(DEATH_ISSPECIAL(deathtype))
494                         awep = get_weaponinfo(attacker.weapon);
495                 else
496                         awep = DEATH_WEAPONOF(deathtype);
497                 valid_damage_for_weaponstats = 1;
498         }
499
500         if(valid_damage_for_weaponstats)
501         {
502                 dh = dh - max(self.health, 0);
503                 da = da - max(self.armorvalue, 0);
504                 WeaponStats_LogDamage(awep.m_id, abot, self.weapon, vbot, dh + da);
505                 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc, deathtype);
506         }
507
508         if (self.health < 1)
509         {
510                 float defer_ClientKill_Now_TeamChange;
511                 defer_ClientKill_Now_TeamChange = false;
512
513                 if(self.alivetime)
514                 {
515                         PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
516                         self.alivetime = 0;
517                 }
518
519                 if(valid_damage_for_weaponstats)
520                         WeaponStats_LogKill(awep.m_id, abot, self.weapon, vbot);
521
522                 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
523                 if(sound_allowed(MSG_BROADCAST, attacker))
524                 {
525                         if(deathtype == DEATH_DROWN.m_id)
526                                 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
527                         else
528                                 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
529                 }
530
531                 // get rid of kill indicator
532                 if(self.killindicator)
533                 {
534                         remove(self.killindicator);
535                         self.killindicator = world;
536                         if(self.killindicator_teamchange)
537                                 defer_ClientKill_Now_TeamChange = true;
538
539                         if(self.classname == "body")
540                         if(deathtype == DEATH_KILL.m_id)
541                         {
542                                 // for the lemmings fans, a small harmless explosion
543                                 Send_Effect(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
544                         }
545                 }
546
547                 // print an obituary message
548                 if(self.classname != "body")
549                         Obituary (attacker, inflictor, self, deathtype);
550
551         // increment frag counter for used weapon type
552         Weapon w = DEATH_WEAPONOF(deathtype);
553         if(w != WEP_Null)
554         if(accuracy_isgooddamage(attacker, self))
555         attacker.accuracy.(accuracy_frags[w.m_id-1]) += 1;
556
557                 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
558                 excess = frag_damage;
559
560                 Weapon wep = get_weaponinfo(self.weapon);
561                 wep.wr_playerdeath(wep);
562
563                 RemoveGrapplingHook(self);
564
565                 Portal_ClearAllLater(self);
566
567                 self.fixangle = true;
568
569                 if(defer_ClientKill_Now_TeamChange)
570                         ClientKill_Now_TeamChange(); // can turn player into spectator
571
572                 // player could have been miraculously resuscitated ;)
573                 // e.g. players in freezetag get frozen, they don't really die
574                 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
575                         return;
576
577                 // when we get here, player actually dies
578
579                 Unfreeze(self); // remove any icy remains
580                 self.health = 0; // Unfreeze resets health, so we need to set it back
581
582                 // clear waypoints
583                 WaypointSprite_PlayerDead();
584                 // throw a weapon
585                 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
586
587                 // become fully visible
588                 self.alpha = default_player_alpha;
589                 // make the corpse upright (not tilted)
590                 self.angles_x = 0;
591                 self.angles_z = 0;
592                 // don't spin
593                 self.avelocity = '0 0 0';
594                 // view from the floor
595                 self.view_ofs = '0 0 -8';
596                 // toss the corpse
597                 self.movetype = MOVETYPE_TOSS;
598                 // shootable corpse
599                 self.solid = SOLID_CORPSE;
600                 self.ballistics_density = autocvar_g_ballistics_density_corpse;
601                 // don't stick to the floor
602                 self.flags &= ~FL_ONGROUND;
603                 // dying animation
604                 self.deadflag = DEAD_DYING;
605
606                 // when to allow respawn
607                 calculate_player_respawn_time();
608
609                 self.death_time = time;
610                 if (random() < 0.5)
611                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
612                 else
613                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
614                 if (self.maxs.z > 5)
615                 {
616                         self.maxs_z = 5;
617                         setsize(self, self.mins, self.maxs);
618                 }
619                 // set damage function to corpse damage
620                 self.event_damage = PlayerCorpseDamage;
621                 // call the corpse damage function just in case it wants to gib
622                 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
623
624                 // set up to fade out later
625                 SUB_SetFade (self, time + 6 + random (), 1);
626                 // reset body think wrapper broken by SUB_SetFade
627                 if(self.classname == "body" && self.think != CopyBody_Think) {
628                         self.CopyBody_think = self.think;
629                         self.CopyBody_nextthink = self.nextthink;
630                         self.think = CopyBody_Think;
631                         self.nextthink = time;
632                 }
633
634                 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
635                         // remove corpse
636                         // clones don't run any animation code any more, so we must gib them when they die :(
637                         PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
638                 }
639
640                 // reset fields the weapons may use just in case
641                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
642                 {
643                         Weapon w = get_weaponinfo(j);
644                         w.wr_resetplayer(w);
645                         for (int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
646                         {
647                                 ATTACK_FINISHED_FOR(self, j, slot) = 0;
648                         }
649                 }
650         }
651 }
652
653 void MoveToTeam(entity client, int team_colour, int type)
654 {
655         int lockteams_backup = lockteams;  // backup any team lock
656         lockteams = 0;  // disable locked teams
657         TeamchangeFrags(client);  // move the players frags
658         SetPlayerColors(client, team_colour - 1);  // set the players colour
659         Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0');  // kill the player
660         lockteams = lockteams_backup;  // restore the team lock
661         LogTeamchange(client.playerid, client.team, type);
662 }
663
664 /**
665  * message "": do not say, just test flood control
666  * return value:
667  *   1 = accept
668  *   0 = reject
669  *  -1 = fake accept
670  */
671 int Say(entity source, float teamsay, entity privatesay, string msgin, bool floodcontrol)
672 {
673         string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
674         float flood;
675         var .float flood_field;
676         entity head;
677         float ret;
678         string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
679
680         if(!teamsay && !privatesay)
681                 if(substring(msgin, 0, 1) == " ")
682                         msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
683
684         msgin = formatmessage(msgin);
685
686         if (!IS_PLAYER(source))
687                 colorstr = "^0"; // black for spectators
688         else if(teamplay)
689                 colorstr = Team_ColorCode(source.team);
690         else
691         {
692                 colorstr = "";
693                 teamsay = false;
694         }
695
696         if(intermission_running)
697                 teamsay = false;
698
699         if(msgin != "")
700                 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
701
702         /*
703          * using bprint solves this... me stupid
704         // how can we prevent the message from appearing in a listen server?
705         // for now, just give "say" back and only handle say_team
706         if(!teamsay)
707         {
708                 clientcommand(self, strcat("say ", msgin));
709                 return;
710         }
711         */
712
713         if(autocvar_g_chat_teamcolors)
714                 namestr = playername(source);
715         else
716                 namestr = source.netname;
717
718         if(strdecolorize(namestr) == namestr)
719                 colorprefix = "^3";
720         else
721                 colorprefix = "^7";
722
723         if(msgin != "")
724         {
725                 if(privatesay)
726                 {
727                         msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
728                         privatemsgprefixlen = strlen(msgstr);
729                         msgstr = strcat(msgstr, msgin);
730                         cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
731                         if(autocvar_g_chat_teamcolors)
732                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
733                         else
734                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
735                 }
736                 else if(teamsay)
737                 {
738                         if(strstrofs(msgin, "/me", 0) >= 0)
739                         {
740                                 //msgin = strreplace("/me", "", msgin);
741                                 //msgin = substring(msgin, 3, strlen(msgin));
742                                 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
743                                 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
744                         }
745                         else
746                                 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
747                         cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
748                 }
749                 else
750                 {
751                         if(strstrofs(msgin, "/me", 0) >= 0)
752                         {
753                                 //msgin = strreplace("/me", "", msgin);
754                                 //msgin = substring(msgin, 3, strlen(msgin));
755                                 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
756                                 msgstr = strcat("\{1}^4* ", "^7", msgin);
757                         }
758                         else
759                                 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
760                         cmsgstr = "";
761                 }
762                 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
763         }
764         else
765         {
766                 msgstr = cmsgstr = "";
767         }
768
769         fullmsgstr = msgstr;
770         fullcmsgstr = cmsgstr;
771
772         // FLOOD CONTROL
773         flood = 0;
774         flood_field = floodcontrol_chat;
775         if(floodcontrol)
776         {
777                 float flood_spl;
778                 float flood_burst;
779                 float flood_lmax;
780                 float lines;
781                 if(privatesay)
782                 {
783                         flood_spl = autocvar_g_chat_flood_spl_tell;
784                         flood_burst = autocvar_g_chat_flood_burst_tell;
785                         flood_lmax = autocvar_g_chat_flood_lmax_tell;
786                         flood_field = floodcontrol_chattell;
787                 }
788                 else if(teamsay)
789                 {
790                         flood_spl = autocvar_g_chat_flood_spl_team;
791                         flood_burst = autocvar_g_chat_flood_burst_team;
792                         flood_lmax = autocvar_g_chat_flood_lmax_team;
793                         flood_field = floodcontrol_chatteam;
794                 }
795                 else
796                 {
797                         flood_spl = autocvar_g_chat_flood_spl;
798                         flood_burst = autocvar_g_chat_flood_burst;
799                         flood_lmax = autocvar_g_chat_flood_lmax;
800                         flood_field = floodcontrol_chat;
801                 }
802                 flood_burst = max(0, flood_burst - 1);
803                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
804
805                 // do flood control for the default line size
806                 if(msgstr != "")
807                 {
808                         getWrappedLine_remaining = msgstr;
809                         msgstr = "";
810                         lines = 0;
811                         while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
812                         {
813                                 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
814                                 ++lines;
815                         }
816                         msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
817
818                         if(getWrappedLine_remaining != "")
819                         {
820                                 msgstr = strcat(msgstr, "\n");
821                                 flood = 2;
822                         }
823
824                         if (time >= source.(flood_field))
825                         {
826                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
827                         }
828                         else
829                         {
830                                 flood = 1;
831                                 msgstr = fullmsgstr;
832                         }
833                 }
834                 else
835                 {
836                         if (time >= source.(flood_field))
837                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
838                         else
839                                 flood = 1;
840                 }
841
842                 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
843                         source.(flood_field) = flood = 0;
844         }
845
846         if(flood == 2) // cannot happen for empty msgstr
847         {
848                 if(autocvar_g_chat_flood_notify_flooder)
849                 {
850                         sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
851                         sourcecmsgstr = "";
852                 }
853                 else
854                 {
855                         sourcemsgstr = fullmsgstr;
856                         sourcecmsgstr = fullcmsgstr;
857                 }
858                 cmsgstr = "";
859         }
860         else
861         {
862                 sourcemsgstr = msgstr;
863                 sourcecmsgstr = cmsgstr;
864         }
865
866         if(!privatesay)
867         if (!IS_PLAYER(source))
868         {
869                 if (!intermission_running)
870                         if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
871                                 teamsay = -1; // spectators
872         }
873
874         if(flood)
875                 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
876
877         // build sourcemsgstr by cutting off a prefix and replacing it by the other one
878         if(privatesay)
879                 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
880
881         if(source.muted)
882         {
883                 // always fake the message
884                 ret = -1;
885         }
886         else if(flood == 1)
887         {
888                 if (autocvar_g_chat_flood_notify_flooder)
889                 {
890                         sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
891                         ret = 0;
892                 }
893                 else
894                         ret = -1;
895         }
896         else
897         {
898                 ret = 1;
899         }
900
901         if(sourcemsgstr != "" && ret != 0)
902         {
903                 if(ret < 0) // faked message, because the player is muted
904                 {
905                         sprint(source, sourcemsgstr);
906                         if(sourcecmsgstr != "" && !privatesay)
907                                 centerprint(source, sourcecmsgstr);
908                 }
909                 else if(privatesay) // private message, between 2 people only
910                 {
911                         sprint(source, sourcemsgstr);
912                         sprint(privatesay, msgstr);
913                         if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
914                         if(cmsgstr != "")
915                                 centerprint(privatesay, cmsgstr);
916                 }
917                 else if ( teamsay && source.active_minigame )
918                 {
919                         sprint(source, sourcemsgstr);
920                         dedicated_print(msgstr); // send to server console too
921                         FOR_EACH_REALCLIENT(head)
922                                 if(head != source)
923                                 if(head.active_minigame == source.active_minigame)
924                                         sprint(head, msgstr);
925                 }
926                 else if(teamsay > 0) // team message, only sent to team mates
927                 {
928                         sprint(source, sourcemsgstr);
929                         dedicated_print(msgstr); // send to server console too
930                         if(sourcecmsgstr != "")
931                                 centerprint(source, sourcecmsgstr);
932                         FOR_EACH_REALPLAYER(head) if(head.team == source.team)
933                                 if(head != source)
934                                 {
935                                         sprint(head, msgstr);
936                                         if(cmsgstr != "")
937                                                 centerprint(head, cmsgstr);
938                                 }
939                 }
940                 else if(teamsay < 0) // spectator message, only sent to spectators
941                 {
942                         sprint(source, sourcemsgstr);
943                         dedicated_print(msgstr); // send to server console too
944                         FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
945                                 if(head != source)
946                                         sprint(head, msgstr);
947                 }
948                 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
949                 {
950                         sprint(source, sourcemsgstr);
951                         dedicated_print(msgstr); // send to server console too
952                         FOR_EACH_REALCLIENT(head)
953                                 if(head != source)
954                                         sprint(head, msgstr);
955                 }
956                 else
957                         bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
958         }
959
960         return ret;
961 }
962
963 float GetVoiceMessageVoiceType(string type)
964 {
965         if (type == "taunt") return VOICETYPE_TAUNT;
966         if (type == "teamshoot") return VOICETYPE_LASTATTACKER;
967         return VOICETYPE_TEAMRADIO;
968 }
969
970 .string GetVoiceMessageSampleField(string type)
971 {
972         GetPlayerSoundSampleField_notFound = false;
973         switch (type)
974         {
975 #define X(m) case #m: return playersound_##m;
976                 ALLVOICEMSGS(X)
977 #undef X
978         }
979         GetPlayerSoundSampleField_notFound = true;
980         return playersound_taunt;
981 }
982
983 .string GetPlayerSoundSampleField(string type)
984 {
985         GetPlayerSoundSampleField_notFound = false;
986         switch (type)
987         {
988 #define X(m) case #m: return playersound_##m;
989                 ALLPLAYERSOUNDS(X)
990 #undef X
991         }
992         GetPlayerSoundSampleField_notFound = true;
993         return playersound_taunt;
994 }
995
996 void PrecacheGlobalSound(string sample)
997 {
998         int n;
999         {
1000                 string s = cdr(sample);
1001                 if (s) n = stof(s);
1002                 else n = 0;
1003         }
1004         sample = car(sample);
1005         if (n > 0)
1006         {
1007                 for (int i = 1; i <= n; ++i)
1008                         precache_sound(sprintf("%s%d.wav", sample, i));
1009         }
1010         else
1011         {
1012                 precache_sound(sprintf("%s.wav", sample));
1013         }
1014 }
1015
1016 string allvoicesamples;
1017
1018 void PrecachePlayerSounds(string f)
1019 {
1020         int fh = fopen(f, FILE_READ);
1021         if (fh < 0)
1022         {
1023                 LOG_WARNINGF("Player sound file not found: %s\n", f);
1024                 return;
1025         }
1026         for (string s; (s = fgets(fh)); )
1027         {
1028                 int n = tokenize_console(s);
1029                 if (n != 3)
1030                 {
1031                         if (n != 0) LOG_WARNINGF("Invalid sound info line: %s\n", s);
1032                         continue;
1033                 }
1034                 string file = argv(1);
1035                 string variants = argv(2);
1036                 PrecacheGlobalSound(strcat(file, " ", variants));
1037         }
1038         fclose(fh);
1039
1040         if (!allvoicesamples)
1041         {
1042 #define X(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1043                 ALLVOICEMSGS(X)
1044 #undef X
1045                 allvoicesamples = strzone(substring(allvoicesamples, 1, -1));
1046         }
1047 }
1048
1049 void ClearPlayerSounds(entity this)
1050 {
1051 #define X(m) if (this.playersound_##m) { strunzone(this.playersound_##m); this.playersound_##m = string_null; }
1052         ALLPLAYERSOUNDS(X)
1053         ALLVOICEMSGS(X)
1054 #undef X
1055 }
1056
1057 bool LoadPlayerSounds(string f, bool strict)
1058 {
1059         SELFPARAM();
1060         int fh = fopen(f, FILE_READ);
1061         if (fh < 0)
1062         {
1063                 if (strict) LOG_WARNINGF("Player sound file not found: %s\n", f);
1064                 return false;
1065         }
1066         for (string s; (s = fgets(fh)); )
1067         {
1068                 int n = tokenize_console(s);
1069                 if (n != 3)
1070                 {
1071                         if (n != 0) LOG_WARNINGF("Invalid sound info line: %s\n", s);
1072                         continue;
1073                 }
1074                 string key = argv(0);
1075                 var .string field = GetPlayerSoundSampleField(key);
1076                 if (GetPlayerSoundSampleField_notFound) field = GetVoiceMessageSampleField(key);
1077                 if (GetPlayerSoundSampleField_notFound)
1078                 {
1079                         LOG_TRACEF("Invalid sound info field: %s\n", key);
1080                         continue;
1081                 }
1082                 string file = argv(1);
1083                 string variants = argv(2);
1084                 if (self.(field)) strunzone(self.(field));
1085                 self.(field) = strzone(strcat(file, " ", variants));
1086         }
1087         fclose(fh);
1088         return true;
1089 }
1090
1091 .int modelindex_for_playersound;
1092 .int skin_for_playersound;
1093
1094 void UpdatePlayerSounds(entity this)
1095 {
1096         if (this.modelindex == this.modelindex_for_playersound && this.skin == this.skin_for_playersound) return;
1097         this.modelindex_for_playersound = this.modelindex;
1098         this.skin_for_playersound = this.skin;
1099         ClearPlayerSounds(this);
1100         LoadPlayerSounds("sound/player/default.sounds", true);
1101         if (autocvar_g_debug_defaultsounds) return;
1102         if (!LoadPlayerSounds(get_model_datafilename(this.model, this.skin, "sounds"), false))
1103                 LoadPlayerSounds(get_model_datafilename(this.model, 0, "sounds"), true);
1104 }
1105
1106 void FakeGlobalSound(string sample, int chan, int voicetype)
1107 {
1108         SELFPARAM();
1109         if (sample == "") return;
1110         int n;
1111         {
1112                 string s = cdr(sample);
1113                 if (s) n = stof(s);
1114                 else n = 0;
1115         }
1116         sample = car(sample);
1117         if (n > 0) sample = sprintf("%s%d.wav", sample, floor(random() * n + 1));  // randomization
1118         else sample = sprintf("%s.wav", sample);
1119         switch (voicetype)
1120         {
1121                 case VOICETYPE_LASTATTACKER_ONLY:
1122                 case VOICETYPE_LASTATTACKER:
1123                 {
1124                     if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break;
1125             msg_entity = this;
1126             if (IS_REAL_CLIENT(msg_entity)) soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE);
1127                         break;
1128                 }
1129                 case VOICETYPE_TEAMRADIO:
1130                 {
1131                         msg_entity = this;
1132                         float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE;
1133                         soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten);
1134                         break;
1135                 }
1136                 case VOICETYPE_AUTOTAUNT:
1137                 case VOICETYPE_TAUNT:
1138                 {
1139                         if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) break; else {}
1140                         else if (IS_PLAYER(this) && this.deadflag == DEAD_NO) animdecide_setaction(this, ANIMACTION_TAUNT, true);
1141                         if (!sv_taunt) break;
1142                         if (autocvar_sv_gentle) break;
1143                         float tauntrand = 0;
1144                         if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random();
1145                         msg_entity = this;
1146                         if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt)
1147                         {
1148                                 float atten = (msg_entity.cvar_cl_voice_directional >= 1)
1149                                         ? bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX)
1150                                         : ATTEN_NONE;
1151                                 soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten);
1152                         }
1153                         break;
1154                 }
1155                 case VOICETYPE_PLAYERSOUND:
1156                 {
1157                         msg_entity = this;
1158                         soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NORM);
1159                         break;
1160                 }
1161                 default:
1162                 {
1163                         backtrace("Invalid voice type!");
1164                         break;
1165                 }
1166         }
1167 }
1168
1169 void GlobalSound(string sample, int chan, int voicetype)
1170 {
1171         SELFPARAM();
1172         if (sample == "") return;
1173         int n;
1174         {
1175                 string s = cdr(sample);
1176                 if (s) n = stof(s);
1177                 else n = 0;
1178         }
1179         sample = car(sample);
1180         if (n > 0) sample = sprintf("%s%d.wav", sample, floor(random() * n + 1)); // randomization
1181         else sample = sprintf("%s.wav", sample);
1182         switch (voicetype)
1183         {
1184                 case VOICETYPE_LASTATTACKER_ONLY:
1185                 case VOICETYPE_LASTATTACKER:
1186                 {
1187                         if (!this.pusher) break;
1188             msg_entity = this.pusher;
1189             if (IS_REAL_CLIENT(msg_entity))
1190             {
1191                 float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE;
1192                 soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten);
1193             }
1194             if (voicetype == VOICETYPE_LASTATTACKER_ONLY) break;
1195                         msg_entity = this;
1196                         if (IS_REAL_CLIENT(msg_entity)) soundto(MSG_ONE, this, chan, sample, VOL_BASE, ATTEN_NONE);
1197                         break;
1198                 }
1199                 case VOICETYPE_TEAMRADIO:
1200                 {
1201                         FOR_EACH_REALCLIENT(msg_entity)
1202                         if (!teamplay || msg_entity.team == this.team)
1203                         {
1204                                 float atten = (msg_entity.cvar_cl_voice_directional == 1) ? ATTEN_MIN : ATTEN_NONE;
1205                                 soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten);
1206                         }
1207                         break;
1208                 }
1209                 case VOICETYPE_AUTOTAUNT:
1210                 case VOICETYPE_TAUNT:
1211                 {
1212                         if (voicetype == VOICETYPE_AUTOTAUNT) if (!sv_autotaunt) break; else {}
1213                         else if (IS_PLAYER(this) && this.deadflag == DEAD_NO) animdecide_setaction(this, ANIMACTION_TAUNT, true);
1214                         if (!sv_taunt) break;
1215                         if (autocvar_sv_gentle) break;
1216                         float tauntrand = 0;
1217                         if (voicetype == VOICETYPE_AUTOTAUNT) tauntrand = random();
1218                         FOR_EACH_REALCLIENT(msg_entity)
1219                         if (voicetype != VOICETYPE_AUTOTAUNT || tauntrand < msg_entity.cvar_cl_autotaunt)
1220                         {
1221                                 float atten = (msg_entity.cvar_cl_voice_directional >= 1)
1222                                         ? bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX)
1223                                         : ATTEN_NONE;
1224                                 soundto(MSG_ONE, this, chan, sample, VOL_BASEVOICE, atten);
1225                         }
1226                         break;
1227                 }
1228                 case VOICETYPE_PLAYERSOUND:
1229                 {
1230                         _sound(this, chan, sample, VOL_BASE, ATTEN_NORM);
1231                         break;
1232                 }
1233                 default:
1234                 {
1235                         backtrace("Invalid voice type!");
1236                         break;
1237                 }
1238         }
1239 }
1240
1241 void PlayerSound(.string samplefield, float chan, float voicetype)
1242 {
1243         SELFPARAM();
1244         GlobalSound(this.(samplefield), chan, voicetype);
1245 }
1246
1247 void VoiceMessage(string type, string msg)
1248 {
1249         SELFPARAM();
1250         var .string sample = GetVoiceMessageSampleField(type);
1251         if (GetPlayerSoundSampleField_notFound)
1252         {
1253                 sprint(this, sprintf("Invalid voice. Use one of: %s\n", allvoicesamples));
1254                 return;
1255         }
1256         int voicetype = GetVoiceMessageVoiceType(type);
1257         bool ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1258         int flood = Say(this, ownteam, world, msg, true);
1259         void(string sample, int chan, int voicetype) f;
1260         f = (IS_SPEC(this) || IS_OBSERVER(this) || flood < 0) ? FakeGlobalSound
1261                 : (flood > 0) ? GlobalSound
1262                 : func_null;
1263         if (f) f(this.(sample), CH_VOICE, voicetype);
1264 }