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 #include "../common/animdecide.qh"
10 void CopyBody_Think(void)
12 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
14 self.CopyBody_think();
17 self.CopyBody_nextthink = self.nextthink;
18 self.CopyBody_think = self.think;
19 self.think = CopyBody_Think;
21 CSQCMODEL_AUTOUPDATE();
22 self.nextthink = time;
24 void CopyBody(float keepvelocity)
27 if (self.effects & EF_NODRAW)
32 self.lip = oldself.lip;
33 self.colormap = oldself.colormap;
34 self.iscreature = oldself.iscreature;
35 self.teleportable = oldself.teleportable;
36 self.damagedbycontents = oldself.damagedbycontents;
37 self.angles = oldself.angles;
38 self.v_angle = oldself.v_angle;
39 self.avelocity = oldself.avelocity;
40 self.classname = "body";
41 self.damageforcescale = oldself.damageforcescale;
42 self.effects = oldself.effects;
43 self.glowmod = oldself.glowmod;
44 self.event_damage = oldself.event_damage;
45 self.anim_state = oldself.anim_state;
46 self.anim_time = oldself.anim_time;
47 self.anim_lower_action = oldself.anim_lower_action;
48 self.anim_lower_time = oldself.anim_lower_time;
49 self.anim_upper_action = oldself.anim_upper_action;
50 self.anim_upper_time = oldself.anim_upper_time;
51 self.anim_implicit_state = oldself.anim_implicit_state;
52 self.anim_implicit_time = oldself.anim_implicit_time;
53 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
54 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
55 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
56 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
57 self.dphitcontentsmask = oldself.dphitcontentsmask;
58 self.death_time = oldself.death_time;
59 self.pain_finished = oldself.pain_finished;
60 self.health = oldself.health;
61 self.armorvalue = oldself.armorvalue;
62 self.armortype = oldself.armortype;
63 self.model = oldself.model;
64 self.modelindex = oldself.modelindex;
65 self.skin = oldself.skin;
66 self.species = oldself.species;
67 self.movetype = oldself.movetype;
68 self.solid = oldself.solid;
69 self.ballistics_density = oldself.ballistics_density;
70 self.takedamage = oldself.takedamage;
71 self.customizeentityforclient = oldself.customizeentityforclient;
72 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
73 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
74 if (keepvelocity == 1)
75 self.velocity = oldself.velocity;
76 self.oldvelocity = self.velocity;
77 self.alpha = oldself.alpha;
78 self.fade_time = oldself.fade_time;
79 self.fade_rate = oldself.fade_rate;
80 //self.weapon = oldself.weapon;
81 setorigin(self, oldself.origin);
82 setsize(self, oldself.mins, oldself.maxs);
83 self.prevorigin = oldself.origin;
84 self.reset = SUB_Remove;
86 Drag_MoveDrag(oldself, self);
88 if(self.colormap <= maxclients && self.colormap > 0)
89 self.colormap = 1024 + oldself.clientcolors;
92 self.CopyBody_nextthink = oldself.nextthink;
93 self.CopyBody_think = oldself.think;
94 self.nextthink = time;
95 self.think = CopyBody_Think;
96 // "bake" the current animation frame for clones (they don't get clientside animation)
97 animdecide_load_if_needed(self);
98 animdecide_setframes(self, false, frame, frame1time, frame2, frame2time);
103 float player_getspecies()
106 get_model_parameters(self.model, self.skin);
107 s = get_model_parameters_species;
108 get_model_parameters(string_null, 0);
110 return SPECIES_HUMAN;
114 void player_setupanimsformodel()
116 // load animation info
117 animdecide_load_if_needed(self);
118 animdecide_setstate(self, 0, false);
121 void player_anim (void)
123 int deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
126 // Decide on which death animation to use.
128 deadbits = ANIMSTATE_DEAD1;
130 deadbits = ANIMSTATE_DEAD2;
133 // Clear a previous death animation.
136 int animbits = deadbits;
138 animbits |= ANIMSTATE_FROZEN;
140 animbits |= ANIMSTATE_DUCK;
141 animdecide_setstate(self, animbits, false);
142 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
144 if (self.weaponentity)
146 updateanim(self.weaponentity);
147 if (!self.weaponentity.animstate_override)
148 setanim(self.weaponentity, self.weaponentity.anim_idle, true, false, false);
152 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
156 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
158 // damage resistance (ignore most of the damage from a bullet or similar)
159 damage = max(damage - 5, 1);
161 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
165 if(sound_allowed(MSG_BROADCAST, attacker))
168 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
170 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
172 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
176 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
178 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
180 self.armorvalue = self.armorvalue - save;
181 self.health = self.health - take;
182 // pause regeneration for 5 seconds
183 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
185 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
186 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
187 self.dmg_inflictor = inflictor;
189 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
191 // don't use any animations as a gib
193 // view just above the floor
194 self.view_ofs = '0 0 4';
196 Violence_GibSplash(self, 1, 1, attacker);
198 self.solid = SOLID_NOT; // restore later
199 self.takedamage = DAMAGE_NO; // restore later
200 self.damagedbycontents = false;
204 void calculate_player_respawn_time()
209 float gametype_setting_tmp;
210 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
211 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
212 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
213 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
214 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
215 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
217 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
223 if (pl.team == self.team)
225 if (sdelay_small_count == 0)
226 sdelay_small_count = 1;
227 if (sdelay_large_count == 0)
228 sdelay_large_count = 1;
235 if (sdelay_small_count == 0)
239 // Players play independently. No point in requiring enemies.
240 sdelay_small_count = 1;
244 // Players play AGAINST each other. Enemies required.
245 sdelay_small_count = 2;
248 if (sdelay_large_count == 0)
252 // Players play independently. No point in requiring enemies.
253 sdelay_large_count = 1;
257 // Players play AGAINST each other. Enemies required.
258 sdelay_large_count = 2;
265 if (pcount <= sdelay_small_count)
266 sdelay = sdelay_small;
267 else if (pcount >= sdelay_large_count)
268 sdelay = sdelay_large;
269 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
270 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
273 self.respawn_time = ceil((time + sdelay) / waves) * waves;
275 self.respawn_time = time + sdelay;
277 if(sdelay < sdelay_max)
278 self.respawn_time_max = time + sdelay_max;
280 self.respawn_time_max = self.respawn_time;
282 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
283 self.respawn_countdown = 10; // first number to count down from is 10
285 self.respawn_countdown = -1; // do not count down
287 if(autocvar_g_forced_respawn)
288 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
291 void PlayerDamage (entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
293 float take, save, dh, da;
296 float valid_damage_for_weaponstats;
299 dh = max(self.health, 0);
300 da = max(self.armorvalue, 0);
302 if(!DEATH_ISSPECIAL(deathtype))
304 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
306 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
309 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
311 // tuba causes blood to come out of the ears
316 ear1_z += 0.125 * self.view_ofs.z + 0.875 * self.maxs.z; // 7/8
318 makevectors(self.angles);
319 ear1 += v_right * -10;
320 ear2 += v_right * +10;
321 d = inflictor.origin - self.origin;
323 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
325 f = 0; // Assum ecenter.
326 force = v_right * vlen(force);
327 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
328 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
337 // force is already good
341 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
344 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
350 // don't reset pushltime for self damage as it may be an attempt to
351 // escape a lava pit or similar
352 //self.pushltime = 0;
355 else if(IS_PLAYER(attacker))
357 self.pusher = attacker;
358 self.pushltime = time + autocvar_g_maxpushtime;
359 self.istypefrag = self.BUTTON_CHAT;
361 else if(time < self.pushltime)
363 attacker = self.pusher;
364 self.pushltime = max(self.pushltime, time + 0.6);
372 frag_inflictor = inflictor;
373 frag_attacker = attacker;
375 frag_damage = damage;
378 damage_force = force;
379 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
380 take = bound(0, damage_take, self.health);
381 save = bound(0, damage_save, self.armorvalue);
382 excess = max(0, damage - take - save);
384 if(sound_allowed(MSG_BROADCAST, attacker))
387 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
389 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
391 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
395 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
397 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
399 if (time >= self.spawnshieldtime)
401 if (!(self.flags & FL_GODMODE))
403 self.armorvalue = self.armorvalue - save;
404 self.health = self.health - take;
405 // pause regeneration for 5 seconds
407 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
409 if (time > self.pain_finished) //Don't switch pain sequences like crazy
411 self.pain_finished = time + 0.5; //Supajoe
413 if(autocvar_sv_gentle < 1) {
414 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
416 if (!self.animstate_override)
419 animdecide_setaction(self, ANIMACTION_PAIN1, true);
421 animdecide_setaction(self, ANIMACTION_PAIN2, true);
425 if(sound_allowed(MSG_BROADCAST, attacker))
426 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
428 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
430 if(deathtype == DEATH_FALL)
431 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
432 else if(self.health > 75) // TODO make a "gentle" version?
433 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
434 else if(self.health > 50)
435 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
436 else if(self.health > 25)
437 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
439 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
444 // throw off bot aim temporarily
446 if(IS_BOT_CLIENT(self) && self.health >= 1)
448 shake = damage * 5 / (bound(0,skill,100) + 1);
449 self.v_angle_x = self.v_angle.x + (random() * 2 - 1) * shake;
450 self.v_angle_y = self.v_angle.y + (random() * 2 - 1) * shake;
451 self.v_angle_x = bound(-90, self.v_angle.x, 90);
455 self.max_armorvalue += (save + take);
457 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
458 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
459 self.dmg_inflictor = inflictor;
461 float abot, vbot, awep;
462 abot = (IS_BOT_CLIENT(attacker));
463 vbot = (IS_BOT_CLIENT(self));
465 valid_damage_for_weaponstats = 0;
468 if(vbot || IS_REAL_CLIENT(self))
469 if(abot || IS_REAL_CLIENT(attacker))
470 if(attacker && self != attacker)
471 if(DIFF_TEAM(self, attacker))
473 if(DEATH_ISSPECIAL(deathtype))
474 awep = attacker.weapon;
476 awep = DEATH_WEAPONOF(deathtype);
477 valid_damage_for_weaponstats = 1;
480 if(valid_damage_for_weaponstats)
482 dh = dh - max(self.health, 0);
483 da = da - max(self.armorvalue, 0);
484 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
489 float defer_ClientKill_Now_TeamChange;
490 defer_ClientKill_Now_TeamChange = false;
494 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
498 if(valid_damage_for_weaponstats)
499 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
501 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
502 if(sound_allowed(MSG_BROADCAST, attacker))
504 if(deathtype == DEATH_DROWN)
505 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
507 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
510 // get rid of kill indicator
511 if(self.killindicator)
513 remove(self.killindicator);
514 self.killindicator = world;
515 if(self.killindicator_teamchange)
516 defer_ClientKill_Now_TeamChange = true;
518 if(self.classname == "body")
519 if(deathtype == DEATH_KILL)
521 // for the lemmings fans, a small harmless explosion
522 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
526 // print an obituary message
527 if(self.classname != "body")
528 Obituary (attacker, inflictor, self, deathtype);
530 // increment frag counter for used weapon type
531 int w = DEATH_WEAPONOF(deathtype);
533 if(accuracy_isgooddamage(attacker, self))
534 attacker.accuracy.(accuracy_frags[w-1]) += 1;
536 frag_attacker = attacker;
537 frag_inflictor = inflictor;
539 frag_deathtype = deathtype;
540 MUTATOR_CALLHOOK(PlayerDies);
542 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
544 RemoveGrapplingHook(self);
546 Portal_ClearAllLater(self);
548 self.fixangle = true;
550 if(defer_ClientKill_Now_TeamChange)
551 ClientKill_Now_TeamChange(); // can turn player into spectator
553 // player could have been miraculously resuscitated ;)
554 // e.g. players in freezetag get frozen, they don't really die
555 if(self.health >= 1 || !(IS_PLAYER(self) || self.classname == "body"))
558 // when we get here, player actually dies
560 Unfreeze(self); // remove any icy remains
561 self.health = 0; // Unfreeze resets health, so we need to set it back
564 WaypointSprite_PlayerDead();
566 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
568 // become fully visible
569 self.alpha = default_player_alpha;
570 // make the corpse upright (not tilted)
574 self.avelocity = '0 0 0';
575 // view from the floor
576 self.view_ofs = '0 0 -8';
578 self.movetype = MOVETYPE_TOSS;
580 self.solid = SOLID_CORPSE;
581 self.ballistics_density = autocvar_g_ballistics_density_corpse;
582 // don't stick to the floor
583 self.flags &= ~FL_ONGROUND;
585 self.deadflag = DEAD_DYING;
587 // when to allow respawn
588 calculate_player_respawn_time();
590 self.death_time = time;
592 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, true);
594 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, true);
598 setsize(self, self.mins, self.maxs);
600 // set damage function to corpse damage
601 self.event_damage = PlayerCorpseDamage;
602 // call the corpse damage function just in case it wants to gib
603 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
605 // set up to fade out later
606 SUB_SetFade (self, time + 6 + random (), 1);
607 // reset body think wrapper broken by SUB_SetFade
608 if(self.classname == "body" && self.think != CopyBody_Think) {
609 self.CopyBody_think = self.think;
610 self.CopyBody_nextthink = self.nextthink;
611 self.think = CopyBody_Think;
612 self.nextthink = time;
615 if(autocvar_sv_gentle > 0 || autocvar_ekg || self.classname == "body") {
617 // clones don't run any animation code any more, so we must gib them when they die :(
618 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
621 // reset fields the weapons may use just in case
622 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
624 WEP_ACTION(j, WR_RESETPLAYER);
625 ATTACK_FINISHED_FOR(self, j) = 0;
630 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
631 // message "": do not say, just test flood control
637 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
639 var .float flood_field;
642 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
644 if(!teamsay && !privatesay)
645 if(substring(msgin, 0, 1) == " ")
646 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
648 msgin = formatmessage(msgin);
650 if (!IS_PLAYER(source))
651 colorstr = "^0"; // black for spectators
653 colorstr = Team_ColorCode(source.team);
660 if(intermission_running)
664 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
667 * using bprint solves this... me stupid
668 // how can we prevent the message from appearing in a listen server?
669 // for now, just give "say" back and only handle say_team
672 clientcommand(self, strcat("say ", msgin));
677 if(autocvar_g_chat_teamcolors)
678 namestr = playername(source);
680 namestr = source.netname;
682 if(strdecolorize(namestr) == namestr)
691 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
692 privatemsgprefixlen = strlen(msgstr);
693 msgstr = strcat(msgstr, msgin);
694 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
695 if(autocvar_g_chat_teamcolors)
696 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
698 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
702 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
703 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
707 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
710 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
714 msgstr = cmsgstr = "";
718 fullcmsgstr = cmsgstr;
722 flood_field = floodcontrol_chat;
731 flood_spl = autocvar_g_chat_flood_spl_tell;
732 flood_burst = autocvar_g_chat_flood_burst_tell;
733 flood_lmax = autocvar_g_chat_flood_lmax_tell;
734 flood_field = floodcontrol_chattell;
738 flood_spl = autocvar_g_chat_flood_spl_team;
739 flood_burst = autocvar_g_chat_flood_burst_team;
740 flood_lmax = autocvar_g_chat_flood_lmax_team;
741 flood_field = floodcontrol_chatteam;
745 flood_spl = autocvar_g_chat_flood_spl;
746 flood_burst = autocvar_g_chat_flood_burst;
747 flood_lmax = autocvar_g_chat_flood_lmax;
748 flood_field = floodcontrol_chat;
750 flood_burst = max(0, flood_burst - 1);
751 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
753 // do flood control for the default line size
756 getWrappedLine_remaining = msgstr;
759 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
761 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
764 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
766 if(getWrappedLine_remaining != "")
768 msgstr = strcat(msgstr, "\n");
772 if(time >= source.flood_field)
774 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
784 if(time >= source.flood_field)
785 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
790 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
791 source.flood_field = flood = 0;
794 if(flood == 2) // cannot happen for empty msgstr
796 if(autocvar_g_chat_flood_notify_flooder)
798 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
803 sourcemsgstr = fullmsgstr;
804 sourcecmsgstr = fullcmsgstr;
810 sourcemsgstr = msgstr;
811 sourcecmsgstr = cmsgstr;
815 if (!IS_PLAYER(source))
817 if (!intermission_running)
818 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
819 teamsay = -1; // spectators
823 print("NOTE: ", playername(source), "^7 is flooding.\n");
825 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
827 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
831 // always fake the message
836 if(autocvar_g_chat_flood_notify_flooder)
838 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
849 if(sourcemsgstr != "" && ret != 0)
851 if(ret < 0) // faked message, because the player is muted
853 sprint(source, sourcemsgstr);
854 if(sourcecmsgstr != "" && !privatesay)
855 centerprint(source, sourcecmsgstr);
857 else if(privatesay) // private message, between 2 people only
859 sprint(source, sourcemsgstr);
860 sprint(privatesay, msgstr);
861 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
863 centerprint(privatesay, cmsgstr);
865 else if(teamsay > 0) // team message, only sent to team mates
867 sprint(source, sourcemsgstr);
868 dedicated_print(msgstr); // send to server console too
869 if(sourcecmsgstr != "")
870 centerprint(source, sourcecmsgstr);
871 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
874 sprint(head, msgstr);
876 centerprint(head, cmsgstr);
879 else if(teamsay < 0) // spectator message, only sent to spectators
881 sprint(source, sourcemsgstr);
882 dedicated_print(msgstr); // send to server console too
883 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
885 sprint(head, msgstr);
887 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
889 sprint(source, sourcemsgstr);
890 dedicated_print(msgstr); // send to server console too
891 FOR_EACH_REALCLIENT(head)
893 sprint(head, msgstr);
896 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
902 float GetVoiceMessageVoiceType(string type)
905 return VOICETYPE_TAUNT;
906 if(type == "teamshoot")
907 return VOICETYPE_LASTATTACKER;
908 return VOICETYPE_TEAMRADIO;
911 .string GetVoiceMessageSampleField(string type)
913 GetPlayerSoundSampleField_notFound = 0;
916 #define _VOICEMSG(m) case #m: return playersound_##m;
920 GetPlayerSoundSampleField_notFound = 1;
921 return playersound_taunt;
924 .string GetPlayerSoundSampleField(string type)
926 GetPlayerSoundSampleField_notFound = 0;
929 #define _VOICEMSG(m) case #m: return playersound_##m;
933 GetPlayerSoundSampleField_notFound = 1;
934 return playersound_taunt;
937 void PrecacheGlobalSound(string samplestring)
940 tokenize_console(samplestring);
944 for(i = 1; i <= n; ++i)
945 precache_sound(strcat(argv(0), ftos(i), ".wav"));
949 precache_sound(strcat(argv(0), ".wav"));
953 void PrecachePlayerSounds(string f)
957 fh = fopen(f, FILE_READ);
960 while((s = fgets(fh)))
962 if(tokenize_console(s) != 3)
964 dprint("Invalid sound info line: ", s, "\n");
967 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
971 if (!allvoicesamples)
973 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
976 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
980 void ClearPlayerSounds()
982 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
988 float LoadPlayerSounds(string f, float first)
993 fh = fopen(f, FILE_READ);
996 dprint("Player sound file not found: ", f, "\n");
999 while((s = fgets(fh)))
1001 if(tokenize_console(s) != 3)
1003 field = GetPlayerSoundSampleField(argv(0));
1004 if(GetPlayerSoundSampleField_notFound)
1005 field = GetVoiceMessageSampleField(argv(0));
1006 if(GetPlayerSoundSampleField_notFound)
1009 strunzone(self.field);
1010 self.field = strzone(strcat(argv(1), " ", argv(2)));
1016 void UpdatePlayerSounds()
1018 if(self.modelindex == self.modelindex_for_playersound)
1019 if(self.skin == self.skin_for_playersound)
1021 self.modelindex_for_playersound = self.modelindex;
1022 self.skin_for_playersound = self.skin;
1023 ClearPlayerSounds();
1024 LoadPlayerSounds("sound/player/default.sounds", 1);
1025 if(!autocvar_g_debug_defaultsounds)
1026 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1027 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1030 void FakeGlobalSound(string sample, float chan, float voicetype)
1038 tokenize_console(sample);
1041 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1043 sample = strcat(argv(0), ".wav"); // randomization
1047 case VOICETYPE_LASTATTACKER_ONLY:
1049 case VOICETYPE_LASTATTACKER:
1053 if(IS_REAL_CLIENT(msg_entity))
1054 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1057 case VOICETYPE_TEAMRADIO:
1059 if(msg_entity.cvar_cl_voice_directional == 1)
1060 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1062 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1064 case VOICETYPE_AUTOTAUNT:
1069 if(autocvar_sv_gentle)
1071 tauntrand = random();
1073 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1075 if (msg_entity.cvar_cl_voice_directional >= 1)
1076 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1078 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1081 case VOICETYPE_TAUNT:
1083 if(self.deadflag == DEAD_NO)
1084 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1087 if(autocvar_sv_gentle)
1090 if (msg_entity.cvar_cl_voice_directional >= 1)
1091 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1093 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1095 case VOICETYPE_PLAYERSOUND:
1097 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1100 backtrace("Invalid voice type!");
1105 void GlobalSound(string sample, float chan, float voicetype)
1113 tokenize_console(sample);
1116 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1118 sample = strcat(argv(0), ".wav"); // randomization
1122 case VOICETYPE_LASTATTACKER_ONLY:
1125 msg_entity = self.pusher;
1126 if(IS_REAL_CLIENT(msg_entity))
1128 if(msg_entity.cvar_cl_voice_directional == 1)
1129 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1131 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1135 case VOICETYPE_LASTATTACKER:
1138 msg_entity = self.pusher;
1139 if(IS_REAL_CLIENT(msg_entity))
1141 if(msg_entity.cvar_cl_voice_directional == 1)
1142 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1144 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1147 if(IS_REAL_CLIENT(msg_entity))
1148 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1151 case VOICETYPE_TEAMRADIO:
1152 FOR_EACH_REALCLIENT(msg_entity)
1153 if(!teamplay || msg_entity.team == self.team)
1155 if(msg_entity.cvar_cl_voice_directional == 1)
1156 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1158 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1161 case VOICETYPE_AUTOTAUNT:
1166 if(autocvar_sv_gentle)
1168 tauntrand = random();
1169 FOR_EACH_REALCLIENT(msg_entity)
1170 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1172 if (msg_entity.cvar_cl_voice_directional >= 1)
1173 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1175 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1178 case VOICETYPE_TAUNT:
1180 if(self.deadflag == DEAD_NO)
1181 animdecide_setaction(self, ANIMACTION_TAUNT, true);
1184 if(autocvar_sv_gentle)
1186 FOR_EACH_REALCLIENT(msg_entity)
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));
1191 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1194 case VOICETYPE_PLAYERSOUND:
1195 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1198 backtrace("Invalid voice type!");
1203 void PlayerSound(.string samplefield, float chan, float voicetype)
1205 GlobalSound(self.samplefield, chan, voicetype);
1208 void VoiceMessage(string type, string msg)
1211 float voicetype, ownteam;
1213 sample = GetVoiceMessageSampleField(type);
1215 if(GetPlayerSoundSampleField_notFound)
1217 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1221 voicetype = GetVoiceMessageVoiceType(type);
1222 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1224 flood = Say(self, ownteam, world, msg, 1);
1226 if(IS_SPEC(self) || IS_OBSERVER(self) || flood < 0)
1227 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1229 GlobalSound(self.sample, CH_VOICE, voicetype);
1232 void MoveToTeam(entity client, float team_colour, float type)
1234 float lockteams_backup;
1236 lockteams_backup = lockteams; // backup any team lock
1238 lockteams = 0; // disable locked teams
1240 TeamchangeFrags(client); // move the players frags
1241 SetPlayerColors(client, team_colour - 1); // set the players colour
1242 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1244 lockteams = lockteams_backup; // restore the team lock
1246 LogTeamchange(client.playerid, client.team, type);