1 #include "cl_player.qh"
7 #include "miscfunctions.qh"
10 #include "weapons/throwing.qh"
11 #include "command/common.qh"
12 #include "../common/anim.qh"
13 #include "../common/animdecide.qh"
14 #include "../common/csqcmodel_settings.qh"
15 #include "../common/deathtypes/all.qh"
16 #include "../common/triggers/subs.qh"
17 #include "../common/playerstats.qh"
18 #include "../lib/csqcmodel/sv_model.qh"
20 #include "../common/minigames/sv_minigames.qh"
22 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
23 #include "../common/triggers/include.qh"
25 #include "weapons/weaponstats.qh"
27 #include "../common/animdecide.qh"
29 void Drop_Special_Items(entity player)
31 // called when the player has become stuck or frozen
32 // so objective items aren't stuck with the player
34 MUTATOR_CALLHOOK(DropSpecialItems, player);
39 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
41 self.CopyBody_think();
44 self.CopyBody_nextthink = self.nextthink;
45 self.CopyBody_think = self.think;
46 self.think = CopyBody_Think;
48 CSQCMODEL_AUTOUPDATE(self);
49 self.nextthink = time;
51 void CopyBody(entity this, float keepvelocity)
53 if (this.effects & EF_NODRAW)
55 entity clone = new(body);
58 clone.colormap = this.colormap;
59 clone.iscreature = this.iscreature;
60 clone.teleportable = this.teleportable;
61 clone.damagedbycontents = this.damagedbycontents;
62 clone.angles = this.angles;
63 clone.v_angle = this.v_angle;
64 clone.avelocity = this.avelocity;
65 clone.damageforcescale = this.damageforcescale;
66 clone.effects = this.effects;
67 clone.glowmod = this.glowmod;
68 clone.event_damage = this.event_damage;
69 clone.anim_state = this.anim_state;
70 clone.anim_time = this.anim_time;
71 clone.anim_lower_action = this.anim_lower_action;
72 clone.anim_lower_time = this.anim_lower_time;
73 clone.anim_upper_action = this.anim_upper_action;
74 clone.anim_upper_time = this.anim_upper_time;
75 clone.anim_implicit_state = this.anim_implicit_state;
76 clone.anim_implicit_time = this.anim_implicit_time;
77 clone.anim_lower_implicit_action = this.anim_lower_implicit_action;
78 clone.anim_lower_implicit_time = this.anim_lower_implicit_time;
79 clone.anim_upper_implicit_action = this.anim_upper_implicit_action;
80 clone.anim_upper_implicit_time = this.anim_upper_implicit_time;
81 clone.dphitcontentsmask = this.dphitcontentsmask;
82 clone.death_time = this.death_time;
83 clone.pain_finished = this.pain_finished;
84 clone.health = this.health;
85 clone.armorvalue = this.armorvalue;
86 clone.armortype = this.armortype;
87 clone.model = this.model;
88 clone.modelindex = this.modelindex;
89 clone.skin = this.skin;
90 clone.species = this.species;
91 clone.movetype = this.movetype;
92 clone.solid = this.solid;
93 clone.ballistics_density = this.ballistics_density;
94 clone.takedamage = this.takedamage;
95 clone.customizeentityforclient = this.customizeentityforclient;
96 clone.uncustomizeentityforclient = this.uncustomizeentityforclient;
97 clone.uncustomizeentityforclient_set = this.uncustomizeentityforclient_set;
98 if (keepvelocity == 1)
99 clone.velocity = this.velocity;
100 clone.oldvelocity = clone.velocity;
101 clone.alpha = this.alpha;
102 clone.fade_time = this.fade_time;
103 clone.fade_rate = this.fade_rate;
104 //clone.weapon = this.weapon;
105 setorigin(clone, this.origin);
106 setsize(clone, this.mins, this.maxs);
107 clone.prevorigin = this.origin;
108 clone.reset = SUB_Remove;
109 clone._ps = this._ps;
111 Drag_MoveDrag(this, clone);
113 if(clone.colormap <= maxclients && clone.colormap > 0)
114 clone.colormap = 1024 + this.clientcolors;
116 CSQCMODEL_AUTOINIT(clone);
117 clone.CopyBody_nextthink = this.nextthink;
118 clone.CopyBody_think = this.think;
119 clone.nextthink = time;
120 clone.think = CopyBody_Think;
121 // "bake" the current animation frame for clones (they don't get clientside animation)
122 animdecide_load_if_needed(clone);
123 animdecide_setframes(clone, false, frame, frame1time, frame2, frame2time);
126 void player_setupanimsformodel()
128 // load animation info
129 animdecide_load_if_needed(self);
130 animdecide_setstate(self, 0, false);
135 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
138 // Decide on which death animation to use.
140 deadbits = ANIMSTATE_DEAD1;
142 deadbits = ANIMSTATE_DEAD2;
145 // Clear a previous death animation.
148 int animbits = deadbits;
149 if(STAT(FROZEN, self))
150 animbits |= ANIMSTATE_FROZEN;
151 if(self.movetype == MOVETYPE_FOLLOW)
152 animbits |= ANIMSTATE_FOLLOW;
154 animbits |= ANIMSTATE_DUCK;
155 animdecide_setstate(self, animbits, false);
156 animdecide_setimplicitstate(self, IS_ONGROUND(self));
159 void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
163 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
165 // damage resistance (ignore most of the damage from a bullet or similar)
166 damage = max(damage - 5, 1);
168 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
172 if(sound_allowed(MSG_BROADCAST, attacker))
175 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
177 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
179 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM);
183 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
185 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
187 this.armorvalue = this.armorvalue - save;
188 this.health = this.health - take;
189 // pause regeneration for 5 seconds
190 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
192 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
193 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
194 this.dmg_inflictor = inflictor;
196 if (this.health <= -autocvar_sv_gibhealth && this.alpha >= 0)
198 // don't use any animations as a gib
200 // view just above the floor
201 this.view_ofs = '0 0 4';
203 Violence_GibSplash(this, 1, 1, attacker);
205 this.solid = SOLID_NOT; // restore later
206 this.takedamage = DAMAGE_NO; // restore later
207 this.damagedbycontents = false;
211 void calculate_player_respawn_time(entity this)
216 float gametype_setting_tmp;
217 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
218 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
219 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
220 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
221 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
222 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
224 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
227 FOREACH_CLIENT(IS_PLAYER(it) && it != this, LAMBDA(
228 if(it.team == this.team)
231 if (sdelay_small_count == 0)
232 sdelay_small_count = 1;
233 if (sdelay_large_count == 0)
234 sdelay_large_count = 1;
238 FOREACH_CLIENT(IS_PLAYER(it) && it != this, LAMBDA(
241 if (sdelay_small_count == 0)
245 // Players play independently. No point in requiring enemies.
246 sdelay_small_count = 1;
250 // Players play AGAINST each other. Enemies required.
251 sdelay_small_count = 2;
254 if (sdelay_large_count == 0)
258 // Players play independently. No point in requiring enemies.
259 sdelay_large_count = 1;
263 // Players play AGAINST each other. Enemies required.
264 sdelay_large_count = 2;
271 if (pcount <= sdelay_small_count)
272 sdelay = sdelay_small;
273 else if (pcount >= sdelay_large_count)
274 sdelay = sdelay_large;
275 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
276 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
279 this.respawn_time = ceil((time + sdelay) / waves) * waves;
281 this.respawn_time = time + sdelay;
283 if(sdelay < sdelay_max)
284 this.respawn_time_max = time + sdelay_max;
286 this.respawn_time_max = this.respawn_time;
288 if((sdelay + waves >= 5.0) && (this.respawn_time - time > 1.75))
289 this.respawn_countdown = 10; // first number to count down from is 10
291 this.respawn_countdown = -1; // do not count down
293 if(autocvar_g_forced_respawn)
294 this.respawn_flags = this.respawn_flags | RESPAWN_FORCE;
297 void PlayerDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
299 float take, save, dh, da;
301 float valid_damage_for_weaponstats;
304 dh = max(this.health, 0);
305 da = max(this.armorvalue, 0);
307 if(!DEATH_ISSPECIAL(deathtype))
309 damage *= sqrt(bound(1.0, this.cvar_cl_handicap, 100.0));
311 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
314 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
316 // tuba causes blood to come out of the ears
321 ear1_z += 0.125 * this.view_ofs.z + 0.875 * this.maxs.z; // 7/8
323 makevectors(this.angles);
324 ear1 += v_right * -10;
325 ear2 += v_right * +10;
326 d = inflictor.origin - this.origin;
328 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
330 f = 0; // Assum ecenter.
331 force = v_right * vlen(force);
332 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), this, attacker);
333 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), this, attacker);
342 // force is already good
346 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, this, attacker);
349 v = healtharmor_applydamage(this.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
355 // don't reset pushltime for this damage as it may be an attempt to
356 // escape a lava pit or similar
357 //this.pushltime = 0;
360 else if(IS_PLAYER(attacker))
362 this.pusher = attacker;
363 this.pushltime = time + autocvar_g_maxpushtime;
364 this.istypefrag = PHYS_INPUT_BUTTON_CHAT(this);
366 else if(time < this.pushltime)
368 attacker = this.pusher;
369 this.pushltime = max(this.pushltime, time + 0.6);
377 if (time < this.spawnshieldtime && autocvar_g_spawnshield_blockdamage < 1)
379 vector v = healtharmor_applydamage(this.armorvalue, max(0, autocvar_g_spawnshield_blockdamage), deathtype, damage);
384 frag_damage = damage;
385 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor, inflictor, attacker, this, force, take, save);
386 take = bound(0, damage_take, this.health);
387 save = bound(0, damage_save, this.armorvalue);
388 excess = max(0, damage - take - save);
390 if(sound_allowed(MSG_BROADCAST, attacker))
393 sound (this, CH_SHOTS, SND_ARMORIMPACT, VOL_BASE, ATTEN_NORM);
395 sound (this, CH_SHOTS, SND_BODYIMPACT2, VOL_BASE, ATTEN_NORM);
397 sound (this, CH_SHOTS, SND_BODYIMPACT1, VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
401 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, this, attacker);
403 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, this, attacker);
405 if (time >= this.spawnshieldtime || autocvar_g_spawnshield_blockdamage < 1)
407 if (!(this.flags & FL_GODMODE))
409 this.armorvalue = this.armorvalue - save;
410 this.health = this.health - take;
411 // pause regeneration for 5 seconds
413 this.pauseregen_finished = max(this.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
415 if (time > this.pain_finished) //Don't switch pain sequences like crazy
417 this.pain_finished = time + 0.5; //Supajoe
419 if(autocvar_sv_gentle < 1) {
420 if(this.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
422 if (!this.animstate_override)
425 animdecide_setaction(this, ANIMACTION_PAIN1, true);
427 animdecide_setaction(this, ANIMACTION_PAIN2, true);
431 if(sound_allowed(MSG_BROADCAST, attacker))
432 if((this.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) || !(DEATH_WEAPONOF(deathtype).spawnflags & WEP_FLAG_CANCLIMB) || attacker != this) // WEAPONTODO: create separate limit for pain notification with laser
434 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
436 if(deathtype == DEATH_FALL.m_id)
437 PlayerSound(this, playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
438 else if(this.health > 75)
439 PlayerSound(this, playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
440 else if(this.health > 50)
441 PlayerSound(this, playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
442 else if(this.health > 25)
443 PlayerSound(this, playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
445 PlayerSound(this, playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
450 // throw off bot aim temporarily
452 if(IS_BOT_CLIENT(this) && this.health >= 1)
454 shake = damage * 5 / (bound(0,skill,100) + 1);
455 this.v_angle_x = this.v_angle.x + (random() * 2 - 1) * shake;
456 this.v_angle_y = this.v_angle.y + (random() * 2 - 1) * shake;
457 this.v_angle_x = bound(-90, this.v_angle.x, 90);
461 this.max_armorvalue += (save + take);
463 this.dmg_save = this.dmg_save + save;//max(save - 10, 0);
464 this.dmg_take = this.dmg_take + take;//max(take - 10, 0);
465 this.dmg_inflictor = inflictor;
467 if (this != attacker) {
468 float realdmg = damage - excess;
469 if (IS_PLAYER(attacker)) {
470 PlayerScore_Add(attacker, SP_DMG, realdmg);
472 if (IS_PLAYER(this)) {
473 PlayerScore_Add(this, SP_DMGTAKEN, realdmg);
477 bool abot = (IS_BOT_CLIENT(attacker));
478 bool vbot = (IS_BOT_CLIENT(this));
480 valid_damage_for_weaponstats = 0;
481 Weapon awep = WEP_Null;
483 if(vbot || IS_REAL_CLIENT(this))
484 if(abot || IS_REAL_CLIENT(attacker))
485 if(attacker && this != attacker)
486 if(DIFF_TEAM(this, attacker))
488 if(DEATH_ISSPECIAL(deathtype))
489 awep = PS(attacker).m_weapon;
491 awep = DEATH_WEAPONOF(deathtype);
492 valid_damage_for_weaponstats = 1;
495 if(valid_damage_for_weaponstats)
497 dh = dh - max(this.health, 0);
498 da = da - max(this.armorvalue, 0);
499 WeaponStats_LogDamage(awep.m_id, abot, PS(this).m_weapon.m_id, vbot, dh + da);
500 MUTATOR_CALLHOOK(PlayerDamaged, attacker, this, dh, da, hitloc, deathtype);
505 float defer_ClientKill_Now_TeamChange;
506 defer_ClientKill_Now_TeamChange = false;
510 PS_GR_P_ADDVAL(this, PLAYERSTATS_ALIVETIME, time - this.alivetime);
514 if(valid_damage_for_weaponstats)
515 WeaponStats_LogKill(awep.m_id, abot, PS(this).m_weapon.m_id, vbot);
517 if(autocvar_sv_gentle < 1)
518 if(sound_allowed(MSG_BROADCAST, attacker))
520 if(deathtype == DEATH_DROWN.m_id)
521 PlayerSound(this, playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
523 PlayerSound(this, playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
526 // get rid of kill indicator
527 if(this.killindicator)
529 remove(this.killindicator);
530 this.killindicator = world;
531 if(this.killindicator_teamchange)
532 defer_ClientKill_Now_TeamChange = true;
534 if(this.classname == "body")
535 if(deathtype == DEATH_KILL.m_id)
537 // for the lemmings fans, a small harmless explosion
538 Send_Effect(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
542 // print an obituary message
543 if(this.classname != "body")
544 Obituary (attacker, inflictor, this, deathtype);
546 // increment frag counter for used weapon type
547 Weapon w = DEATH_WEAPONOF(deathtype);
549 if(accuracy_isgooddamage(attacker, this))
550 attacker.accuracy.(accuracy_frags[w.m_id-1]) += 1;
552 MUTATOR_CALLHOOK(PlayerDies, inflictor, attacker, this, deathtype);
553 excess = frag_damage;
555 Weapon wep = PS(this).m_weapon;
556 WITH(entity, self, this, wep.wr_playerdeath(wep));
558 RemoveGrapplingHook(this);
560 Portal_ClearAllLater(this);
562 this.fixangle = true;
564 if(defer_ClientKill_Now_TeamChange)
565 ClientKill_Now_TeamChange(this); // can turn player into spectator
567 // player could have been miraculously resuscitated ;)
568 // e.g. players in freezetag get frozen, they don't really die
569 if(this.health >= 1 || !(IS_PLAYER(this) || this.classname == "body"))
572 // when we get here, player actually dies
574 Unfreeze(this); // remove any icy remains
575 this.health = 0; // Unfreeze resets health, so we need to set it back
578 WaypointSprite_PlayerDead(this);
580 SpawnThrownWeapon(this, this.origin + (this.mins + this.maxs) * 0.5, PS(this).m_switchweapon.m_id);
582 // become fully visible
583 this.alpha = default_player_alpha;
584 // make the corpse upright (not tilted)
588 this.avelocity = '0 0 0';
589 // view from the floor
590 this.view_ofs = '0 0 -8';
592 this.movetype = MOVETYPE_TOSS;
594 this.solid = SOLID_CORPSE;
595 this.ballistics_density = autocvar_g_ballistics_density_corpse;
596 // don't stick to the floor
597 UNSET_ONGROUND(this);
599 this.deadflag = DEAD_DYING;
601 // when to allow respawn
602 calculate_player_respawn_time(this);
604 this.death_time = time;
606 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD1, true);
608 animdecide_setstate(this, this.anim_state | ANIMSTATE_DEAD2, true);
612 setsize(this, this.mins, this.maxs);
614 // set damage function to corpse damage
615 this.event_damage = PlayerCorpseDamage;
616 // call the corpse damage function just in case it wants to gib
617 this.event_damage(this, inflictor, attacker, excess, deathtype, hitloc, force);
619 // set up to fade out later
620 SUB_SetFade (this, time + 6 + random (), 1);
621 // reset body think wrapper broken by SUB_SetFade
622 if(this.classname == "body" && this.think != CopyBody_Think) {
623 this.CopyBody_think = this.think;
624 this.CopyBody_nextthink = this.nextthink;
625 this.think = CopyBody_Think;
626 this.nextthink = time;
629 if(autocvar_sv_gentle > 0 || autocvar_ekg || this.classname == "body") {
631 // clones don't run any animation code any more, so we must gib them when they die :(
632 PlayerCorpseDamage(this, inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
635 // reset fields the weapons may use just in case
636 FOREACH(Weapons, it != WEP_Null, LAMBDA(
637 WITH(entity, self, this, it.wr_resetplayer(it));
638 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
640 ATTACK_FINISHED_FOR(this, it.m_id, slot) = 0;
646 void MoveToTeam(entity client, int team_colour, int type)
648 int lockteams_backup = lockteams; // backup any team lock
649 lockteams = 0; // disable locked teams
650 TeamchangeFrags(client); // move the players frags
651 SetPlayerColors(client, team_colour - 1); // set the players colour
652 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE.m_id, client.origin, '0 0 0'); // kill the player
653 lockteams = lockteams_backup; // restore the team lock
654 LogTeamchange(client.playerid, client.team, type);
658 * message "": do not say, just test flood control
664 int Say(entity source, float teamsay, entity privatesay, string msgin, bool floodcontrol)
666 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
668 var .float flood_field;
670 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
672 if(!teamsay && !privatesay)
673 if(substring(msgin, 0, 1) == " ")
674 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
676 msgin = formatmessage(msgin);
678 if (!IS_PLAYER(source))
679 colorstr = "^0"; // black for spectators
681 colorstr = Team_ColorCode(source.team);
688 if(intermission_running)
692 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
695 * using bprint solves this... me stupid
696 // how can we prevent the message from appearing in a listen server?
697 // for now, just give "say" back and only handle say_team
700 clientcommand(self, strcat("say ", msgin));
705 if(autocvar_g_chat_teamcolors)
706 namestr = playername(source);
708 namestr = source.netname;
710 if(strdecolorize(namestr) == namestr)
719 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
720 privatemsgprefixlen = strlen(msgstr);
721 msgstr = strcat(msgstr, msgin);
722 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
723 if(autocvar_g_chat_teamcolors)
724 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
726 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
730 if(strstrofs(msgin, "/me", 0) >= 0)
732 //msgin = strreplace("/me", "", msgin);
733 //msgin = substring(msgin, 3, strlen(msgin));
734 msgin = strreplace("/me", strcat(colorstr, "(", colorprefix, namestr, colorstr, ")^7"), msgin);
735 msgstr = strcat("\{1}\{13}^4* ", "^7", msgin);
738 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
739 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
743 if(strstrofs(msgin, "/me", 0) >= 0)
745 //msgin = strreplace("/me", "", msgin);
746 //msgin = substring(msgin, 3, strlen(msgin));
747 msgin = strreplace("/me", strcat(colorprefix, namestr), msgin);
748 msgstr = strcat("\{1}^4* ", "^7", msgin);
751 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
754 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
758 msgstr = cmsgstr = "";
762 fullcmsgstr = cmsgstr;
766 flood_field = floodcontrol_chat;
775 flood_spl = autocvar_g_chat_flood_spl_tell;
776 flood_burst = autocvar_g_chat_flood_burst_tell;
777 flood_lmax = autocvar_g_chat_flood_lmax_tell;
778 flood_field = floodcontrol_chattell;
782 flood_spl = autocvar_g_chat_flood_spl_team;
783 flood_burst = autocvar_g_chat_flood_burst_team;
784 flood_lmax = autocvar_g_chat_flood_lmax_team;
785 flood_field = floodcontrol_chatteam;
789 flood_spl = autocvar_g_chat_flood_spl;
790 flood_burst = autocvar_g_chat_flood_burst;
791 flood_lmax = autocvar_g_chat_flood_lmax;
792 flood_field = floodcontrol_chat;
794 flood_burst = max(0, flood_burst - 1);
795 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
797 // do flood control for the default line size
800 getWrappedLine_remaining = msgstr;
803 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
805 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
808 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
810 if(getWrappedLine_remaining != "")
812 msgstr = strcat(msgstr, "\n");
816 if (time >= source.(flood_field))
818 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
828 if (time >= source.(flood_field))
829 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
834 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
835 source.(flood_field) = flood = 0;
838 if(flood == 2) // cannot happen for empty msgstr
840 if(autocvar_g_chat_flood_notify_flooder)
842 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
847 sourcemsgstr = fullmsgstr;
848 sourcecmsgstr = fullcmsgstr;
854 sourcemsgstr = msgstr;
855 sourcecmsgstr = cmsgstr;
859 if (!IS_PLAYER(source))
861 if (!intermission_running)
862 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
863 teamsay = -1; // spectators
867 LOG_INFO("NOTE: ", playername(source), "^7 is flooding.\n");
869 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
871 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
875 // always fake the message
880 if (autocvar_g_chat_flood_notify_flooder)
882 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
893 if(sourcemsgstr != "" && ret != 0)
895 if(ret < 0) // faked message, because the player is muted
897 sprint(source, sourcemsgstr);
898 if(sourcecmsgstr != "" && !privatesay)
899 centerprint(source, sourcecmsgstr);
901 else if(privatesay) // private message, between 2 people only
903 sprint(source, sourcemsgstr);
904 sprint(privatesay, msgstr);
905 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
907 centerprint(privatesay, cmsgstr);
909 else if ( teamsay && source.active_minigame )
911 sprint(source, sourcemsgstr);
912 dedicated_print(msgstr); // send to server console too
913 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame, LAMBDA(sprint(it, msgstr)));
915 else if(teamsay > 0) // team message, only sent to team mates
917 sprint(source, sourcemsgstr);
918 dedicated_print(msgstr); // send to server console too
919 if(sourcecmsgstr != "")
920 centerprint(source, sourcecmsgstr);
921 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team, LAMBDA(
924 centerprint(it, cmsgstr);
927 else if(teamsay < 0) // spectator message, only sent to spectators
929 sprint(source, sourcemsgstr);
930 dedicated_print(msgstr); // send to server console too
931 FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
933 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
935 sprint(source, sourcemsgstr);
936 dedicated_print(msgstr); // send to server console too
937 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
940 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.