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