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