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