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