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