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