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