1 #include "cl_player.qh"
2 #include "g_triggers.qh"
3 #include "g_violence.qh"
4 #include "miscfunctions.qh"
6 #include "weapons/weaponstats.qh"
8 void CopyBody_Think(void)
10 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
12 self.CopyBody_think();
15 self.CopyBody_nextthink = self.nextthink;
16 self.CopyBody_think = self.think;
17 self.think = CopyBody_Think;
19 CSQCMODEL_AUTOUPDATE();
20 self.nextthink = time;
22 void CopyBody(float keepvelocity)
25 if (self.effects & EF_NODRAW)
30 self.lip = oldself.lip;
31 self.colormap = oldself.colormap;
32 self.iscreature = oldself.iscreature;
33 self.teleportable = oldself.teleportable;
34 self.damagedbycontents = oldself.damagedbycontents;
35 self.angles = oldself.angles;
36 self.v_angle = oldself.v_angle;
37 self.avelocity = oldself.avelocity;
38 self.classname = "body";
39 self.damageforcescale = oldself.damageforcescale;
40 self.effects = oldself.effects;
41 self.glowmod = oldself.glowmod;
42 self.event_damage = oldself.event_damage;
43 self.anim_state = oldself.anim_state;
44 self.anim_time = oldself.anim_time;
45 self.anim_lower_action = oldself.anim_lower_action;
46 self.anim_lower_time = oldself.anim_lower_time;
47 self.anim_upper_action = oldself.anim_upper_action;
48 self.anim_upper_time = oldself.anim_upper_time;
49 self.anim_implicit_state = oldself.anim_implicit_state;
50 self.anim_implicit_time = oldself.anim_implicit_time;
51 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
52 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
53 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
54 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
55 self.dphitcontentsmask = oldself.dphitcontentsmask;
56 self.death_time = oldself.death_time;
57 self.pain_finished = oldself.pain_finished;
58 self.health = oldself.health;
59 self.armorvalue = oldself.armorvalue;
60 self.armortype = oldself.armortype;
61 self.model = oldself.model;
62 self.modelindex = oldself.modelindex;
63 self.skin = oldself.skin;
64 self.species = oldself.species;
65 self.movetype = oldself.movetype;
66 self.solid = oldself.solid;
67 self.ballistics_density = oldself.ballistics_density;
68 self.takedamage = oldself.takedamage;
69 self.customizeentityforclient = oldself.customizeentityforclient;
70 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
71 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
72 if (keepvelocity == 1)
73 self.velocity = oldself.velocity;
74 self.oldvelocity = self.velocity;
75 self.alpha = oldself.alpha;
76 self.fade_time = oldself.fade_time;
77 self.fade_rate = oldself.fade_rate;
78 //self.weapon = oldself.weapon;
79 setorigin(self, oldself.origin);
80 setsize(self, oldself.mins, oldself.maxs);
81 self.prevorigin = oldself.origin;
82 self.reset = SUB_Remove;
84 Drag_MoveDrag(oldself, self);
86 if(self.colormap <= maxclients && self.colormap > 0)
87 self.colormap = 1024 + oldself.clientcolors;
90 self.CopyBody_nextthink = oldself.nextthink;
91 self.CopyBody_think = oldself.think;
92 self.nextthink = time;
93 self.think = CopyBody_Think;
94 // "bake" the current animation frame for clones (they don't get clientside animation)
95 animdecide_load_if_needed(self);
96 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
101 float player_getspecies()
104 get_model_parameters(self.model, self.skin);
105 s = get_model_parameters_species;
106 get_model_parameters(string_null, 0);
108 return SPECIES_HUMAN;
112 void player_setupanimsformodel()
114 // load animation info
115 animdecide_load_if_needed(self);
116 animdecide_setstate(self, 0, false);
119 void player_anim (void)
121 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
124 // Decide on which death animation to use.
126 deadbits = ANIMSTATE_DEAD1;
128 deadbits = ANIMSTATE_DEAD2;
131 // Clear a previous death animation.
134 int animbits = deadbits;
136 animbits |= ANIMSTATE_FROZEN;
138 animbits |= ANIMSTATE_DUCK;
139 animdecide_setstate(self, animbits, false);
140 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
142 if (self.weaponentity)
144 updateanim(self.weaponentity);
145 if (!self.weaponentity.animstate_override)
146 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
150 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
154 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
156 // damage resistance (ignore most of the damage from a bullet or similar)
157 damage = max(damage - 5, 1);
159 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
163 if(sound_allowed(MSG_BROADCAST, attacker))
166 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
168 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
170 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
174 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
176 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
178 self.armorvalue = self.armorvalue - save;
179 self.health = self.health - take;
180 // pause regeneration for 5 seconds
181 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
183 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
184 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
185 self.dmg_inflictor = inflictor;
187 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
189 // don't use any animations as a gib
191 // view just above the floor
192 self.view_ofs = '0 0 4';
194 Violence_GibSplash(self, 1, 1, attacker);
196 self.solid = SOLID_NOT; // restore later
197 self.takedamage = DAMAGE_NO; // restore later
198 self.damagedbycontents = false;
202 void calculate_player_respawn_time()
207 float gametype_setting_tmp;
208 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
209 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
210 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
211 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
212 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
213 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
215 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
221 if (pl.team == self.team)
223 if (sdelay_small_count == 0)
224 sdelay_small_count = 1;
225 if (sdelay_large_count == 0)
226 sdelay_large_count = 1;
233 if (sdelay_small_count == 0)
237 // Players play independently. No point in requiring enemies.
238 sdelay_small_count = 1;
242 // Players play AGAINST each other. Enemies required.
243 sdelay_small_count = 2;
246 if (sdelay_large_count == 0)
250 // Players play independently. No point in requiring enemies.
251 sdelay_large_count = 1;
255 // Players play AGAINST each other. Enemies required.
256 sdelay_large_count = 2;
263 if (pcount <= sdelay_small_count)
264 sdelay = sdelay_small;
265 else if (pcount >= sdelay_large_count)
266 sdelay = sdelay_large;
267 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
268 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
271 self.respawn_time = ceil((time + sdelay) / waves) * waves;
273 self.respawn_time = time + sdelay;
275 if(sdelay < sdelay_max)
276 self.respawn_time_max = time + sdelay_max;
278 self.respawn_time_max = self.respawn_time;
280 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
281 self.respawn_countdown = 10; // first number to count down from is 10
283 self.respawn_countdown = -1; // do not count down
285 if(autocvar_g_forced_respawn)
286 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
289 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
291 float take, save, dh, da;
294 float valid_damage_for_weaponstats;
297 dh = max(self.health, 0);
298 da = max(self.armorvalue, 0);
300 if(!DEATH_ISSPECIAL(deathtype))
302 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
304 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
307 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
309 // tuba causes blood to come out of the ears
314 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
316 makevectors(self.angles);
317 ear1 += v_right * -10;
318 ear2 += v_right * +10;
319 d = inflictor.origin - self.origin;
321 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
323 f = 0; // Assum ecenter.
324 force = v_right * vlen(force);
325 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
326 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
335 // force is already good
339 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
342 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
348 // don't reset pushltime for self damage as it may be an attempt to
349 // escape a lava pit or similar
350 //self.pushltime = 0;
353 else if(IS_PLAYER(attacker))
355 self.pusher = attacker;
356 self.pushltime = time + autocvar_g_maxpushtime;
357 self.istypefrag = self.BUTTON_CHAT;
359 else if(time < self.pushltime)
361 attacker = self.pusher;
362 self.pushltime = max(self.pushltime, time + 0.6);
370 frag_inflictor = inflictor;
371 frag_attacker = attacker;
373 frag_damage = damage;
376 damage_force = force;
377 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
378 take = bound(0, damage_take, self.health);
379 save = bound(0, damage_save, self.armorvalue);
380 excess = max(0, damage - take - save);
382 if(sound_allowed(MSG_BROADCAST, attacker))
385 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
387 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
389 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
393 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
395 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
397 if (time >= self.spawnshieldtime)
399 if (!(self.flags & FL_GODMODE))
401 self.armorvalue = self.armorvalue - save;
402 self.health = self.health - take;
403 // pause regeneration for 5 seconds
405 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
407 if (time > self.pain_finished) //Don't switch pain sequences like crazy
409 self.pain_finished = time + 0.5; //Supajoe
411 if(autocvar_sv_gentle < 1) {
412 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
414 if (!self.animstate_override)
417 animdecide_setaction(self, ANIMACTION_PAIN1, true);
419 animdecide_setaction(self, ANIMACTION_PAIN2, true);
423 if(sound_allowed(MSG_BROADCAST, attacker))
424 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
426 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
428 if(deathtype == DEATH_FALL)
429 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
430 else if(self.health > 75) // TODO make a "gentle" version?
431 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
432 else if(self.health > 50)
433 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
434 else if(self.health > 25)
435 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
437 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
442 // throw off bot aim temporarily
444 if(IS_BOT_CLIENT(self) && self.health >= 1)
446 shake = damage * 5 / (bound(0,skill,100) + 1);
447 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
448 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
449 self.v_angle_x = bound(-90, self.v_angle.x, 90);
453 self.max_armorvalue += (save + take);
455 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
456 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
457 self.dmg_inflictor = inflictor;
459 float abot, vbot, awep;
460 abot = (IS_BOT_CLIENT(attacker));
461 vbot = (IS_BOT_CLIENT(self));
463 valid_damage_for_weaponstats = 0;
466 if(vbot || IS_REAL_CLIENT(self))
467 if(abot || IS_REAL_CLIENT(attacker))
468 if(attacker && self != attacker)
469 if(DIFF_TEAM(self, attacker))
471 if(DEATH_ISSPECIAL(deathtype))
472 awep = attacker.weapon;
474 awep = DEATH_WEAPONOF(deathtype);
475 valid_damage_for_weaponstats = 1;
478 if(valid_damage_for_weaponstats)
480 dh = dh - max(self.health, 0);
481 da = da - max(self.armorvalue, 0);
482 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
487 float defer_ClientKill_Now_TeamChange;
488 defer_ClientKill_Now_TeamChange = false;
492 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
496 if(valid_damage_for_weaponstats)
497 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
499 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
500 if(sound_allowed(MSG_BROADCAST, attacker))
502 if(deathtype == DEATH_DROWN)
503 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
505 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
508 // get rid of kill indicator
509 if(self.killindicator)
511 remove(self.killindicator);
512 self.killindicator = world;
513 if(self.killindicator_teamchange)
514 defer_ClientKill_Now_TeamChange = true;
516 if(self.classname == "body")
517 if(deathtype == DEATH_KILL)
519 // for the lemmings fans, a small harmless explosion
520 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
524 // print an obituary message
525 if(self.classname != "body")
526 Obituary (attacker, inflictor, self, deathtype);
528 // increment frag counter for used weapon type
529 int w = DEATH_WEAPONOF(deathtype);
531 if(accuracy_isgooddamage(attacker, self))
532 attacker.accuracy.(accuracy_frags[w-1]) += 1;
534 frag_attacker = attacker;
535 frag_inflictor = inflictor;
537 frag_deathtype = deathtype;
538 MUTATOR_CALLHOOK(PlayerDies);
540 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
542 RemoveGrapplingHook(self);
544 Portal_ClearAllLater(self);
546 self.fixangle = true;
548 if(defer_ClientKill_Now_TeamChange)
549 ClientKill_Now_TeamChange(); // can turn player into spectator
551 // player could have been miraculously resuscitated ;)
552 // e.g. players in freezetag get frozen, they don't really die
553 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
556 // when we get here, player actually dies
558 Unfreeze(self); // remove any icy remains
559 self.health = 0; // Unfreeze resets health, so we need to set it back
562 WaypointSprite_PlayerDead();
564 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
566 // become fully visible
567 self.alpha = default_player_alpha;
568 // make the corpse upright (not tilted)
572 self.avelocity = '0 0 0';
573 // view from the floor
574 self.view_ofs = '0 0 -8';
576 self.movetype = MOVETYPE_TOSS;
578 self.solid = SOLID_CORPSE;
579 self.ballistics_density = autocvar_g_ballistics_density_corpse;
580 // don't stick to the floor
581 self.flags &= ~FL_ONGROUND;
583 self.deadflag = DEAD_DYING;
585 // when to allow respawn
586 calculate_player_respawn_time();
588 self.death_time = time;
590 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
592 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
596 setsize(self, self.mins, self.maxs);
598 // set damage function to corpse damage
599 self.event_damage = PlayerCorpseDamage;
600 // call the corpse damage function just in case it wants to gib
601 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
603 // set up to fade out later
604 SUB_SetFade (self, time + 6 + random (), 1);
605 // reset body think wrapper broken by SUB_SetFade
606 if(self.classname == "body" && self.think != CopyBody_Think) {
607 self.CopyBody_think = self.think;
608 self.CopyBody_nextthink = self.nextthink;
609 self.think = CopyBody_Think;
610 self.nextthink = time;
613 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
615 // clones don't run any animation code any more, so we must gib them when they die :(
616 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
619 // reset fields the weapons may use just in case
620 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
622 WEP_ACTION(j, WR_RESETPLAYER);
623 ATTACK_FINISHED_FOR(self, j) = 0;
628 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
629 // message "": do not say, just test flood control
635 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
637 var .float flood_field;
640 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
642 if(!teamsay && !privatesay)
643 if(substring(msgin, 0, 1) == " ")
644 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
646 msgin = formatmessage(msgin);
648 if (!IS_PLAYER(source))
649 colorstr = "^0"; // black for spectators
651 colorstr = Team_ColorCode(source.team);
658 if(intermission_running)
662 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
665 * using bprint solves this... me stupid
666 // how can we prevent the message from appearing in a listen server?
667 // for now, just give "say" back and only handle say_team
670 clientcommand(self, strcat("say ", msgin));
675 if(autocvar_g_chat_teamcolors)
676 namestr = playername(source);
678 namestr = source.netname;
680 if(strdecolorize(namestr) == namestr)
689 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
690 privatemsgprefixlen = strlen(msgstr);
691 msgstr = strcat(msgstr, msgin);
692 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
693 if(autocvar_g_chat_teamcolors)
694 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
696 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
700 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
701 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
705 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
708 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
712 msgstr = cmsgstr = "";
716 fullcmsgstr = cmsgstr;
720 flood_field = floodcontrol_chat;
729 flood_spl = autocvar_g_chat_flood_spl_tell;
730 flood_burst = autocvar_g_chat_flood_burst_tell;
731 flood_lmax = autocvar_g_chat_flood_lmax_tell;
732 flood_field = floodcontrol_chattell;
736 flood_spl = autocvar_g_chat_flood_spl_team;
737 flood_burst = autocvar_g_chat_flood_burst_team;
738 flood_lmax = autocvar_g_chat_flood_lmax_team;
739 flood_field = floodcontrol_chatteam;
743 flood_spl = autocvar_g_chat_flood_spl;
744 flood_burst = autocvar_g_chat_flood_burst;
745 flood_lmax = autocvar_g_chat_flood_lmax;
746 flood_field = floodcontrol_chat;
748 flood_burst = max(0, flood_burst - 1);
749 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
751 // do flood control for the default line size
754 getWrappedLine_remaining = msgstr;
757 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
759 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
762 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
764 if(getWrappedLine_remaining != "")
766 msgstr = strcat(msgstr, "\n");
770 if (time >= source.(flood_field))
772 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + lines * flood_spl;
782 if (time >= source.(flood_field))
783 source.(flood_field) = max(time - flood_burst * flood_spl, source.(flood_field)) + flood_spl;
788 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
789 source.(flood_field) = flood = 0;
792 if(flood == 2) // cannot happen for empty msgstr
794 if(autocvar_g_chat_flood_notify_flooder)
796 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
801 sourcemsgstr = fullmsgstr;
802 sourcecmsgstr = fullcmsgstr;
808 sourcemsgstr = msgstr;
809 sourcecmsgstr = cmsgstr;
813 if (!IS_PLAYER(source))
815 if (!intermission_running)
816 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
817 teamsay = -1; // spectators
821 print("NOTE: ", playername(source), "^7 is flooding.\n");
823 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
825 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
829 // always fake the message
834 if (autocvar_g_chat_flood_notify_flooder)
836 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.(flood_field) - time), "^3 seconds\n"));
847 if(sourcemsgstr != "" && ret != 0)
849 if(ret < 0) // faked message, because the player is muted
851 sprint(source, sourcemsgstr);
852 if(sourcecmsgstr != "" && !privatesay)
853 centerprint(source, sourcecmsgstr);
855 else if(privatesay) // private message, between 2 people only
857 sprint(source, sourcemsgstr);
858 sprint(privatesay, msgstr);
859 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
861 centerprint(privatesay, cmsgstr);
863 else if(teamsay > 0) // team message, only sent to team mates
865 sprint(source, sourcemsgstr);
866 dedicated_print(msgstr); // send to server console too
867 if(sourcecmsgstr != "")
868 centerprint(source, sourcecmsgstr);
869 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
872 sprint(head, msgstr);
874 centerprint(head, cmsgstr);
877 else if(teamsay < 0) // spectator message, only sent to spectators
879 sprint(source, sourcemsgstr);
880 dedicated_print(msgstr); // send to server console too
881 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
883 sprint(head, msgstr);
885 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
887 sprint(source, sourcemsgstr);
888 dedicated_print(msgstr); // send to server console too
889 FOR_EACH_REALCLIENT(head)
891 sprint(head, msgstr);
894 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
900 float GetVoiceMessageVoiceType(string type)
903 return VOICETYPE_TAUNT;
904 if(type == "teamshoot")
905 return VOICETYPE_LASTATTACKER;
906 return VOICETYPE_TEAMRADIO;
909 .string GetVoiceMessageSampleField(string type)
911 GetPlayerSoundSampleField_notFound = 0;
914 #define _VOICEMSG(m) case #m: return playersound_##m;
918 GetPlayerSoundSampleField_notFound = 1;
919 return playersound_taunt;
922 .string GetPlayerSoundSampleField(string type)
924 GetPlayerSoundSampleField_notFound = 0;
927 #define _VOICEMSG(m) case #m: return playersound_##m;
931 GetPlayerSoundSampleField_notFound = 1;
932 return playersound_taunt;
935 void PrecacheGlobalSound(string samplestring)
938 tokenize_console(samplestring);
942 for(i = 1; i <= n; ++i)
943 precache_sound(strcat(argv(0), ftos(i), ".wav"));
947 precache_sound(strcat(argv(0), ".wav"));
951 void PrecachePlayerSounds(string f)
955 fh = fopen(f, FILE_READ);
958 while((s = fgets(fh)))
960 if(tokenize_console(s) != 3)
962 dprint("Invalid sound info line: ", s, "\n");
965 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
969 if (!allvoicesamples)
971 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
974 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
978 void ClearPlayerSounds()
980 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
986 float LoadPlayerSounds(string f, float first)
991 fh = fopen(f, FILE_READ);
994 dprint("Player sound file not found: ", f, "\n");
997 while((s = fgets(fh)))
999 if(tokenize_console(s) != 3)
1001 field = GetPlayerSoundSampleField(argv(0));
1002 if(GetPlayerSoundSampleField_notFound)
1003 field = GetVoiceMessageSampleField(argv(0));
1004 if(GetPlayerSoundSampleField_notFound)
1007 strunzone(self.(field));
1008 self.(field) = strzone(strcat(argv(1), " ", argv(2)));
1014 void UpdatePlayerSounds()
1016 if(self.modelindex == self.modelindex_for_playersound)
1017 if(self.skin == self.skin_for_playersound)
1019 self.modelindex_for_playersound = self.modelindex;
1020 self.skin_for_playersound = self.skin;
1021 ClearPlayerSounds();
1022 LoadPlayerSounds("sound/player/default.sounds", 1);
1023 if(!autocvar_g_debug_defaultsounds)
1024 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1025 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1028 void FakeGlobalSound(string sample, float chan, float voicetype)
1036 tokenize_console(sample);
1039 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1041 sample = strcat(argv(0), ".wav"); // randomization
1045 case VOICETYPE_LASTATTACKER_ONLY:
1047 case VOICETYPE_LASTATTACKER:
1051 if(IS_REAL_CLIENT(msg_entity))
1052 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1055 case VOICETYPE_TEAMRADIO:
1057 if(msg_entity.cvar_cl_voice_directional == 1)
1058 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1060 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1062 case VOICETYPE_AUTOTAUNT:
1067 if(autocvar_sv_gentle)
1069 tauntrand = random();
1071 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1073 if (msg_entity.cvar_cl_voice_directional >= 1)
1074 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1076 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1079 case VOICETYPE_TAUNT:
1081 if(self.deadflag == DEAD_NO)
1082 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1085 if(autocvar_sv_gentle)
1088 if (msg_entity.cvar_cl_voice_directional >= 1)
1089 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1091 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1093 case VOICETYPE_PLAYERSOUND:
1095 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1098 backtrace("Invalid voice type!");
1103 void GlobalSound(string sample, float chan, float voicetype)
1111 tokenize_console(sample);
1114 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1116 sample = strcat(argv(0), ".wav"); // randomization
1120 case VOICETYPE_LASTATTACKER_ONLY:
1123 msg_entity = self.pusher;
1124 if(IS_REAL_CLIENT(msg_entity))
1126 if(msg_entity.cvar_cl_voice_directional == 1)
1127 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1129 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1133 case VOICETYPE_LASTATTACKER:
1136 msg_entity = self.pusher;
1137 if(IS_REAL_CLIENT(msg_entity))
1139 if(msg_entity.cvar_cl_voice_directional == 1)
1140 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1142 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1145 if(IS_REAL_CLIENT(msg_entity))
1146 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1149 case VOICETYPE_TEAMRADIO:
1150 FOR_EACH_REALCLIENT(msg_entity)
1151 if(!teamplay || msg_entity.team == self.team)
1153 if(msg_entity.cvar_cl_voice_directional == 1)
1154 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1156 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1159 case VOICETYPE_AUTOTAUNT:
1164 if(autocvar_sv_gentle)
1166 tauntrand = random();
1167 FOR_EACH_REALCLIENT(msg_entity)
1168 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1170 if (msg_entity.cvar_cl_voice_directional >= 1)
1171 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1173 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1176 case VOICETYPE_TAUNT:
1178 if(self.deadflag == DEAD_NO)
1179 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1182 if(autocvar_sv_gentle)
1184 FOR_EACH_REALCLIENT(msg_entity)
1186 if (msg_entity.cvar_cl_voice_directional >= 1)
1187 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1189 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1192 case VOICETYPE_PLAYERSOUND:
1193 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1196 backtrace("Invalid voice type!");
1201 void PlayerSound(.string samplefield, float chan, float voicetype)
1203 GlobalSound(self.(samplefield), chan, voicetype);
1206 void VoiceMessage(string type, string msg)
1209 float voicetype, ownteam;
1211 sample = GetVoiceMessageSampleField(type);
1213 if(GetPlayerSoundSampleField_notFound)
1215 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1219 voicetype = GetVoiceMessageVoiceType(type);
1220 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1222 flood = Say(self, ownteam, world, msg, 1);
1224 if (IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1225 FakeGlobalSound(self.(sample), CH_VOICE, voicetype);
1227 GlobalSound(self.(sample), CH_VOICE, voicetype);
1230 void MoveToTeam(entity client, float team_colour, float type)
1232 float lockteams_backup;
1234 lockteams_backup = lockteams; // backup any team lock
1236 lockteams = 0; // disable locked teams
1238 TeamchangeFrags(client); // move the players frags
1239 SetPlayerColors(client, team_colour - 1); // set the players colour
1240 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1242 lockteams = lockteams_backup; // restore the team lock
1244 LogTeamchange(client.playerid, client.team, type);