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