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