1 #include "cl_player.qh"
2 #include "g_violence.qh"
3 #include "miscfunctions.qh"
5 #include "weapons/weaponstats.qh"
7 #include "../common/animdecide.qh"
9 void CopyBody_Think(void)
11 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
13 self.CopyBody_think();
16 self.CopyBody_nextthink = self.nextthink;
17 self.CopyBody_think = self.think;
18 self.think = CopyBody_Think;
20 CSQCMODEL_AUTOUPDATE();
21 self.nextthink = time;
23 void CopyBody(float keepvelocity)
26 if (self.effects & EF_NODRAW)
31 self.lip = oldself.lip;
32 self.colormap = oldself.colormap;
33 self.iscreature = oldself.iscreature;
34 self.teleportable = oldself.teleportable;
35 self.damagedbycontents = oldself.damagedbycontents;
36 self.angles = oldself.angles;
37 self.v_angle = oldself.v_angle;
38 self.avelocity = oldself.avelocity;
39 self.classname = "body";
40 self.damageforcescale = oldself.damageforcescale;
41 self.effects = oldself.effects;
42 self.glowmod = oldself.glowmod;
43 self.event_damage = oldself.event_damage;
44 self.anim_state = oldself.anim_state;
45 self.anim_time = oldself.anim_time;
46 self.anim_lower_action = oldself.anim_lower_action;
47 self.anim_lower_time = oldself.anim_lower_time;
48 self.anim_upper_action = oldself.anim_upper_action;
49 self.anim_upper_time = oldself.anim_upper_time;
50 self.anim_implicit_state = oldself.anim_implicit_state;
51 self.anim_implicit_time = oldself.anim_implicit_time;
52 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
53 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
54 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
55 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
56 self.dphitcontentsmask = oldself.dphitcontentsmask;
57 self.death_time = oldself.death_time;
58 self.pain_finished = oldself.pain_finished;
59 self.health = oldself.health;
60 self.armorvalue = oldself.armorvalue;
61 self.armortype = oldself.armortype;
62 self.model = oldself.model;
63 self.modelindex = oldself.modelindex;
64 self.skin = oldself.skin;
65 self.species = oldself.species;
66 self.movetype = oldself.movetype;
67 self.solid = oldself.solid;
68 self.ballistics_density = oldself.ballistics_density;
69 self.takedamage = oldself.takedamage;
70 self.customizeentityforclient = oldself.customizeentityforclient;
71 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
72 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
73 if (keepvelocity == 1)
74 self.velocity = oldself.velocity;
75 self.oldvelocity = self.velocity;
76 self.alpha = oldself.alpha;
77 self.fade_time = oldself.fade_time;
78 self.fade_rate = oldself.fade_rate;
79 //self.weapon = oldself.weapon;
80 setorigin(self, oldself.origin);
81 setsize(self, oldself.mins, oldself.maxs);
82 self.prevorigin = oldself.origin;
83 self.reset = SUB_Remove;
85 Drag_MoveDrag(oldself, self);
87 if(self.colormap <= maxclients && self.colormap > 0)
88 self.colormap = 1024 + oldself.clientcolors;
91 self.CopyBody_nextthink = oldself.nextthink;
92 self.CopyBody_think = oldself.think;
93 self.nextthink = time;
94 self.think = CopyBody_Think;
95 // "bake" the current animation frame for clones (they don't get clientside animation)
96 animdecide_load_if_needed(self);
97 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
102 float player_getspecies()
105 get_model_parameters(self.model, self.skin);
106 s = get_model_parameters_species;
107 get_model_parameters(string_null, 0);
109 return SPECIES_HUMAN;
113 void player_setupanimsformodel()
115 // load animation info
116 animdecide_load_if_needed(self);
117 animdecide_setstate(self, 0, false);
120 void player_anim (void)
122 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
125 // Decide on which death animation to use.
127 deadbits = ANIMSTATE_DEAD1;
129 deadbits = ANIMSTATE_DEAD2;
132 // Clear a previous death animation.
135 int animbits = deadbits;
137 animbits |= ANIMSTATE_FROZEN;
139 animbits |= ANIMSTATE_DUCK;
140 animdecide_setstate(self, animbits, false);
141 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
143 if (self.weaponentity)
145 updateanim(self.weaponentity);
146 if (!self.weaponentity.animstate_override)
147 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
151 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
155 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
157 // damage resistance (ignore most of the damage from a bullet or similar)
158 damage = max(damage - 5, 1);
160 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
164 if(sound_allowed(MSG_BROADCAST, attacker))
167 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
169 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
171 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
175 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
177 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
179 self.armorvalue = self.armorvalue - save;
180 self.health = self.health - take;
181 // pause regeneration for 5 seconds
182 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
184 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
185 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
186 self.dmg_inflictor = inflictor;
188 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
190 // don't use any animations as a gib
192 // view just above the floor
193 self.view_ofs = '0 0 4';
195 Violence_GibSplash(self, 1, 1, attacker);
197 self.solid = SOLID_NOT; // restore later
198 self.takedamage = DAMAGE_NO; // restore later
199 self.damagedbycontents = false;
203 void calculate_player_respawn_time()
208 float gametype_setting_tmp;
209 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
210 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
211 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
212 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
213 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
214 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
216 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
222 if (pl.team == self.team)
224 if (sdelay_small_count == 0)
225 sdelay_small_count = 1;
226 if (sdelay_large_count == 0)
227 sdelay_large_count = 1;
234 if (sdelay_small_count == 0)
238 // Players play independently. No point in requiring enemies.
239 sdelay_small_count = 1;
243 // Players play AGAINST each other. Enemies required.
244 sdelay_small_count = 2;
247 if (sdelay_large_count == 0)
251 // Players play independently. No point in requiring enemies.
252 sdelay_large_count = 1;
256 // Players play AGAINST each other. Enemies required.
257 sdelay_large_count = 2;
264 if (pcount <= sdelay_small_count)
265 sdelay = sdelay_small;
266 else if (pcount >= sdelay_large_count)
267 sdelay = sdelay_large;
268 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
269 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
272 self.respawn_time = ceil((time + sdelay) / waves) * waves;
274 self.respawn_time = time + sdelay;
276 if(sdelay < sdelay_max)
277 self.respawn_time_max = time + sdelay_max;
279 self.respawn_time_max = self.respawn_time;
281 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
282 self.respawn_countdown = 10; // first number to count down from is 10
284 self.respawn_countdown = -1; // do not count down
286 if(autocvar_g_forced_respawn)
287 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
290 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
292 float take, save, dh, da;
295 float valid_damage_for_weaponstats;
298 dh = max(self.health, 0);
299 da = max(self.armorvalue, 0);
301 if(!DEATH_ISSPECIAL(deathtype))
303 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
305 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
308 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
310 // tuba causes blood to come out of the ears
315 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
317 makevectors(self.angles);
318 ear1 += v_right * -10;
319 ear2 += v_right * +10;
320 d = inflictor.origin - self.origin;
322 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
324 f = 0; // Assum ecenter.
325 force = v_right * vlen(force);
326 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
327 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
336 // force is already good
340 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
343 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
349 // don't reset pushltime for self damage as it may be an attempt to
350 // escape a lava pit or similar
351 //self.pushltime = 0;
354 else if(IS_PLAYER(attacker))
356 self.pusher = attacker;
357 self.pushltime = time + autocvar_g_maxpushtime;
358 self.istypefrag = self.BUTTON_CHAT;
360 else if(time < self.pushltime)
362 attacker = self.pusher;
363 self.pushltime = max(self.pushltime, time + 0.6);
371 frag_inflictor = inflictor;
372 frag_attacker = attacker;
374 frag_damage = damage;
377 damage_force = force;
378 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
379 take = bound(0, damage_take, self.health);
380 save = bound(0, damage_save, self.armorvalue);
381 excess = max(0, damage - take - save);
383 if(sound_allowed(MSG_BROADCAST, attacker))
386 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
388 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
390 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
394 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
396 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
398 if (time >= self.spawnshieldtime)
400 if (!(self.flags & FL_GODMODE))
402 self.armorvalue = self.armorvalue - save;
403 self.health = self.health - take;
404 // pause regeneration for 5 seconds
406 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
408 if (time > self.pain_finished) //Don't switch pain sequences like crazy
410 self.pain_finished = time + 0.5; //Supajoe
412 if(autocvar_sv_gentle < 1) {
413 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
415 if (!self.animstate_override)
418 animdecide_setaction(self, ANIMACTION_PAIN1, true);
420 animdecide_setaction(self, ANIMACTION_PAIN2, true);
424 if(sound_allowed(MSG_BROADCAST, attacker))
425 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
427 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
429 if(deathtype == DEATH_FALL)
430 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
431 else if(self.health > 75) // TODO make a "gentle" version?
432 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
433 else if(self.health > 50)
434 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
435 else if(self.health > 25)
436 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
438 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
443 // throw off bot aim temporarily
445 if(IS_BOT_CLIENT(self) && self.health >= 1)
447 shake = damage * 5 / (bound(0,skill,100) + 1);
448 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
449 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
450 self.v_angle_x = bound(-90, self.v_angle.x, 90);
454 self.max_armorvalue += (save + take);
456 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
457 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
458 self.dmg_inflictor = inflictor;
460 float abot, vbot, awep;
461 abot = (IS_BOT_CLIENT(attacker));
462 vbot = (IS_BOT_CLIENT(self));
464 valid_damage_for_weaponstats = 0;
467 if(vbot || IS_REAL_CLIENT(self))
468 if(abot || IS_REAL_CLIENT(attacker))
469 if(attacker && self != attacker)
470 if(DIFF_TEAM(self, attacker))
472 if(DEATH_ISSPECIAL(deathtype))
473 awep = attacker.weapon;
475 awep = DEATH_WEAPONOF(deathtype);
476 valid_damage_for_weaponstats = 1;
479 if(valid_damage_for_weaponstats)
481 dh = dh - max(self.health, 0);
482 da = da - max(self.armorvalue, 0);
483 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
488 float defer_ClientKill_Now_TeamChange;
489 defer_ClientKill_Now_TeamChange = false;
493 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
497 if(valid_damage_for_weaponstats)
498 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
500 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
501 if(sound_allowed(MSG_BROADCAST, attacker))
503 if(deathtype == DEATH_DROWN)
504 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
506 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
509 // get rid of kill indicator
510 if(self.killindicator)
512 remove(self.killindicator);
513 self.killindicator = world;
514 if(self.killindicator_teamchange)
515 defer_ClientKill_Now_TeamChange = true;
517 if(self.classname == "body")
518 if(deathtype == DEATH_KILL)
520 // for the lemmings fans, a small harmless explosion
521 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
525 // print an obituary message
526 if(self.classname != "body")
527 Obituary (attacker, inflictor, self, deathtype);
529 // increment frag counter for used weapon type
530 int w = DEATH_WEAPONOF(deathtype);
532 if(accuracy_isgooddamage(attacker, self))
533 attacker.accuracy.(accuracy_frags[w-1]) += 1;
535 frag_attacker = attacker;
536 frag_inflictor = inflictor;
538 frag_deathtype = deathtype;
539 MUTATOR_CALLHOOK(PlayerDies);
541 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
543 RemoveGrapplingHook(self);
545 Portal_ClearAllLater(self);
547 self.fixangle = true;
549 if(defer_ClientKill_Now_TeamChange)
550 ClientKill_Now_TeamChange(); // can turn player into spectator
552 // player could have been miraculously resuscitated ;)
553 // e.g. players in freezetag get frozen, they don't really die
554 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
557 // when we get here, player actually dies
559 Unfreeze(self); // remove any icy remains
560 self.health = 0; // Unfreeze resets health, so we need to set it back
563 WaypointSprite_PlayerDead();
565 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
567 // become fully visible
568 self.alpha = default_player_alpha;
569 // make the corpse upright (not tilted)
573 self.avelocity = '0 0 0';
574 // view from the floor
575 self.view_ofs = '0 0 -8';
577 self.movetype = MOVETYPE_TOSS;
579 self.solid = SOLID_CORPSE;
580 self.ballistics_density = autocvar_g_ballistics_density_corpse;
581 // don't stick to the floor
582 self.flags &= ~FL_ONGROUND;
584 self.deadflag = DEAD_DYING;
586 // when to allow respawn
587 calculate_player_respawn_time();
589 self.death_time = time;
591 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
593 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
597 setsize(self, self.mins, self.maxs);
599 // set damage function to corpse damage
600 self.event_damage = PlayerCorpseDamage;
601 // call the corpse damage function just in case it wants to gib
602 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
604 // set up to fade out later
605 SUB_SetFade (self, time + 6 + random (), 1);
606 // reset body think wrapper broken by SUB_SetFade
607 if(self.classname == "body" && self.think != CopyBody_Think) {
608 self.CopyBody_think = self.think;
609 self.CopyBody_nextthink = self.nextthink;
610 self.think = CopyBody_Think;
611 self.nextthink = time;
614 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
616 // clones don't run any animation code any more, so we must gib them when they die :(
617 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
620 // reset fields the weapons may use just in case
621 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
623 WEP_ACTION(j, WR_RESETPLAYER);
624 ATTACK_FINISHED_FOR(self, j) = 0;
629 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
630 // message "": do not say, just test flood control
636 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
638 var .float flood_field;
641 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
643 if(!teamsay && !privatesay)
644 if(substring(msgin, 0, 1) == " ")
645 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
647 msgin = formatmessage(msgin);
649 if (!IS_PLAYER(source))
650 colorstr = "^0"; // black for spectators
652 colorstr = Team_ColorCode(source.team);
659 if(intermission_running)
663 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
666 * using bprint solves this... me stupid
667 // how can we prevent the message from appearing in a listen server?
668 // for now, just give "say" back and only handle say_team
671 clientcommand(self, strcat("say ", msgin));
676 if(autocvar_g_chat_teamcolors)
677 namestr = playername(source);
679 namestr = source.netname;
681 if(strdecolorize(namestr) == namestr)
690 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
691 privatemsgprefixlen = strlen(msgstr);
692 msgstr = strcat(msgstr, msgin);
693 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
694 if(autocvar_g_chat_teamcolors)
695 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
697 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
701 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
702 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
706 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
709 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
713 msgstr = cmsgstr = "";
717 fullcmsgstr = cmsgstr;
721 flood_field = floodcontrol_chat;
730 flood_spl = autocvar_g_chat_flood_spl_tell;
731 flood_burst = autocvar_g_chat_flood_burst_tell;
732 flood_lmax = autocvar_g_chat_flood_lmax_tell;
733 flood_field = floodcontrol_chattell;
737 flood_spl = autocvar_g_chat_flood_spl_team;
738 flood_burst = autocvar_g_chat_flood_burst_team;
739 flood_lmax = autocvar_g_chat_flood_lmax_team;
740 flood_field = floodcontrol_chatteam;
744 flood_spl = autocvar_g_chat_flood_spl;
745 flood_burst = autocvar_g_chat_flood_burst;
746 flood_lmax = autocvar_g_chat_flood_lmax;
747 flood_field = floodcontrol_chat;
749 flood_burst = max(0, flood_burst - 1);
750 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
752 // do flood control for the default line size
755 getWrappedLine_remaining = msgstr;
758 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
760 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
763 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
765 if(getWrappedLine_remaining != "")
767 msgstr = strcat(msgstr, "\n");
771 if(time >= source.flood_field)
773 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
783 if(time >= source.flood_field)
784 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
789 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
790 source.flood_field = flood = 0;
793 if(flood == 2) // cannot happen for empty msgstr
795 if(autocvar_g_chat_flood_notify_flooder)
797 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
802 sourcemsgstr = fullmsgstr;
803 sourcecmsgstr = fullcmsgstr;
809 sourcemsgstr = msgstr;
810 sourcecmsgstr = cmsgstr;
814 if (!IS_PLAYER(source))
816 if (!intermission_running)
817 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
818 teamsay = -1; // spectators
822 print("NOTE: ", playername(source), "^7 is flooding.\n");
824 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
826 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
830 // always fake the message
835 if(autocvar_g_chat_flood_notify_flooder)
837 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
848 if(sourcemsgstr != "" && ret != 0)
850 if(ret < 0) // faked message, because the player is muted
852 sprint(source, sourcemsgstr);
853 if(sourcecmsgstr != "" && !privatesay)
854 centerprint(source, sourcecmsgstr);
856 else if(privatesay) // private message, between 2 people only
858 sprint(source, sourcemsgstr);
859 sprint(privatesay, msgstr);
860 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
862 centerprint(privatesay, cmsgstr);
864 else if(teamsay > 0) // team message, only sent to team mates
866 sprint(source, sourcemsgstr);
867 dedicated_print(msgstr); // send to server console too
868 if(sourcecmsgstr != "")
869 centerprint(source, sourcecmsgstr);
870 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
873 sprint(head, msgstr);
875 centerprint(head, cmsgstr);
878 else if(teamsay < 0) // spectator message, only sent to spectators
880 sprint(source, sourcemsgstr);
881 dedicated_print(msgstr); // send to server console too
882 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
884 sprint(head, msgstr);
886 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
888 sprint(source, sourcemsgstr);
889 dedicated_print(msgstr); // send to server console too
890 FOR_EACH_REALCLIENT(head)
892 sprint(head, msgstr);
895 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
901 float GetVoiceMessageVoiceType(string type)
904 return VOICETYPE_TAUNT;
905 if(type == "teamshoot")
906 return VOICETYPE_LASTATTACKER;
907 return VOICETYPE_TEAMRADIO;
910 .string GetVoiceMessageSampleField(string type)
912 GetPlayerSoundSampleField_notFound = 0;
915 #define _VOICEMSG(m) case #m: return playersound_##m;
919 GetPlayerSoundSampleField_notFound = 1;
920 return playersound_taunt;
923 .string GetPlayerSoundSampleField(string type)
925 GetPlayerSoundSampleField_notFound = 0;
928 #define _VOICEMSG(m) case #m: return playersound_##m;
932 GetPlayerSoundSampleField_notFound = 1;
933 return playersound_taunt;
936 void PrecacheGlobalSound(string samplestring)
939 tokenize_console(samplestring);
943 for(i = 1; i <= n; ++i)
944 precache_sound(strcat(argv(0), ftos(i), ".wav"));
948 precache_sound(strcat(argv(0), ".wav"));
952 void PrecachePlayerSounds(string f)
956 fh = fopen(f, FILE_READ);
959 while((s = fgets(fh)))
961 if(tokenize_console(s) != 3)
963 dprint("Invalid sound info line: ", s, "\n");
966 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
970 if (!allvoicesamples)
972 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
975 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
979 void ClearPlayerSounds()
981 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
987 float LoadPlayerSounds(string f, float first)
992 fh = fopen(f, FILE_READ);
995 dprint("Player sound file not found: ", f, "\n");
998 while((s = fgets(fh)))
1000 if(tokenize_console(s) != 3)
1002 field = GetPlayerSoundSampleField(argv(0));
1003 if(GetPlayerSoundSampleField_notFound)
1004 field = GetVoiceMessageSampleField(argv(0));
1005 if(GetPlayerSoundSampleField_notFound)
1008 strunzone(self.field);
1009 self.field = strzone(strcat(argv(1), " ", argv(2)));
1015 void UpdatePlayerSounds()
1017 if(self.modelindex == self.modelindex_for_playersound)
1018 if(self.skin == self.skin_for_playersound)
1020 self.modelindex_for_playersound = self.modelindex;
1021 self.skin_for_playersound = self.skin;
1022 ClearPlayerSounds();
1023 LoadPlayerSounds("sound/player/default.sounds", 1);
1024 if(!autocvar_g_debug_defaultsounds)
1025 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1026 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1029 void FakeGlobalSound(string sample, float chan, float voicetype)
1037 tokenize_console(sample);
1040 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1042 sample = strcat(argv(0), ".wav"); // randomization
1046 case VOICETYPE_LASTATTACKER_ONLY:
1048 case VOICETYPE_LASTATTACKER:
1052 if(IS_REAL_CLIENT(msg_entity))
1053 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1056 case VOICETYPE_TEAMRADIO:
1058 if(msg_entity.cvar_cl_voice_directional == 1)
1059 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1061 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1063 case VOICETYPE_AUTOTAUNT:
1068 if(autocvar_sv_gentle)
1070 tauntrand = random();
1072 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1074 if (msg_entity.cvar_cl_voice_directional >= 1)
1075 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1077 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1080 case VOICETYPE_TAUNT:
1082 if(self.deadflag == DEAD_NO)
1083 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1086 if(autocvar_sv_gentle)
1089 if (msg_entity.cvar_cl_voice_directional >= 1)
1090 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1092 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1094 case VOICETYPE_PLAYERSOUND:
1096 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1099 backtrace("Invalid voice type!");
1104 void GlobalSound(string sample, float chan, float voicetype)
1112 tokenize_console(sample);
1115 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1117 sample = strcat(argv(0), ".wav"); // randomization
1121 case VOICETYPE_LASTATTACKER_ONLY:
1124 msg_entity = self.pusher;
1125 if(IS_REAL_CLIENT(msg_entity))
1127 if(msg_entity.cvar_cl_voice_directional == 1)
1128 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1130 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1134 case VOICETYPE_LASTATTACKER:
1137 msg_entity = self.pusher;
1138 if(IS_REAL_CLIENT(msg_entity))
1140 if(msg_entity.cvar_cl_voice_directional == 1)
1141 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1143 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1146 if(IS_REAL_CLIENT(msg_entity))
1147 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1150 case VOICETYPE_TEAMRADIO:
1151 FOR_EACH_REALCLIENT(msg_entity)
1152 if(!teamplay || msg_entity.team == self.team)
1154 if(msg_entity.cvar_cl_voice_directional == 1)
1155 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1157 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1160 case VOICETYPE_AUTOTAUNT:
1165 if(autocvar_sv_gentle)
1167 tauntrand = random();
1168 FOR_EACH_REALCLIENT(msg_entity)
1169 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1171 if (msg_entity.cvar_cl_voice_directional >= 1)
1172 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1174 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1177 case VOICETYPE_TAUNT:
1179 if(self.deadflag == DEAD_NO)
1180 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1183 if(autocvar_sv_gentle)
1185 FOR_EACH_REALCLIENT(msg_entity)
1187 if (msg_entity.cvar_cl_voice_directional >= 1)
1188 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1190 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1193 case VOICETYPE_PLAYERSOUND:
1194 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1197 backtrace("Invalid voice type!");
1202 void PlayerSound(.string samplefield, float chan, float voicetype)
1204 GlobalSound(self.samplefield, chan, voicetype);
1207 void VoiceMessage(string type, string msg)
1210 float voicetype, ownteam;
1212 sample = GetVoiceMessageSampleField(type);
1214 if(GetPlayerSoundSampleField_notFound)
1216 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1220 voicetype = GetVoiceMessageVoiceType(type);
1221 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1223 flood = Say(self, ownteam, world, msg, 1);
1225 if(IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1226 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1228 GlobalSound(self.sample, CH_VOICE, voicetype);
1231 void MoveToTeam(entity client, float team_colour, float type)
1233 float lockteams_backup;
1235 lockteams_backup = lockteams; // backup any team lock
1237 lockteams = 0; // disable locked teams
1239 TeamchangeFrags(client); // move the players frags
1240 SetPlayerColors(client, team_colour - 1); // set the players colour
1241 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1243 lockteams = lockteams_backup; // restore the team lock
1245 LogTeamchange(client.playerid, client.team, type);