Weapons: remove WEP_ACTION
[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, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
186                 else if (take > 30)
187                         sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
188                 else if (take > 10)
189                         sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
190         }
191
192         if (take > 50)
193                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
194         if (take > 100)
195                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
196
197         self.armorvalue = self.armorvalue - save;
198         self.health = self.health - take;
199         // pause regeneration for 5 seconds
200         self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
201
202         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
203         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
204         self.dmg_inflictor = inflictor;
205
206         if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
207         {
208                 // don't use any animations as a gib
209                 self.frame = 0;
210                 // view just above the floor
211                 self.view_ofs = '0 0 4';
212
213                 Violence_GibSplash(self, 1, 1, attacker);
214                 self.alpha = -1;
215                 self.solid = SOLID_NOT; // restore later
216                 self.takedamage = DAMAGE_NO; // restore later
217                 self.damagedbycontents = false;
218         }
219 }
220
221 void calculate_player_respawn_time()
222 {SELFPARAM();
223         if(g_ca)
224                 return;
225
226         float gametype_setting_tmp;
227         float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
228         float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
229         float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
230         float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
231         float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
232         float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
233
234         float pcount = 1;  // Include myself whether or not team is already set right and I'm a "player".
235         entity pl;
236         if (teamplay)
237         {
238                 FOR_EACH_PLAYER(pl)
239                         if (pl != self)
240                                 if (pl.team == self.team)
241                                         ++pcount;
242                 if (sdelay_small_count == 0)
243                         sdelay_small_count = 1;
244                 if (sdelay_large_count == 0)
245                         sdelay_large_count = 1;
246         }
247         else
248         {
249                 FOR_EACH_PLAYER(pl)
250                         if (pl != self)
251                                 ++pcount;
252                 if (sdelay_small_count == 0)
253                 {
254                         if (g_cts)
255                         {
256                                 // Players play independently. No point in requiring enemies.
257                                 sdelay_small_count = 1;
258                         }
259                         else
260                         {
261                                 // Players play AGAINST each other. Enemies required.
262                                 sdelay_small_count = 2;
263                         }
264                 }
265                 if (sdelay_large_count == 0)
266                 {
267                         if (g_cts)
268                         {
269                                 // Players play independently. No point in requiring enemies.
270                                 sdelay_large_count = 1;
271                         }
272                         else
273                         {
274                                 // Players play AGAINST each other. Enemies required.
275                                 sdelay_large_count = 2;
276                         }
277                 }
278         }
279
280         float sdelay;
281
282         if (pcount <= sdelay_small_count)
283                 sdelay = sdelay_small;
284         else if (pcount >= sdelay_large_count)
285                 sdelay = sdelay_large;
286         else  // NOTE: this case implies sdelay_large_count > sdelay_small_count.
287                 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
288
289         if(waves)
290                 self.respawn_time = ceil((time + sdelay) / waves) * waves;
291         else
292                 self.respawn_time = time + sdelay;
293
294         if(sdelay < sdelay_max)
295                 self.respawn_time_max = time + sdelay_max;
296         else
297                 self.respawn_time_max = self.respawn_time;
298
299         if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
300                 self.respawn_countdown = 10; // first number to count down from is 10
301         else
302                 self.respawn_countdown = -1; // do not count down
303
304         if(autocvar_g_forced_respawn)
305                 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
306 }
307
308 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
309 {SELFPARAM();
310         float take, save, dh, da;
311         int j;
312         vector v;
313         float valid_damage_for_weaponstats;
314         float excess;
315
316         dh = max(self.health, 0);
317         da = max(self.armorvalue, 0);
318
319         if(!DEATH_ISSPECIAL(deathtype))
320         {
321                 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
322                 if(self != attacker)
323                         damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
324         }
325
326         if(DEATH_ISWEAPON(deathtype, WEP_TUBA.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, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
399                 else if (take > 30)
400                         sound (self, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
401                 else if (take > 10)
402                         sound (self, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
403         }
404
405         if (take > 50)
406                 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
407         if (take > 100)
408                 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
409
410         if (time >= self.spawnshieldtime)
411         {
412                 if (!(self.flags & FL_GODMODE))
413                 {
414                         self.armorvalue = self.armorvalue - save;
415                         self.health = self.health - take;
416                         // pause regeneration for 5 seconds
417                         if(take)
418                                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
419
420                         if (time > self.pain_finished)          //Don't switch pain sequences like crazy
421                         {
422                                 self.pain_finished = time + 0.5;        //Supajoe
423
424                                 if(autocvar_sv_gentle < 1) {
425                                         if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
426                                         {
427                                                 if (!self.animstate_override)
428                                                 {
429                                                         if (random() > 0.5)
430                                                                 animdecide_setaction(self, ANIMACTION_PAIN1, true);
431                                                         else
432                                                                 animdecide_setaction(self, ANIMACTION_PAIN2, true);
433                                                 }
434                                         }
435
436                                         if(sound_allowed(MSG_BROADCAST, attacker))
437                                         if((self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !((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                 Weapon wep = get_weaponinfo(self.weapon);
552                 wep.wr_playerdeath(wep);
553
554                 RemoveGrapplingHook(self);
555
556                 Portal_ClearAllLater(self);
557
558                 self.fixangle = true;
559
560                 if(defer_ClientKill_Now_TeamChange)
561                         ClientKill_Now_TeamChange(); // can turn player into spectator
562
563                 // player could have been miraculously resuscitated ;)
564                 // e.g. players in freezetag get frozen, they don't really die
565                 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
566                         return;
567
568                 // when we get here, player actually dies
569
570                 Unfreeze(self); // remove any icy remains
571                 self.health = 0; // Unfreeze resets health, so we need to set it back
572
573                 // clear waypoints
574                 WaypointSprite_PlayerDead();
575                 // throw a weapon
576                 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
577
578                 // become fully visible
579                 self.alpha = default_player_alpha;
580                 // make the corpse upright (not tilted)
581                 self.angles_x = 0;
582                 self.angles_z = 0;
583                 // don't spin
584                 self.avelocity = '0 0 0';
585                 // view from the floor
586                 self.view_ofs = '0 0 -8';
587                 // toss the corpse
588                 self.movetype = MOVETYPE_TOSS;
589                 // shootable corpse
590                 self.solid = SOLID_CORPSE;
591                 self.ballistics_density = autocvar_g_ballistics_density_corpse;
592                 // don't stick to the floor
593                 self.flags &= ~FL_ONGROUND;
594                 // dying animation
595                 self.deadflag = DEAD_DYING;
596
597                 // when to allow respawn
598                 calculate_player_respawn_time();
599
600                 self.death_time = time;
601                 if (random() < 0.5)
602                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
603                 else
604                         animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
605                 if (self.maxs.z > 5)
606                 {
607                         self.maxs_z = 5;
608                         setsize(self, self.mins, self.maxs);
609                 }
610                 // set damage function to corpse damage
611                 self.event_damage = PlayerCorpseDamage;
612                 // call the corpse damage function just in case it wants to gib
613                 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
614
615                 // set up to fade out later
616                 SUB_SetFade (self, time + 6 + random (), 1);
617                 // reset body think wrapper broken by SUB_SetFade
618                 if(self.classname == "body" && self.think != CopyBody_Think) {
619                         self.CopyBody_think = self.think;
620                         self.CopyBody_nextthink = self.nextthink;
621                         self.think = CopyBody_Think;
622                         self.nextthink = time;
623                 }
624
625                 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
626                         // remove corpse
627                         // clones don't run any animation code any more, so we must gib them when they die :(
628                         PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
629                 }
630
631                 // reset fields the weapons may use just in case
632                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
633                 {
634                         Weapon w = get_weaponinfo(j);
635                         w.wr_resetplayer(w);
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         int fh = fopen(f, FILE_READ);
992         if (fh < 0)
993                 return;
994         for (string s; (s = fgets(fh)); )
995         {
996                 int n = tokenize_console(s);
997                 if (n != 3)
998                 {
999                         if (n != 0) LOG_TRACEF("Invalid sound info line: %s\n", s);
1000                         continue;
1001                 }
1002                 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1003         }
1004         fclose(fh);
1005
1006         if (!allvoicesamples)
1007         {
1008 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1009                 ALLVOICEMSGS
1010 #undef _VOICEMSG
1011                 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1012         }
1013 }
1014
1015 void ClearPlayerSounds()
1016 {SELFPARAM();
1017 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1018         ALLPLAYERSOUNDS
1019         ALLVOICEMSGS
1020 #undef _VOICEMSG
1021 }
1022
1023 float LoadPlayerSounds(string f, float first)
1024 {SELFPARAM();
1025         float fh;
1026         string s;
1027         var .string field;
1028         fh = fopen(f, FILE_READ);
1029         if(fh < 0)
1030         {
1031                 LOG_TRACE("Player sound file not found: ", f, "\n");
1032                 return 0;
1033         }
1034         while((s = fgets(fh)))
1035         {
1036                 if(tokenize_console(s) != 3)
1037                         continue;
1038                 field = GetPlayerSoundSampleField(argv(0));
1039                 if(GetPlayerSoundSampleField_notFound)
1040                         field = GetVoiceMessageSampleField(argv(0));
1041                 if(GetPlayerSoundSampleField_notFound)
1042                         continue;
1043                 if (self.(field))
1044                         strunzone(self.(field));
1045                 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1046         }
1047         fclose(fh);
1048         return 1;
1049 }
1050
1051 void UpdatePlayerSounds()
1052 {SELFPARAM();
1053         if(self.modelindex == self.modelindex_for_playersound)
1054         if(self.skin == self.skin_for_playersound)
1055                 return;
1056         self.modelindex_for_playersound = self.modelindex;
1057         self.skin_for_playersound = self.skin;
1058         ClearPlayerSounds();
1059         LoadPlayerSounds("sound/player/default.sounds", 1);
1060         if(!autocvar_g_debug_defaultsounds)
1061                 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1062                         LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1063 }
1064
1065 void FakeGlobalSound(string sample, float chan, float voicetype)
1066 {SELFPARAM();
1067         float n;
1068         float tauntrand;
1069
1070         if(sample == "")
1071                 return;
1072
1073         tokenize_console(sample);
1074         n = stof(argv(1));
1075         if(n > 0)
1076                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1077         else
1078                 sample = strcat(argv(0), ".wav"); // randomization
1079
1080         switch(voicetype)
1081         {
1082                 case VOICETYPE_LASTATTACKER_ONLY:
1083                         break;
1084                 case VOICETYPE_LASTATTACKER:
1085                         if(self.pusher)
1086                         {
1087                                 msg_entity = self;
1088                                 if(IS_REAL_CLIENT(msg_entity))
1089                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1090                         }
1091                         break;
1092                 case VOICETYPE_TEAMRADIO:
1093                         msg_entity = self;
1094                         if(msg_entity.cvar_cl_voice_directional == 1)
1095                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1096                         else
1097                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1098                         break;
1099                 case VOICETYPE_AUTOTAUNT:
1100                         if(!sv_autotaunt)
1101                                 break;
1102                         if(!sv_taunt)
1103                                 break;
1104                         if(autocvar_sv_gentle)
1105                                 break;
1106                         tauntrand = random();
1107                         msg_entity = self;
1108                         if (tauntrand < msg_entity.cvar_cl_autotaunt)
1109                         {
1110                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1111                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1112                                 else
1113                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1114                         }
1115                         break;
1116                 case VOICETYPE_TAUNT:
1117                         if(IS_PLAYER(self))
1118                                 if(self.deadflag == DEAD_NO)
1119                                         animdecide_setaction(self, ANIMACTION_TAUNT, true);
1120                         if(!sv_taunt)
1121                                 break;
1122                         if(autocvar_sv_gentle)
1123                                 break;
1124                         msg_entity = self;
1125                         if (msg_entity.cvar_cl_voice_directional >= 1)
1126                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1127                         else
1128                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1129                         break;
1130                 case VOICETYPE_PLAYERSOUND:
1131                         msg_entity = self;
1132                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1133                         break;
1134                 default:
1135                         backtrace("Invalid voice type!");
1136                         break;
1137         }
1138 }
1139
1140 void GlobalSound(string sample, float chan, float voicetype)
1141 {SELFPARAM();
1142         float n;
1143         float tauntrand;
1144
1145         if(sample == "")
1146                 return;
1147
1148         tokenize_console(sample);
1149         n = stof(argv(1));
1150         if(n > 0)
1151                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1152         else
1153                 sample = strcat(argv(0), ".wav"); // randomization
1154
1155         switch(voicetype)
1156         {
1157                 case VOICETYPE_LASTATTACKER_ONLY:
1158                         if(self.pusher)
1159                         {
1160                                 msg_entity = self.pusher;
1161                                 if(IS_REAL_CLIENT(msg_entity))
1162                                 {
1163                                         if(msg_entity.cvar_cl_voice_directional == 1)
1164                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1165                                         else
1166                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1167                                 }
1168                         }
1169                         break;
1170                 case VOICETYPE_LASTATTACKER:
1171                         if(self.pusher)
1172                         {
1173                                 msg_entity = self.pusher;
1174                                 if(IS_REAL_CLIENT(msg_entity))
1175                                 {
1176                                         if(msg_entity.cvar_cl_voice_directional == 1)
1177                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1178                                         else
1179                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1180                                 }
1181                                 msg_entity = self;
1182                                 if(IS_REAL_CLIENT(msg_entity))
1183                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1184                         }
1185                         break;
1186                 case VOICETYPE_TEAMRADIO:
1187                         FOR_EACH_REALCLIENT(msg_entity)
1188                                 if(!teamplay || msg_entity.team == self.team)
1189                                 {
1190                                         if(msg_entity.cvar_cl_voice_directional == 1)
1191                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1192                                         else
1193                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1194                                 }
1195                         break;
1196                 case VOICETYPE_AUTOTAUNT:
1197                         if(!sv_autotaunt)
1198                                 break;
1199                         if(!sv_taunt)
1200                                 break;
1201                         if(autocvar_sv_gentle)
1202                                 break;
1203                         tauntrand = random();
1204                         FOR_EACH_REALCLIENT(msg_entity)
1205                                 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1206                                 {
1207                                         if (msg_entity.cvar_cl_voice_directional >= 1)
1208                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1209                                         else
1210                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1211                                 }
1212                         break;
1213                 case VOICETYPE_TAUNT:
1214                         if(IS_PLAYER(self))
1215                                 if(self.deadflag == DEAD_NO)
1216                                         animdecide_setaction(self, ANIMACTION_TAUNT, true);
1217                         if(!sv_taunt)
1218                                 break;
1219                         if(autocvar_sv_gentle)
1220                                 break;
1221                         FOR_EACH_REALCLIENT(msg_entity)
1222                         {
1223                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1224                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1225                                 else
1226                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1227                         }
1228                         break;
1229                 case VOICETYPE_PLAYERSOUND:
1230                         _sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1231                         break;
1232                 default:
1233                         backtrace("Invalid voice type!");
1234                         break;
1235         }
1236 }
1237
1238 void PlayerSound(.string samplefield, float chan, float voicetype)
1239 {SELFPARAM();
1240         GlobalSound(self.(samplefield), chan, voicetype);
1241 }
1242
1243 void VoiceMessage(string type, string msg)
1244 {SELFPARAM();
1245         float voicetype, ownteam;
1246         float flood;
1247         var .string sample = GetVoiceMessageSampleField(type);
1248
1249         if(GetPlayerSoundSampleField_notFound)
1250         {
1251                 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1252                 return;
1253         }
1254
1255         voicetype = GetVoiceMessageVoiceType(type);
1256         ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1257
1258         flood = Say(self, ownteam, world, msg, 1);
1259
1260         if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1261                 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1262         else if (flood > 0)
1263                 GlobalSound(self.(sample), CH_VOICE, voicetype);
1264 }
1265
1266 void MoveToTeam(entity client, float team_colour, float type)
1267 {
1268         float lockteams_backup;
1269
1270         lockteams_backup = lockteams;  // backup any team lock
1271
1272         lockteams = 0;  // disable locked teams
1273
1274         TeamchangeFrags(client);  // move the players frags
1275         SetPlayerColors(client, team_colour - 1);  // set the players colour
1276         Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0');  // kill the player
1277
1278         lockteams = lockteams_backup;  // restore the team lock
1279
1280         LogTeamchange(client.playerid, client.team, type);
1281 }