Fix overkill superweapon waypoints
[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 {SELFPARAM();
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(self);
39         self.nextthink = time;
40 }
41 void CopyBody(float keepvelocity)
42 {SELFPARAM();
43         if (self.effects & EF_NODRAW)
44                 return;
45         setself(spawn());
46         self.enemy = this;
47         self.lip = this.lip;
48         self.colormap = this.colormap;
49         self.iscreature = this.iscreature;
50         self.teleportable = this.teleportable;
51         self.damagedbycontents = this.damagedbycontents;
52         self.angles = this.angles;
53         self.v_angle = this.v_angle;
54         self.avelocity = this.avelocity;
55         self.classname = "body";
56         self.damageforcescale = this.damageforcescale;
57         self.effects = this.effects;
58         self.glowmod = this.glowmod;
59         self.event_damage = this.event_damage;
60         self.anim_state = this.anim_state;
61         self.anim_time = this.anim_time;
62         self.anim_lower_action = this.anim_lower_action;
63         self.anim_lower_time = this.anim_lower_time;
64         self.anim_upper_action = this.anim_upper_action;
65         self.anim_upper_time = this.anim_upper_time;
66         self.anim_implicit_state = this.anim_implicit_state;
67         self.anim_implicit_time = this.anim_implicit_time;
68         self.anim_lower_implicit_action = this.anim_lower_implicit_action;
69         self.anim_lower_implicit_time = this.anim_lower_implicit_time;
70         self.anim_upper_implicit_action = this.anim_upper_implicit_action;
71         self.anim_upper_implicit_time = this.anim_upper_implicit_time;
72         self.dphitcontentsmask = this.dphitcontentsmask;
73         self.death_time = this.death_time;
74         self.pain_finished = this.pain_finished;
75         self.health = this.health;
76         self.armorvalue = this.armorvalue;
77         self.armortype = this.armortype;
78         self.model = this.model;
79         self.modelindex = this.modelindex;
80         self.skin = this.skin;
81         self.species = this.species;
82         self.movetype = this.movetype;
83         self.solid = this.solid;
84         self.ballistics_density = this.ballistics_density;
85         self.takedamage = this.takedamage;
86         self.customizeentityforclient = this.customizeentityforclient;
87         self.uncustomizeentityforclient = this.uncustomizeentityforclient;
88         self.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
89         if (keepvelocity == 1)
90                 self.velocity = this.velocity;
91         self.oldvelocity = self.velocity;
92         self.alpha = this.alpha;
93         self.fade_time = this.fade_time;
94         self.fade_rate = this.fade_rate;
95         //self.weapon = this.weapon;
96         setorigin(self, this.origin);
97         setsize(self, this.mins, this.maxs);
98         self.prevorigin = this.origin;
99         self.reset = SUB_Remove;
100
101         Drag_MoveDrag(this, self);
102
103         if(self.colormap <= maxclients && self.colormap > 0)
104                 self.colormap = 1024 + this.clientcolors;
105
106         CSQCMODEL_AUTOINIT(self);
107         self.CopyBody_nextthink = this.nextthink;
108         self.CopyBody_think = this.think;
109         self.nextthink = time;
110         self.think = CopyBody_Think;
111         // "bake" the current animation frame for clones (they don't get clientside animation)
112         animdecide_load_if_needed(self);
113         animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
114
115         setself(this);
116 }
117
118 float player_getspecies()
119 {SELFPARAM();
120         float s;
121         get_model_parameters(self.model, self.skin);
122         s = get_model_parameters_species;
123         get_model_parameters(string_null, 0);
124         if(s < 0)
125                 return SPECIES_HUMAN;
126         return s;
127 }
128
129 void player_setupanimsformodel()
130 {SELFPARAM();
131         // load animation info
132         animdecide_load_if_needed(self);
133         animdecide_setstate(self, 0, false);
134 }
135
136 void player_anim (void)
137 {SELFPARAM();
138         int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
139         if(self.deadflag) {
140                 if (!deadbits) {
141                         // Decide on which death animation to use.
142                         if(random() < 0.5)
143                                 deadbits = ANIMSTATE_DEAD1;
144                         else
145                                 deadbits = ANIMSTATE_DEAD2;
146                 }
147         } else {
148                 // Clear a previous death animation.
149                 deadbits = 0;
150         }
151         int animbits = deadbits;
152         if(self.frozen)
153                 animbits |= ANIMSTATE_FROZEN;
154         if(self.movetype == MOVETYPE_FOLLOW)
155                 animbits |= ANIMSTATE_FOLLOW;
156         if(self.crouch)
157                 animbits |= ANIMSTATE_DUCK;
158         animdecide_setstate(self, animbits, false);
159         animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
160
161         if (self.weaponentity)
162         {
163                 updateanim(self.weaponentity);
164                 if (!self.weaponentity.animstate_override)
165                         setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
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, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
186                 else if (take > 30)
187                         sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
188                 else if (take > 10)
189                         sound (self, CH_SHOTS, "misc/bodyimpact1.wav", 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.m_id))
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, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
399                 else if (take > 30)
400                         sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
401                 else if (take > 10)
402                         sound (self, CH_SHOTS, "misc/bodyimpact1.wav", 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) || !((get_weaponinfo(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)
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         float abot, vbot, awep;
473         abot = (IS_BOT_CLIENT(attacker));
474         vbot = (IS_BOT_CLIENT(self));
475
476         valid_damage_for_weaponstats = 0;
477         awep = 0;
478
479         if(vbot || IS_REAL_CLIENT(self))
480         if(abot || IS_REAL_CLIENT(attacker))
481         if(attacker && self != attacker)
482         if(DIFF_TEAM(self, attacker))
483         {
484                 if(DEATH_ISSPECIAL(deathtype))
485                         awep = attacker.weapon;
486                 else
487                         awep = DEATH_WEAPONOF(deathtype);
488                 valid_damage_for_weaponstats = 1;
489         }
490
491         if(valid_damage_for_weaponstats)
492         {
493                 dh = dh - max(self.health, 0);
494                 da = da - max(self.armorvalue, 0);
495                 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
496                 MUTATOR_CALLHOOK(PlayerDamaged, attacker, self, dh, da, hitloc);
497         }
498
499         if (self.health < 1)
500         {
501                 float defer_ClientKill_Now_TeamChange;
502                 defer_ClientKill_Now_TeamChange = false;
503
504                 if(self.alivetime)
505                 {
506                         PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
507                         self.alivetime = 0;
508                 }
509
510                 if(valid_damage_for_weaponstats)
511                         WeaponStats_LogKill(awep, abot, self.weapon, vbot);
512
513                 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
514                 if(sound_allowed(MSG_BROADCAST, attacker))
515                 {
516                         if(deathtype == DEATH_DROWN)
517                                 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
518                         else
519                                 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
520                 }
521
522                 // get rid of kill indicator
523                 if(self.killindicator)
524                 {
525                         remove(self.killindicator);
526                         self.killindicator = world;
527                         if(self.killindicator_teamchange)
528                                 defer_ClientKill_Now_TeamChange = true;
529
530                         if(self.classname == "body")
531                         if(deathtype == DEATH_KILL)
532                         {
533                                 // for the lemmings fans, a small harmless explosion
534                                 Send_Effect(EFFECT_ROCKET_EXPLODE, self.origin, '0 0 0', 1);
535                         }
536                 }
537
538                 // print an obituary message
539                 if(self.classname != "body")
540                         Obituary (attacker, inflictor, self, deathtype);
541
542         // increment frag counter for used weapon type
543         int w = DEATH_WEAPONOF(deathtype);
544         if(WEP_VALID(w))
545         if(accuracy_isgooddamage(attacker, self))
546         attacker.accuracy.(accuracy_frags[w-1]) += 1;
547
548                 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, self, deathtype);
549                 excess = frag_damage;
550
551                 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
552
553                 RemoveGrapplingHook(self);
554
555                 Portal_ClearAllLater(self);
556
557                 self.fixangle = true;
558
559                 if(defer_ClientKill_Now_TeamChange)
560                         ClientKill_Now_TeamChange(); // can turn player into spectator
561
562                 // player could have been miraculously resuscitated ;)
563                 // e.g. players in freezetag get frozen, they don't really die
564                 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
565                         return;
566
567                 // when we get here, player actually dies
568
569                 Unfreeze(self); // remove any icy remains
570                 self.health = 0; // Unfreeze resets health, so we need to set it back
571
572                 // clear waypoints
573                 WaypointSprite_PlayerDead();
574                 // throw a weapon
575                 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
576
577                 // become fully visible
578                 self.alpha = default_player_alpha;
579                 // make the corpse upright (not tilted)
580                 self.angles_x = 0;
581                 self.angles_z = 0;
582                 // don't spin
583                 self.avelocity = '0 0 0';
584                 // view from the floor
585                 self.view_ofs = '0 0 -8';
586                 // toss the corpse
587                 self.movetype = MOVETYPE_TOSS;
588                 // shootable corpse
589                 self.solid = SOLID_CORPSE;
590                 self.ballistics_density = autocvar_g_ballistics_density_corpse;
591                 // don't stick to the floor
592                 self.flags &= ~FL_ONGROUND;
593                 // dying animation
594                 self.deadflag = DEAD_DYING;
595
596                 // when to allow respawn
597                 calculate_player_respawn_time();
598
599                 self.death_time = time;
600                 if (random() < 0.5)
601                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
602                 else
603                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
604                 if (self.maxs.z > 5)
605                 {
606                         self.maxs_z = 5;
607                         setsize(self, self.mins, self.maxs);
608                 }
609                 // set damage function to corpse damage
610                 self.event_damage = PlayerCorpseDamage;
611                 // call the corpse damage function just in case it wants to gib
612                 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
613
614                 // set up to fade out later
615                 SUB_SetFade (self, time + 6 + random (), 1);
616                 // reset body think wrapper broken by SUB_SetFade
617                 if(self.classname == "body" && self.think != CopyBody_Think) {
618                         self.CopyBody_think = self.think;
619                         self.CopyBody_nextthink = self.nextthink;
620                         self.think = CopyBody_Think;
621                         self.nextthink = time;
622                 }
623
624                 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
625                         // remove corpse
626                         // clones don't run any animation code any more, so we must gib them when they die :(
627                         PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
628                 }
629
630                 // reset fields the weapons may use just in case
631                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
632                 {
633                         WEP_ACTION(j, WR_RESETPLAYER);
634                         ATTACK_FINISHED_FOR(self, j) = 0;
635                 }
636         }
637 }
638
639 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
640 // message "": do not say, just test flood control
641 // return value:
642 //   1 = accept
643 //   0 = reject
644 //  -1 = fake accept
645 {
646         string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
647         float flood;
648         var .float flood_field;
649         entity head;
650         float ret;
651         string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
652
653         if(!teamsay && !privatesay)
654                 if(substring(msgin, 0, 1) == " ")
655                         msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
656
657         msgin = formatmessage(msgin);
658
659         if (!IS_PLAYER(source))
660                 colorstr = "^0"; // black for spectators
661         else if(teamplay)
662                 colorstr = Team_ColorCode(source.team);
663         else
664         {
665                 colorstr = "";
666                 teamsay = false;
667         }
668
669         if(intermission_running)
670                 teamsay = false;
671
672         if(msgin != "")
673                 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
674
675         /*
676          * using bprint solves this... me stupid
677         // how can we prevent the message from appearing in a listen server?
678         // for now, just give "say" back and only handle say_team
679         if(!teamsay)
680         {
681                 clientcommand(self, strcat("say ", msgin));
682                 return;
683         }
684         */
685
686         if(autocvar_g_chat_teamcolors)
687                 namestr = playername(source);
688         else
689                 namestr = source.netname;
690
691         if(strdecolorize(namestr) == namestr)
692                 colorprefix = "^3";
693         else
694                 colorprefix = "^7";
695
696         if(msgin != "")
697         {
698                 if(privatesay)
699                 {
700                         msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
701                         privatemsgprefixlen = strlen(msgstr);
702                         msgstr = strcat(msgstr, msgin);
703                         cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
704                         if(autocvar_g_chat_teamcolors)
705                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
706                         else
707                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
708                 }
709                 else if(teamsay)
710                 {
711                         if(strstrofs(msgin, "/me", 0) >= 0)
712                         {
713                                 //msgin = strreplace("/me", "", msgin);
714                                 //msgin = substring(msgin, 3, strlen(msgin));
715                                 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
716                                 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
717                         }
718                         else
719                                 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
720                         cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
721                 }
722                 else
723                 {
724                         if(strstrofs(msgin, "/me", 0) >= 0)
725                         {
726                                 //msgin = strreplace("/me", "", msgin);
727                                 //msgin = substring(msgin, 3, strlen(msgin));
728                                 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
729                                 msgstr = strcat("\{1}^4* ", "^7", msgin);
730                         }
731                         else
732                                 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
733                         cmsgstr = "";
734                 }
735                 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
736         }
737         else
738         {
739                 msgstr = cmsgstr = "";
740         }
741
742         fullmsgstr = msgstr;
743         fullcmsgstr = cmsgstr;
744
745         // FLOOD CONTROL
746         flood = 0;
747         flood_field = floodcontrol_chat;
748         if(floodcontrol)
749         {
750                 float flood_spl;
751                 float flood_burst;
752                 float flood_lmax;
753                 float lines;
754                 if(privatesay)
755                 {
756                         flood_spl = autocvar_g_chat_flood_spl_tell;
757                         flood_burst = autocvar_g_chat_flood_burst_tell;
758                         flood_lmax = autocvar_g_chat_flood_lmax_tell;
759                         flood_field = floodcontrol_chattell;
760                 }
761                 else if(teamsay)
762                 {
763                         flood_spl = autocvar_g_chat_flood_spl_team;
764                         flood_burst = autocvar_g_chat_flood_burst_team;
765                         flood_lmax = autocvar_g_chat_flood_lmax_team;
766                         flood_field = floodcontrol_chatteam;
767                 }
768                 else
769                 {
770                         flood_spl = autocvar_g_chat_flood_spl;
771                         flood_burst = autocvar_g_chat_flood_burst;
772                         flood_lmax = autocvar_g_chat_flood_lmax;
773                         flood_field = floodcontrol_chat;
774                 }
775                 flood_burst = max(0, flood_burst - 1);
776                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
777
778                 // do flood control for the default line size
779                 if(msgstr != "")
780                 {
781                         getWrappedLine_remaining = msgstr;
782                         msgstr = "";
783                         lines = 0;
784                         while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
785                         {
786                                 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
787                                 ++lines;
788                         }
789                         msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
790
791                         if(getWrappedLine_remaining != "")
792                         {
793                                 msgstr = strcat(msgstr, "\n");
794                                 flood = 2;
795                         }
796
797                         if (time >= source.(flood_field))
798                         {
799                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
800                         }
801                         else
802                         {
803                                 flood = 1;
804                                 msgstr = fullmsgstr;
805                         }
806                 }
807                 else
808                 {
809                         if (time >= source.(flood_field))
810                                 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
811                         else
812                                 flood = 1;
813                 }
814
815                 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
816                         source.(flood_field) = flood = 0;
817         }
818
819         if(flood == 2) // cannot happen for empty msgstr
820         {
821                 if(autocvar_g_chat_flood_notify_flooder)
822                 {
823                         sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
824                         sourcecmsgstr = "";
825                 }
826                 else
827                 {
828                         sourcemsgstr = fullmsgstr;
829                         sourcecmsgstr = fullcmsgstr;
830                 }
831                 cmsgstr = "";
832         }
833         else
834         {
835                 sourcemsgstr = msgstr;
836                 sourcecmsgstr = cmsgstr;
837         }
838
839         if(!privatesay)
840         if (!IS_PLAYER(source))
841         {
842                 if (!intermission_running)
843                         if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
844                                 teamsay = -1; // spectators
845         }
846
847         if(flood)
848                 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
849
850         // build sourcemsgstr by cutting off a prefix and replacing it by the other one
851         if(privatesay)
852                 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
853
854         if(source.muted)
855         {
856                 // always fake the message
857                 ret = -1;
858         }
859         else if(flood == 1)
860         {
861                 if (autocvar_g_chat_flood_notify_flooder)
862                 {
863                         sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
864                         ret = 0;
865                 }
866                 else
867                         ret = -1;
868         }
869         else
870         {
871                 ret = 1;
872         }
873
874         if(sourcemsgstr != "" && ret != 0)
875         {
876                 if(ret < 0) // faked message, because the player is muted
877                 {
878                         sprint(source, sourcemsgstr);
879                         if(sourcecmsgstr != "" && !privatesay)
880                                 centerprint(source, sourcecmsgstr);
881                 }
882                 else if(privatesay) // private message, between 2 people only
883                 {
884                         sprint(source, sourcemsgstr);
885                         sprint(privatesay, msgstr);
886                         if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
887                         if(cmsgstr != "")
888                                 centerprint(privatesay, cmsgstr);
889                 }
890                 else if ( teamsay && source.active_minigame )
891                 {
892                         sprint(source, sourcemsgstr);
893                         dedicated_print(msgstr); // send to server console too
894                         FOR_EACH_REALCLIENT(head)
895                                 if(head != source)
896                                 if(head.active_minigame == source.active_minigame)
897                                         sprint(head, msgstr);
898                 }
899                 else if(teamsay > 0) // team message, only sent to team mates
900                 {
901                         sprint(source, sourcemsgstr);
902                         dedicated_print(msgstr); // send to server console too
903                         if(sourcecmsgstr != "")
904                                 centerprint(source, sourcecmsgstr);
905                         FOR_EACH_REALPLAYER(head) if(head.team == source.team)
906                                 if(head != source)
907                                 {
908                                         sprint(head, msgstr);
909                                         if(cmsgstr != "")
910                                                 centerprint(head, cmsgstr);
911                                 }
912                 }
913                 else if(teamsay < 0) // spectator message, only sent to spectators
914                 {
915                         sprint(source, sourcemsgstr);
916                         dedicated_print(msgstr); // send to server console too
917                         FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
918                                 if(head != source)
919                                         sprint(head, msgstr);
920                 }
921                 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
922                 {
923                         sprint(source, sourcemsgstr);
924                         dedicated_print(msgstr); // send to server console too
925                         FOR_EACH_REALCLIENT(head)
926                                 if(head != source)
927                                         sprint(head, msgstr);
928                 }
929                 else
930                         bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
931         }
932
933         return ret;
934 }
935
936 float GetVoiceMessageVoiceType(string type)
937 {
938         if(type == "taunt")
939                 return VOICETYPE_TAUNT;
940         if(type == "teamshoot")
941                 return VOICETYPE_LASTATTACKER;
942         return VOICETYPE_TEAMRADIO;
943 }
944
945 .string GetVoiceMessageSampleField(string type)
946 {
947         GetPlayerSoundSampleField_notFound = 0;
948         switch(type)
949         {
950 #define _VOICEMSG(m) case #m: return playersound_##m;
951                 ALLVOICEMSGS
952 #undef _VOICEMSG
953         }
954         GetPlayerSoundSampleField_notFound = 1;
955         return playersound_taunt;
956 }
957
958 .string GetPlayerSoundSampleField(string type)
959 {
960         GetPlayerSoundSampleField_notFound = 0;
961         switch(type)
962         {
963 #define _VOICEMSG(m) case #m: return playersound_##m;
964                 ALLPLAYERSOUNDS
965 #undef _VOICEMSG
966         }
967         GetPlayerSoundSampleField_notFound = 1;
968         return playersound_taunt;
969 }
970
971 void PrecacheGlobalSound(string samplestring)
972 {
973         float n, i;
974         tokenize_console(samplestring);
975         n = stof(argv(1));
976         if(n > 0)
977         {
978                 for(i = 1; i <= n; ++i)
979                         precache_sound(strcat(argv(0), ftos(i), ".wav"));
980         }
981         else
982         {
983                 precache_sound(strcat(argv(0), ".wav"));
984         }
985 }
986
987 void PrecachePlayerSounds(string f)
988 {
989         int fh = fopen(f, FILE_READ);
990         if (fh < 0)
991                 return;
992         for (string s; (s = fgets(fh)); )
993         {
994                 int n = tokenize_console(s);
995                 if (n != 3)
996                 {
997                         if (n != 0) LOG_TRACEF("Invalid sound info line: %s\n", s);
998                         continue;
999                 }
1000                 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1001         }
1002         fclose(fh);
1003
1004         if (!allvoicesamples)
1005         {
1006 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1007                 ALLVOICEMSGS
1008 #undef _VOICEMSG
1009                 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1010         }
1011 }
1012
1013 void ClearPlayerSounds()
1014 {SELFPARAM();
1015 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1016         ALLPLAYERSOUNDS
1017         ALLVOICEMSGS
1018 #undef _VOICEMSG
1019 }
1020
1021 float LoadPlayerSounds(string f, float first)
1022 {SELFPARAM();
1023         float fh;
1024         string s;
1025         var .string field;
1026         fh = fopen(f, FILE_READ);
1027         if(fh < 0)
1028         {
1029                 LOG_TRACE("Player sound file not found: ", f, "\n");
1030                 return 0;
1031         }
1032         while((s = fgets(fh)))
1033         {
1034                 if(tokenize_console(s) != 3)
1035                         continue;
1036                 field = GetPlayerSoundSampleField(argv(0));
1037                 if(GetPlayerSoundSampleField_notFound)
1038                         field = GetVoiceMessageSampleField(argv(0));
1039                 if(GetPlayerSoundSampleField_notFound)
1040                         continue;
1041                 if (self.(field))
1042                         strunzone(self.(field));
1043                 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1044         }
1045         fclose(fh);
1046         return 1;
1047 }
1048
1049 void UpdatePlayerSounds()
1050 {SELFPARAM();
1051         if(self.modelindex == self.modelindex_for_playersound)
1052         if(self.skin == self.skin_for_playersound)
1053                 return;
1054         self.modelindex_for_playersound = self.modelindex;
1055         self.skin_for_playersound = self.skin;
1056         ClearPlayerSounds();
1057         LoadPlayerSounds("sound/player/default.sounds", 1);
1058         if(!autocvar_g_debug_defaultsounds)
1059                 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1060                         LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1061 }
1062
1063 void FakeGlobalSound(string sample, float chan, float voicetype)
1064 {SELFPARAM();
1065         float n;
1066         float tauntrand;
1067
1068         if(sample == "")
1069                 return;
1070
1071         tokenize_console(sample);
1072         n = stof(argv(1));
1073         if(n > 0)
1074                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1075         else
1076                 sample = strcat(argv(0), ".wav"); // randomization
1077
1078         switch(voicetype)
1079         {
1080                 case VOICETYPE_LASTATTACKER_ONLY:
1081                         break;
1082                 case VOICETYPE_LASTATTACKER:
1083                         if(self.pusher)
1084                         {
1085                                 msg_entity = self;
1086                                 if(IS_REAL_CLIENT(msg_entity))
1087                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1088                         }
1089                         break;
1090                 case VOICETYPE_TEAMRADIO:
1091                         msg_entity = self;
1092                         if(msg_entity.cvar_cl_voice_directional == 1)
1093                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1094                         else
1095                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1096                         break;
1097                 case VOICETYPE_AUTOTAUNT:
1098                         if(!sv_autotaunt)
1099                                 break;
1100                         if(!sv_taunt)
1101                                 break;
1102                         if(autocvar_sv_gentle)
1103                                 break;
1104                         tauntrand = random();
1105                         msg_entity = self;
1106                         if (tauntrand < msg_entity.cvar_cl_autotaunt)
1107                         {
1108                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1109                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1110                                 else
1111                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1112                         }
1113                         break;
1114                 case VOICETYPE_TAUNT:
1115                         if(IS_PLAYER(self))
1116                                 if(self.deadflag == DEAD_NO)
1117                                         animdecide_setaction(self, ANIMACTION_TAUNT, true);
1118                         if(!sv_taunt)
1119                                 break;
1120                         if(autocvar_sv_gentle)
1121                                 break;
1122                         msg_entity = self;
1123                         if (msg_entity.cvar_cl_voice_directional >= 1)
1124                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1125                         else
1126                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1127                         break;
1128                 case VOICETYPE_PLAYERSOUND:
1129                         msg_entity = self;
1130                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1131                         break;
1132                 default:
1133                         backtrace("Invalid voice type!");
1134                         break;
1135         }
1136 }
1137
1138 void GlobalSound(string sample, float chan, float voicetype)
1139 {SELFPARAM();
1140         float n;
1141         float tauntrand;
1142
1143         if(sample == "")
1144                 return;
1145
1146         tokenize_console(sample);
1147         n = stof(argv(1));
1148         if(n > 0)
1149                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1150         else
1151                 sample = strcat(argv(0), ".wav"); // randomization
1152
1153         switch(voicetype)
1154         {
1155                 case VOICETYPE_LASTATTACKER_ONLY:
1156                         if(self.pusher)
1157                         {
1158                                 msg_entity = self.pusher;
1159                                 if(IS_REAL_CLIENT(msg_entity))
1160                                 {
1161                                         if(msg_entity.cvar_cl_voice_directional == 1)
1162                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1163                                         else
1164                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1165                                 }
1166                         }
1167                         break;
1168                 case VOICETYPE_LASTATTACKER:
1169                         if(self.pusher)
1170                         {
1171                                 msg_entity = self.pusher;
1172                                 if(IS_REAL_CLIENT(msg_entity))
1173                                 {
1174                                         if(msg_entity.cvar_cl_voice_directional == 1)
1175                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1176                                         else
1177                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1178                                 }
1179                                 msg_entity = self;
1180                                 if(IS_REAL_CLIENT(msg_entity))
1181                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1182                         }
1183                         break;
1184                 case VOICETYPE_TEAMRADIO:
1185                         FOR_EACH_REALCLIENT(msg_entity)
1186                                 if(!teamplay || msg_entity.team == self.team)
1187                                 {
1188                                         if(msg_entity.cvar_cl_voice_directional == 1)
1189                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1190                                         else
1191                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1192                                 }
1193                         break;
1194                 case VOICETYPE_AUTOTAUNT:
1195                         if(!sv_autotaunt)
1196                                 break;
1197                         if(!sv_taunt)
1198                                 break;
1199                         if(autocvar_sv_gentle)
1200                                 break;
1201                         tauntrand = random();
1202                         FOR_EACH_REALCLIENT(msg_entity)
1203                                 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1204                                 {
1205                                         if (msg_entity.cvar_cl_voice_directional >= 1)
1206                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1207                                         else
1208                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1209                                 }
1210                         break;
1211                 case VOICETYPE_TAUNT:
1212                         if(IS_PLAYER(self))
1213                                 if(self.deadflag == DEAD_NO)
1214                                         animdecide_setaction(self, ANIMACTION_TAUNT, true);
1215                         if(!sv_taunt)
1216                                 break;
1217                         if(autocvar_sv_gentle)
1218                                 break;
1219                         FOR_EACH_REALCLIENT(msg_entity)
1220                         {
1221                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1222                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1223                                 else
1224                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1225                         }
1226                         break;
1227                 case VOICETYPE_PLAYERSOUND:
1228                         sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1229                         break;
1230                 default:
1231                         backtrace("Invalid voice type!");
1232                         break;
1233         }
1234 }
1235
1236 void PlayerSound(.string samplefield, float chan, float voicetype)
1237 {SELFPARAM();
1238         GlobalSound(self.(samplefield), chan, voicetype);
1239 }
1240
1241 void VoiceMessage(string type, string msg)
1242 {SELFPARAM();
1243         float voicetype, ownteam;
1244         float flood;
1245         var .string sample = GetVoiceMessageSampleField(type);
1246
1247         if(GetPlayerSoundSampleField_notFound)
1248         {
1249                 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1250                 return;
1251         }
1252
1253         voicetype = GetVoiceMessageVoiceType(type);
1254         ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1255
1256         flood = Say(self, ownteam, world, msg, 1);
1257
1258         if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1259                 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1260         else if (flood > 0)
1261                 GlobalSound(self.(sample), CH_VOICE, voicetype);
1262 }
1263
1264 void MoveToTeam(entity client, float team_colour, float type)
1265 {
1266         float lockteams_backup;
1267
1268         lockteams_backup = lockteams;  // backup any team lock
1269
1270         lockteams = 0;  // disable locked teams
1271
1272         TeamchangeFrags(client);  // move the players frags
1273         SetPlayerColors(client, team_colour - 1);  // set the players colour
1274         Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0');  // kill the player
1275
1276         lockteams = lockteams_backup;  // restore the team lock
1277
1278         LogTeamchange(client.playerid, client.team, type);
1279 }