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