]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_player.qc
Rename anindecide_init to animdecide_load_if_needed (clearer).
[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         if (!(self.flags & FL_GODMODE))
178         {
179                 self.armorvalue = self.armorvalue - save;
180                 self.health = self.health - take;
181                 // pause regeneration for 5 seconds
182                 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
183         }
184         self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
185         self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
186         self.dmg_inflictor = inflictor;
187
188         if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
189         {
190                 // don't use any animations as a gib
191                 self.frame = 0;
192                 // view just above the floor
193                 self.view_ofs = '0 0 4';
194
195                 Violence_GibSplash(self, 1, 1, attacker);
196                 self.alpha = -1;
197                 self.solid = SOLID_NOT; // restore later
198                 self.takedamage = DAMAGE_NO; // restore later
199                 self.damagedbycontents = FALSE;
200         }
201 }
202
203 // g_<gametype>_str:
204 // If 0, default is used.
205 // If <0, 0 is used.
206 // Otherwise, g_str (default value) is used.
207 // For consistency, negative values there are mapped to zero too.
208 #define GAMETYPE_DEFAULTED_SETTING(str) \
209         ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
210          (gametype_setting_tmp < 0) ? 0 : \
211          (gametype_setting_tmp == 0) ? max(0, autocvar_g_##str) : \
212          gametype_setting_tmp)
213
214
215 void calculate_player_respawn_time()
216 {
217         if(g_ca)
218                 return;
219
220         float gametype_setting_tmp;
221         float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
222         float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
223         float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
224         float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
225         float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
226         float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
227
228         float pcount = 1;  // Include myself whether or not team is already set right and I'm a "player".
229         entity pl;
230         if (teamplay)
231         {
232                 FOR_EACH_PLAYER(pl)
233                         if (pl != self)
234                                 if (pl.team == self.team)
235                                         ++pcount;
236                 if (sdelay_small_count == 0)
237                         sdelay_small_count = 1;
238                 if (sdelay_large_count == 0)
239                         sdelay_large_count = 1;
240         }
241         else
242         {
243                 FOR_EACH_PLAYER(pl)
244                         if (pl != self)
245                                 ++pcount;
246                 if (sdelay_small_count == 0)
247                 {
248                         if (g_cts)
249                         {
250                                 // Players play independently. No point in requiring enemies.
251                                 sdelay_small_count = 1;
252                         }
253                         else
254                         {
255                                 // Players play AGAINST each other. Enemies required.
256                                 sdelay_small_count = 2;
257                         }
258                 }
259                 if (sdelay_large_count == 0)
260                 {
261                         if (g_cts)
262                         {
263                                 // Players play independently. No point in requiring enemies.
264                                 sdelay_large_count = 1;
265                         }
266                         else
267                         {
268                                 // Players play AGAINST each other. Enemies required.
269                                 sdelay_large_count = 2;
270                         }
271                 }
272         }
273
274         float sdelay;
275
276         if (pcount <= sdelay_small_count)
277                 sdelay = sdelay_small;
278         else if (pcount >= sdelay_large_count)
279                 sdelay = sdelay_large;
280         else  // NOTE: this case implies sdelay_large_count > sdelay_small_count.
281                 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
282
283         if(waves)
284                 self.respawn_time = ceil((time + sdelay) / waves) * waves;
285         else
286                 self.respawn_time = time + sdelay;
287
288         if(sdelay < sdelay_max)
289                 self.respawn_time_max = time + sdelay_max;
290         else
291                 self.respawn_time_max = self.respawn_time;
292
293         if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
294                 self.respawn_countdown = 10; // first number to count down from is 10
295         else
296                 self.respawn_countdown = -1; // do not count down
297
298         if(autocvar_g_forced_respawn)
299                 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
300 }
301
302 void ClientKill_Now_TeamChange();
303
304 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
305 {
306         float take, save, dh, da, j;
307         vector v;
308         float valid_damage_for_weaponstats;
309         float excess;
310
311         dh = max(self.health, 0);
312         da = max(self.armorvalue, 0);
313
314         if(!DEATH_ISSPECIAL(deathtype))
315         {
316                 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
317                 if(self != attacker)
318                         damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
319         }
320
321         if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
322         {
323                 // tuba causes blood to come out of the ears
324                 vector ear1, ear2;
325                 vector d;
326                 float f;
327                 ear1 = self.origin;
328                 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
329                 ear2 = ear1;
330                 makevectors(self.angles);
331                 ear1 += v_right * -10;
332                 ear2 += v_right * +10;
333                 d = inflictor.origin - self.origin;
334                 if (d)
335                         f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
336                 else
337                         f = 0;  // Assum ecenter.
338                 force = v_right * vlen(force);
339                 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
340                 Violence_GibSplash_At(ear2, force,      2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
341                 if(f > 0)
342                 {
343                         hitloc = ear1;
344                         force = force * -1;
345                 }
346                 else
347                 {
348                         hitloc = ear2;
349                         // force is already good
350                 }
351         }
352         else
353                 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
354
355
356         v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
357         take = v_x;
358         save = v_y;
359
360         if(attacker == self)
361         {
362                 // don't reset pushltime for self damage as it may be an attempt to
363                 // escape a lava pit or similar
364                 //self.pushltime = 0;
365                 self.istypefrag = 0;
366         }
367         else if(IS_PLAYER(attacker))
368         {
369                 self.pusher = attacker;
370                 self.pushltime = time + autocvar_g_maxpushtime;
371                 self.istypefrag = self.BUTTON_CHAT;
372         }
373         else if(time < self.pushltime)
374         {
375                 attacker = self.pusher;
376                 self.pushltime = max(self.pushltime, time + 0.6);
377         }
378         else
379         {
380                 self.pushltime = 0;
381                 self.istypefrag = 0;
382         }
383
384         frag_inflictor = inflictor;
385         frag_attacker = attacker;
386         frag_target = self;
387         frag_damage = damage;
388         damage_take = take;
389         damage_save = save;
390         damage_force = force;
391         MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
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         }
498
499         if (self.health < 1)
500         {
501                 float defer_ClientKill_Now_TeamChange;
502                 defer_ClientKill_Now_TeamChange = FALSE;
503
504                 if(self.alivetime)
505                 {
506                         PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
507                         self.alivetime = 0;
508                 }
509
510                 if(valid_damage_for_weaponstats)
511                         WeaponStats_LogKill(awep, abot, self.weapon, vbot);
512
513                 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
514                 if(sound_allowed(MSG_BROADCAST, attacker))
515                 {
516                         if(deathtype == DEATH_DROWN)
517                                 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
518                         else
519                                 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
520                 }
521
522                 // get rid of kill indicator
523                 if(self.killindicator)
524                 {
525                         remove(self.killindicator);
526                         self.killindicator = world;
527                         if(self.killindicator_teamchange)
528                                 defer_ClientKill_Now_TeamChange = TRUE;
529
530                         if(self.classname == "body")
531                         if(deathtype == DEATH_KILL)
532                         {
533                                 // for the lemmings fans, a small harmless explosion
534                                 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
535                         }
536                 }
537
538                 // print an obituary message
539                 if(self.classname != "body")
540                         Obituary (attacker, inflictor, self, deathtype);
541
542         // increment frag counter for used weapon type
543         float w;
544         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                 frag_attacker = attacker;
550                 frag_inflictor = inflictor;
551                 frag_target = self;
552                 frag_deathtype = deathtype;
553                 MUTATOR_CALLHOOK(PlayerDies);
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                 // set up to fade out later
618                 SUB_SetFade (self, time + 6 + random (), 1);
619
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) {
629                         // remove corpse
630                         PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
631                 }
632
633                 // reset fields the weapons may use just in case
634                 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
635                 {
636                         WEP_ACTION(j, WR_RESETPLAYER);
637                         ATTACK_FINISHED_FOR(self, j) = 0;
638                 }
639         }
640 }
641
642 .float muted; // to be used by prvm_edictset server playernumber muted 1
643 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
644 // message "": do not say, just test flood control
645 // return value:
646 //   1 = accept
647 //   0 = reject
648 //  -1 = fake accept
649 {
650         string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
651         float flood;
652         var .float flood_field;
653         entity head;
654         float ret;
655         string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
656
657         if(!teamsay && !privatesay)
658                 if(substring(msgin, 0, 1) == " ")
659                         msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
660
661         msgin = formatmessage(msgin);
662
663         if (!IS_PLAYER(source))
664                 colorstr = "^0"; // black for spectators
665         else if(teamplay)
666                 colorstr = Team_ColorCode(source.team);
667         else
668         {
669                 colorstr = "";
670                 teamsay = FALSE;
671         }
672
673         if(intermission_running)
674                 teamsay = FALSE;
675
676         if(msgin != "")
677                 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
678
679         /*
680          * using bprint solves this... me stupid
681         // how can we prevent the message from appearing in a listen server?
682         // for now, just give "say" back and only handle say_team
683         if(!teamsay)
684         {
685                 clientcommand(self, strcat("say ", msgin));
686                 return;
687         }
688         */
689
690         if(autocvar_g_chat_teamcolors)
691                 namestr = playername(source);
692         else
693                 namestr = source.netname;
694
695         if(strdecolorize(namestr) == namestr)
696                 colorprefix = "^3";
697         else
698                 colorprefix = "^7";
699
700         if(msgin != "")
701         {
702                 if(privatesay)
703                 {
704                         msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
705                         privatemsgprefixlen = strlen(msgstr);
706                         msgstr = strcat(msgstr, msgin);
707                         cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
708                         if(autocvar_g_chat_teamcolors)
709                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
710                         else
711                                 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
712                 }
713                 else if(teamsay)
714                 {
715                         msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
716                         cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
717                 }
718                 else
719                 {
720                         msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
721                         cmsgstr = "";
722                 }
723                 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
724         }
725         else
726         {
727                 msgstr = cmsgstr = "";
728         }
729
730         fullmsgstr = msgstr;
731         fullcmsgstr = cmsgstr;
732
733         // FLOOD CONTROL
734         flood = 0;
735         flood_field = floodcontrol_chat;
736         if(floodcontrol)
737         {
738                 float flood_spl;
739                 float flood_burst;
740                 float flood_lmax;
741                 float lines;
742                 if(privatesay)
743                 {
744                         flood_spl = autocvar_g_chat_flood_spl_tell;
745                         flood_burst = autocvar_g_chat_flood_burst_tell;
746                         flood_lmax = autocvar_g_chat_flood_lmax_tell;
747                         flood_field = floodcontrol_chattell;
748                 }
749                 else if(teamsay)
750                 {
751                         flood_spl = autocvar_g_chat_flood_spl_team;
752                         flood_burst = autocvar_g_chat_flood_burst_team;
753                         flood_lmax = autocvar_g_chat_flood_lmax_team;
754                         flood_field = floodcontrol_chatteam;
755                 }
756                 else
757                 {
758                         flood_spl = autocvar_g_chat_flood_spl;
759                         flood_burst = autocvar_g_chat_flood_burst;
760                         flood_lmax = autocvar_g_chat_flood_lmax;
761                         flood_field = floodcontrol_chat;
762                 }
763                 flood_burst = max(0, flood_burst - 1);
764                 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
765
766                 // do flood control for the default line size
767                 if(msgstr != "")
768                 {
769                         getWrappedLine_remaining = msgstr;
770                         msgstr = "";
771                         lines = 0;
772                         while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
773                         {
774                                 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
775                                 ++lines;
776                         }
777                         msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
778
779                         if(getWrappedLine_remaining != "")
780                         {
781                                 msgstr = strcat(msgstr, "\n");
782                                 flood = 2;
783                         }
784
785                         if(time >= source.flood_field)
786                         {
787                                 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
788                         }
789                         else
790                         {
791                                 flood = 1;
792                                 msgstr = fullmsgstr;
793                         }
794                 }
795                 else
796                 {
797                         if(time >= source.flood_field)
798                                 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
799                         else
800                                 flood = 1;
801                 }
802
803                 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
804                         source.flood_field = flood = 0;
805         }
806
807         if(flood == 2) // cannot happen for empty msgstr
808         {
809                 if(autocvar_g_chat_flood_notify_flooder)
810                 {
811                         sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
812                         sourcecmsgstr = "";
813                 }
814                 else
815                 {
816                         sourcemsgstr = fullmsgstr;
817                         sourcecmsgstr = fullcmsgstr;
818                 }
819                 cmsgstr = "";
820         }
821         else
822         {
823                 sourcemsgstr = msgstr;
824                 sourcecmsgstr = cmsgstr;
825         }
826
827         if(!privatesay)
828         if (!IS_PLAYER(source))
829         {
830                 if (!intermission_running)
831                         if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
832                                 teamsay = -1; // spectators
833         }
834
835         if(flood)
836                 print("NOTE: ", playername(source), "^7 is flooding.\n");
837
838         // build sourcemsgstr by cutting off a prefix and replacing it by the other one
839         if(privatesay)
840                 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
841
842         if(source.muted)
843         {
844                 // always fake the message
845                 ret = -1;
846         }
847         else if(flood == 1)
848         {
849                 if(autocvar_g_chat_flood_notify_flooder)
850                 {
851                         sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
852                         ret = 0;
853                 }
854                 else
855                         ret = -1;
856         }
857         else
858         {
859                 ret = 1;
860         }
861
862         if(sourcemsgstr != "" && ret != 0)
863         {
864                 if(ret < 0) // faked message, because the player is muted
865                 {
866                         sprint(source, sourcemsgstr);
867                         if(sourcecmsgstr != "" && !privatesay)
868                                 centerprint(source, sourcecmsgstr);
869                 }
870                 else if(privatesay) // private message, between 2 people only
871                 {
872                         sprint(source, sourcemsgstr);
873                         sprint(privatesay, msgstr);
874                         if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
875                         if(cmsgstr != "")
876                                 centerprint(privatesay, cmsgstr);
877                 }
878                 else if(teamsay > 0) // team message, only sent to team mates
879                 {
880                         sprint(source, sourcemsgstr);
881                         dedicated_print(msgstr); // send to server console too
882                         if(sourcecmsgstr != "")
883                                 centerprint(source, sourcecmsgstr);
884                         FOR_EACH_REALPLAYER(head) if(head.team == source.team)
885                                 if(head != source)
886                                 {
887                                         sprint(head, msgstr);
888                                         if(cmsgstr != "")
889                                                 centerprint(head, cmsgstr);
890                                 }
891                 }
892                 else if(teamsay < 0) // spectator message, only sent to spectators
893                 {
894                         sprint(source, sourcemsgstr);
895                         dedicated_print(msgstr); // send to server console too
896                         FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
897                                 if(head != source)
898                                         sprint(head, msgstr);
899                 }
900                 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
901                 {
902                         sprint(source, sourcemsgstr);
903                         dedicated_print(msgstr); // send to server console too
904                         FOR_EACH_REALCLIENT(head)
905                                 if(head != source)
906                                         sprint(head, msgstr);
907                 }
908                 else
909                         bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
910         }
911
912         return ret;
913 }
914
915 float GetVoiceMessageVoiceType(string type)
916 {
917         if(type == "taunt")
918                 return VOICETYPE_TAUNT;
919         if(type == "teamshoot")
920                 return VOICETYPE_LASTATTACKER;
921         return VOICETYPE_TEAMRADIO;
922 }
923
924 string allvoicesamples;
925 .string GetVoiceMessageSampleField(string type)
926 {
927         GetPlayerSoundSampleField_notFound = 0;
928         switch(type)
929         {
930 #define _VOICEMSG(m) case #m: return playersound_##m;
931                 ALLVOICEMSGS
932 #undef _VOICEMSG
933         }
934         GetPlayerSoundSampleField_notFound = 1;
935         return playersound_taunt;
936 }
937
938 .string GetPlayerSoundSampleField(string type)
939 {
940         GetPlayerSoundSampleField_notFound = 0;
941         switch(type)
942         {
943 #define _VOICEMSG(m) case #m: return playersound_##m;
944                 ALLPLAYERSOUNDS
945 #undef _VOICEMSG
946         }
947         GetPlayerSoundSampleField_notFound = 1;
948         return playersound_taunt;
949 }
950
951 void PrecacheGlobalSound(string samplestring)
952 {
953         float n, i;
954         tokenize_console(samplestring);
955         n = stof(argv(1));
956         if(n > 0)
957         {
958                 for(i = 1; i <= n; ++i)
959                         precache_sound(strcat(argv(0), ftos(i), ".wav"));
960         }
961         else
962         {
963                 precache_sound(strcat(argv(0), ".wav"));
964         }
965 }
966
967 void PrecachePlayerSounds(string f)
968 {
969         float fh;
970         string s;
971         fh = fopen(f, FILE_READ);
972         if(fh < 0)
973                 return;
974         while((s = fgets(fh)))
975         {
976                 if(tokenize_console(s) != 3)
977                 {
978                         dprint("Invalid sound info line: ", s, "\n");
979                         continue;
980                 }
981                 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
982         }
983         fclose(fh);
984
985         if (!allvoicesamples)
986         {
987 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
988                 ALLVOICEMSGS
989 #undef _VOICEMSG
990                 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
991         }
992 }
993
994 void ClearPlayerSounds()
995 {
996 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
997         ALLPLAYERSOUNDS
998         ALLVOICEMSGS
999 #undef _VOICEMSG
1000 }
1001
1002 float LoadPlayerSounds(string f, float first)
1003 {
1004         float fh;
1005         string s;
1006         var .string field;
1007         fh = fopen(f, FILE_READ);
1008         if(fh < 0)
1009         {
1010                 dprint("Player sound file not found: ", f, "\n");
1011                 return 0;
1012         }
1013         while((s = fgets(fh)))
1014         {
1015                 if(tokenize_console(s) != 3)
1016                         continue;
1017                 field = GetPlayerSoundSampleField(argv(0));
1018                 if(GetPlayerSoundSampleField_notFound)
1019                         field = GetVoiceMessageSampleField(argv(0));
1020                 if(GetPlayerSoundSampleField_notFound)
1021                         continue;
1022                 if(self.field)
1023                         strunzone(self.field);
1024                 self.field = strzone(strcat(argv(1), " ", argv(2)));
1025         }
1026         fclose(fh);
1027         return 1;
1028 }
1029
1030 .float modelindex_for_playersound;
1031 .float skin_for_playersound;
1032 void UpdatePlayerSounds()
1033 {
1034         if(self.modelindex == self.modelindex_for_playersound)
1035         if(self.skin == self.skin_for_playersound)
1036                 return;
1037         self.modelindex_for_playersound = self.modelindex;
1038         self.skin_for_playersound = self.skin;
1039         ClearPlayerSounds();
1040         LoadPlayerSounds("sound/player/default.sounds", 1);
1041         if(!autocvar_g_debug_defaultsounds)
1042                 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1043                         LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1044 }
1045
1046 void FakeGlobalSound(string sample, float chan, float voicetype)
1047 {
1048         float n;
1049         float tauntrand;
1050
1051         if(sample == "")
1052                 return;
1053
1054         tokenize_console(sample);
1055         n = stof(argv(1));
1056         if(n > 0)
1057                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1058         else
1059                 sample = strcat(argv(0), ".wav"); // randomization
1060
1061         switch(voicetype)
1062         {
1063                 case VOICETYPE_LASTATTACKER_ONLY:
1064                         break;
1065                 case VOICETYPE_LASTATTACKER:
1066                         if(self.pusher)
1067                         {
1068                                 msg_entity = self;
1069                                 if(IS_REAL_CLIENT(msg_entity))
1070                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1071                         }
1072                         break;
1073                 case VOICETYPE_TEAMRADIO:
1074                         msg_entity = self;
1075                         if(msg_entity.cvar_cl_voice_directional == 1)
1076                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1077                         else
1078                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1079                         break;
1080                 case VOICETYPE_AUTOTAUNT:
1081                         if(!sv_autotaunt)
1082                                 break;
1083                         if(!sv_taunt)
1084                                 break;
1085                         if(autocvar_sv_gentle)
1086                                 break;
1087                         tauntrand = random();
1088                         msg_entity = self;
1089                         if (tauntrand < msg_entity.cvar_cl_autotaunt)
1090                         {
1091                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1092                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1093                                 else
1094                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1095                         }
1096                         break;
1097                 case VOICETYPE_TAUNT:
1098                         if(IS_PLAYER(self))
1099                                 if(self.deadflag == DEAD_NO)
1100                                         animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1101                         if(!sv_taunt)
1102                                 break;
1103                         if(autocvar_sv_gentle)
1104                                 break;
1105                         msg_entity = self;
1106                         if (msg_entity.cvar_cl_voice_directional >= 1)
1107                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1108                         else
1109                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1110                         break;
1111                 case VOICETYPE_PLAYERSOUND:
1112                         msg_entity = self;
1113                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1114                         break;
1115                 default:
1116                         backtrace("Invalid voice type!");
1117                         break;
1118         }
1119 }
1120
1121 void GlobalSound(string sample, float chan, float voicetype)
1122 {
1123         float n;
1124         float tauntrand;
1125
1126         if(sample == "")
1127                 return;
1128
1129         tokenize_console(sample);
1130         n = stof(argv(1));
1131         if(n > 0)
1132                 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1133         else
1134                 sample = strcat(argv(0), ".wav"); // randomization
1135
1136         switch(voicetype)
1137         {
1138                 case VOICETYPE_LASTATTACKER_ONLY:
1139                         if(self.pusher)
1140                         {
1141                                 msg_entity = self.pusher;
1142                                 if(IS_REAL_CLIENT(msg_entity))
1143                                 {
1144                                         if(msg_entity.cvar_cl_voice_directional == 1)
1145                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1146                                         else
1147                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1148                                 }
1149                         }
1150                         break;
1151                 case VOICETYPE_LASTATTACKER:
1152                         if(self.pusher)
1153                         {
1154                                 msg_entity = self.pusher;
1155                                 if(IS_REAL_CLIENT(msg_entity))
1156                                 {
1157                                         if(msg_entity.cvar_cl_voice_directional == 1)
1158                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1159                                         else
1160                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1161                                 }
1162                                 msg_entity = self;
1163                                 if(IS_REAL_CLIENT(msg_entity))
1164                                         soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1165                         }
1166                         break;
1167                 case VOICETYPE_TEAMRADIO:
1168                         FOR_EACH_REALCLIENT(msg_entity)
1169                                 if(!teamplay || msg_entity.team == self.team)
1170                                 {
1171                                         if(msg_entity.cvar_cl_voice_directional == 1)
1172                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1173                                         else
1174                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1175                                 }
1176                         break;
1177                 case VOICETYPE_AUTOTAUNT:
1178                         if(!sv_autotaunt)
1179                                 break;
1180                         if(!sv_taunt)
1181                                 break;
1182                         if(autocvar_sv_gentle)
1183                                 break;
1184                         tauntrand = random();
1185                         FOR_EACH_REALCLIENT(msg_entity)
1186                                 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1187                                 {
1188                                         if (msg_entity.cvar_cl_voice_directional >= 1)
1189                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1190                                         else
1191                                                 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1192                                 }
1193                         break;
1194                 case VOICETYPE_TAUNT:
1195                         if(IS_PLAYER(self))
1196                                 if(self.deadflag == DEAD_NO)
1197                                         animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1198                         if(!sv_taunt)
1199                                 break;
1200                         if(autocvar_sv_gentle)
1201                                 break;
1202                         FOR_EACH_REALCLIENT(msg_entity)
1203                         {
1204                                 if (msg_entity.cvar_cl_voice_directional >= 1)
1205                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1206                                 else
1207                                         soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1208                         }
1209                         break;
1210                 case VOICETYPE_PLAYERSOUND:
1211                         sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1212                         break;
1213                 default:
1214                         backtrace("Invalid voice type!");
1215                         break;
1216         }
1217 }
1218
1219 void PlayerSound(.string samplefield, float chan, float voicetype)
1220 {
1221         GlobalSound(self.samplefield, chan, voicetype);
1222 }
1223
1224 void VoiceMessage(string type, string msg)
1225 {
1226         var .string sample;
1227         float voicetype, ownteam;
1228         float flood;
1229         sample = GetVoiceMessageSampleField(type);
1230
1231         if(GetPlayerSoundSampleField_notFound)
1232         {
1233                 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1234                 return;
1235         }
1236
1237         voicetype = GetVoiceMessageVoiceType(type);
1238         ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1239
1240         flood = Say(self, ownteam, world, msg, 1);
1241
1242         if(IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1243                 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1244         else if (flood > 0)
1245                 GlobalSound(self.sample, CH_VOICE, voicetype);
1246 }
1247
1248 void MoveToTeam(entity client, float team_colour, float type)
1249 {
1250         float lockteams_backup;
1251
1252         lockteams_backup = lockteams;  // backup any team lock
1253
1254         lockteams = 0;  // disable locked teams
1255
1256         TeamchangeFrags(client);  // move the players frags
1257         SetPlayerColors(client, team_colour - 1);  // set the players colour
1258         Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0');  // kill the player
1259
1260         lockteams = lockteams_backup;  // restore the team lock
1261
1262         LogTeamchange(client.playerid, client.team, type);
1263 }