5 .float CopyBody_nextthink;
6 .void(void) CopyBody_think;
7 void CopyBody_Think(void)
9 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
11 self.CopyBody_think();
14 self.CopyBody_nextthink = self.nextthink;
15 self.CopyBody_think = self.think;
16 self.think = CopyBody_Think;
18 CSQCMODEL_AUTOUPDATE();
19 self.nextthink = time;
21 void CopyBody(float keepvelocity)
24 if (self.effects & EF_NODRAW)
29 self.lip = oldself.lip;
30 self.colormap = oldself.colormap;
31 self.iscreature = oldself.iscreature;
32 self.teleportable = oldself.teleportable;
33 self.damagedbycontents = oldself.damagedbycontents;
34 self.angles = oldself.angles;
35 self.v_angle = oldself.v_angle;
36 self.avelocity = oldself.avelocity;
37 self.classname = "body";
38 self.damageforcescale = oldself.damageforcescale;
39 self.effects = oldself.effects;
40 self.glowmod = oldself.glowmod;
41 self.event_damage = oldself.event_damage;
42 self.anim_state = oldself.anim_state;
43 self.anim_time = oldself.anim_time;
44 self.anim_lower_action = oldself.anim_lower_action;
45 self.anim_lower_time = oldself.anim_lower_time;
46 self.anim_upper_action = oldself.anim_upper_action;
47 self.anim_upper_time = oldself.anim_upper_time;
48 self.anim_implicit_state = oldself.anim_implicit_state;
49 self.anim_implicit_time = oldself.anim_implicit_time;
50 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
51 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
52 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
53 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
54 self.dphitcontentsmask = oldself.dphitcontentsmask;
55 self.death_time = oldself.death_time;
56 self.pain_finished = oldself.pain_finished;
57 self.health = oldself.health;
58 self.armorvalue = oldself.armorvalue;
59 self.armortype = oldself.armortype;
60 self.model = oldself.model;
61 self.modelindex = oldself.modelindex;
62 self.skin = oldself.skin;
63 self.species = oldself.species;
64 self.movetype = oldself.movetype;
65 self.solid = oldself.solid;
66 self.ballistics_density = oldself.ballistics_density;
67 self.takedamage = oldself.takedamage;
68 self.customizeentityforclient = oldself.customizeentityforclient;
69 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
70 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
71 if (keepvelocity == 1)
72 self.velocity = oldself.velocity;
73 self.oldvelocity = self.velocity;
74 self.alpha = oldself.alpha;
75 self.fade_time = oldself.fade_time;
76 self.fade_rate = oldself.fade_rate;
77 //self.weapon = oldself.weapon;
78 setorigin(self, oldself.origin);
79 setsize(self, oldself.mins, oldself.maxs);
80 self.prevorigin = oldself.origin;
81 self.reset = SUB_Remove;
83 Drag_MoveDrag(oldself, self);
85 if(self.colormap <= maxclients && self.colormap > 0)
86 self.colormap = 1024 + oldself.clientcolors;
89 self.CopyBody_nextthink = oldself.nextthink;
90 self.CopyBody_think = oldself.think;
91 self.nextthink = time;
92 self.think = CopyBody_Think;
93 // "bake" the current animation frame for clones (they don't get clientside animation)
94 animdecide_setframes(self, FALSE, frame, frame1time, frame2, frame2time);
99 float player_getspecies()
102 get_model_parameters(self.model, self.skin);
103 s = get_model_parameters_species;
104 get_model_parameters(string_null, 0);
106 return SPECIES_HUMAN;
110 void player_setupanimsformodel()
112 // load animation info
113 animdecide_init(self);
114 animdecide_setstate(self, 0, FALSE);
117 void player_anim (void)
119 float deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
120 if(self.deadflag && !deadbits)
122 deadbits = ANIMSTATE_DEAD1;
124 deadbits = ANIMSTATE_DEAD2;
125 float animbits = deadbits;
126 if(self.freezetag_frozen)
127 animbits |= ANIMSTATE_FROZEN;
129 animbits |= ANIMSTATE_DUCK;
130 animdecide_setstate(self, animbits, FALSE);
131 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
133 if (self.weaponentity)
135 updateanim(self.weaponentity);
136 if (!self.weaponentity.animstate_override)
137 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
141 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
145 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
147 // damage resistance (ignore most of the damage from a bullet or similar)
148 damage = max(damage - 5, 1);
150 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
154 if(sound_allowed(MSG_BROADCAST, attacker))
157 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
159 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
161 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
165 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
167 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
169 if (!(self.flags & FL_GODMODE))
171 self.armorvalue = self.armorvalue - save;
172 self.health = self.health - take;
173 // pause regeneration for 5 seconds
174 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
176 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
177 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
178 self.dmg_inflictor = inflictor;
180 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
182 // don't use any animations as a gib
184 // view just above the floor
185 self.view_ofs = '0 0 4';
187 Violence_GibSplash(self, 1, 1, attacker);
189 self.solid = SOLID_NOT; // restore later
190 self.takedamage = DAMAGE_NO; // restore later
191 self.damagedbycontents = FALSE;
196 // If 0, default is used.
198 // Otherwise, g_str (default value) is used.
199 // For consistency, negative values there are mapped to zero too.
200 #define GAMETYPE_DEFAULTED_SETTING(str) \
201 ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
202 (gametype_setting_tmp < 0) ? 0 : \
203 (gametype_setting_tmp == 0) ? max(0, autocvar_g_##str) : \
204 gametype_setting_tmp)
207 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(g_cts || autocvar_g_forced_respawn)
288 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
291 void ClientKill_Now_TeamChange();
293 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
295 float take, save, dh, da, j;
297 float valid_damage_for_weaponstats;
300 dh = max(self.health, 0);
301 da = max(self.armorvalue, 0);
303 if(!DEATH_ISSPECIAL(deathtype))
305 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
307 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
310 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
312 // tuba causes blood to come out of the ears
317 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
319 makevectors(self.angles);
320 ear1 += v_right * -10;
321 ear2 += v_right * +10;
322 d = inflictor.origin - self.origin;
324 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
326 f = 0; // Assum ecenter.
327 force = v_right * vlen(force);
328 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
329 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
338 // force is already good
342 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
345 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
351 // don't reset pushltime for self damage as it may be an attempt to
352 // escape a lava pit or similar
353 //self.pushltime = 0;
356 else if(IS_PLAYER(attacker))
358 self.pusher = attacker;
359 self.pushltime = time + autocvar_g_maxpushtime;
360 self.istypefrag = self.BUTTON_CHAT;
362 else if(time < self.pushltime)
364 attacker = self.pusher;
365 self.pushltime = max(self.pushltime, time + 0.6);
373 frag_inflictor = inflictor;
374 frag_attacker = attacker;
376 frag_damage = damage;
379 damage_force = force;
380 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
381 take = bound(0, damage_take, self.health);
382 save = bound(0, damage_save, self.armorvalue);
383 excess = max(0, damage - take - save);
385 if(sound_allowed(MSG_BROADCAST, attacker))
388 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
390 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
392 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
396 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
398 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
400 if (time >= self.spawnshieldtime)
402 if (!(self.flags & FL_GODMODE))
404 self.armorvalue = self.armorvalue - save;
405 self.health = self.health - take;
406 // pause regeneration for 5 seconds
408 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
410 if (time > self.pain_finished) //Don't switch pain sequences like crazy
412 self.pain_finished = time + 0.5; //Supajoe
414 if(autocvar_sv_gentle < 1) {
415 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
417 if (!self.animstate_override)
420 animdecide_setaction(self, ANIMACTION_PAIN1, TRUE);
422 animdecide_setaction(self, ANIMACTION_PAIN2, TRUE);
426 if(sound_allowed(MSG_BROADCAST, attacker))
427 if(!DEATH_ISWEAPON(deathtype, WEP_BLASTER) || attacker != self || self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) // WEAPONTODO: create separate limit for pain notification with laser
429 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
431 if(deathtype == DEATH_FALL)
432 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
433 else if(self.health > 75) // TODO make a "gentle" version?
434 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
435 else if(self.health > 50)
436 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
437 else if(self.health > 25)
438 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
440 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
444 // throw off bot aim temporarily
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;
452 self.max_armorvalue += (save + take);
454 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
455 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
456 self.dmg_inflictor = inflictor;
458 float abot, vbot, awep;
459 abot = (IS_BOT_CLIENT(attacker));
460 vbot = (IS_BOT_CLIENT(self));
462 valid_damage_for_weaponstats = 0;
465 if(vbot || IS_REAL_CLIENT(self))
466 if(abot || IS_REAL_CLIENT(attacker))
467 if(attacker && self != attacker)
468 if(DIFF_TEAM(self, attacker))
470 if(DEATH_ISSPECIAL(deathtype))
471 awep = attacker.weapon;
473 awep = DEATH_WEAPONOF(deathtype);
474 valid_damage_for_weaponstats = 1;
477 if(valid_damage_for_weaponstats)
479 dh = dh - max(self.health, 0);
480 da = da - max(self.armorvalue, 0);
481 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
486 float defer_ClientKill_Now_TeamChange;
487 defer_ClientKill_Now_TeamChange = FALSE;
491 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
495 if(valid_damage_for_weaponstats)
496 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
498 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
499 if(sound_allowed(MSG_BROADCAST, attacker))
501 if(deathtype == DEATH_DROWN)
502 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
504 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
507 // get rid of kill indicator
508 if(self.killindicator)
510 remove(self.killindicator);
511 self.killindicator = world;
512 if(self.killindicator_teamchange)
513 defer_ClientKill_Now_TeamChange = TRUE;
515 if(self.classname == "body")
516 if(deathtype == DEATH_KILL)
518 // for the lemmings fans, a small harmless explosion
519 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
523 // print an obituary message
524 Obituary (attacker, inflictor, self, deathtype);
527 // increment frag counter for used weapon type
529 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))
556 // when we get here, player actually dies
559 WaypointSprite_PlayerDead();
561 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
563 // become fully visible
564 self.alpha = default_player_alpha;
565 // make the corpse upright (not tilted)
569 self.avelocity = '0 0 0';
570 // view from the floor
571 self.view_ofs = '0 0 -8';
573 self.movetype = MOVETYPE_TOSS;
575 self.solid = SOLID_CORPSE;
576 self.ballistics_density = autocvar_g_ballistics_density_corpse;
577 // don't stick to the floor
578 self.flags &= ~FL_ONGROUND;
580 self.deadflag = DEAD_DYING;
581 // when to allow respawn
582 calculate_player_respawn_time();
584 self.death_time = time;
586 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, TRUE);
588 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, TRUE);
592 setsize(self, self.mins, self.maxs);
594 // set damage function to corpse damage
595 self.event_damage = PlayerCorpseDamage;
596 // call the corpse damage function just in case it wants to gib
597 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
598 // set up to fade out later
599 SUB_SetFade (self, time + 6 + random (), 1);
601 if(autocvar_sv_gentle > 0 || autocvar_ekg) {
603 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
606 // reset fields the weapons may use just in case
607 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
609 WEP_ACTION(j, WR_RESETPLAYER);
610 ATTACK_FINISHED_FOR(self, j) = 0;
615 .float muted; // to be used by prvm_edictset server playernumber muted 1
616 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
617 // message "": do not say, just test flood control
623 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
625 var .float flood_field;
628 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
630 if(!teamsay && !privatesay)
631 if(substring(msgin, 0, 1) == " ")
632 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
634 msgin = formatmessage(msgin);
636 if (!IS_PLAYER(source))
637 colorstr = "^0"; // black for spectators
639 colorstr = Team_ColorCode(source.team);
646 if(intermission_running)
650 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
653 * using bprint solves this... me stupid
654 // how can we prevent the message from appearing in a listen server?
655 // for now, just give "say" back and only handle say_team
658 clientcommand(self, strcat("say ", msgin));
663 if(autocvar_g_chat_teamcolors)
664 namestr = playername(source);
666 namestr = source.netname;
668 if(strdecolorize(namestr) == namestr)
677 msgstr = strcat("\{1}\{13}* ", colorprefix, namestr, "^3 tells you: ^7");
678 privatemsgprefixlen = strlen(msgstr);
679 msgstr = strcat(msgstr, msgin);
680 cmsgstr = strcat(colorstr, colorprefix, namestr, "^3 tells you:\n^7", msgin);
681 if(autocvar_g_chat_teamcolors)
682 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
684 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
688 msgstr = strcat("\{1}\{13}", colorstr, "(", colorprefix, namestr, colorstr, ") ^7", msgin);
689 cmsgstr = strcat(colorstr, "(", colorprefix, namestr, colorstr, ")\n^7", msgin);
693 msgstr = strcat("\{1}", colorprefix, namestr, "^7: ", msgin);
696 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
700 msgstr = cmsgstr = "";
704 fullcmsgstr = cmsgstr;
708 flood_field = floodcontrol_chat;
717 flood_spl = autocvar_g_chat_flood_spl_tell;
718 flood_burst = autocvar_g_chat_flood_burst_tell;
719 flood_lmax = autocvar_g_chat_flood_lmax_tell;
720 flood_field = floodcontrol_chattell;
724 flood_spl = autocvar_g_chat_flood_spl_team;
725 flood_burst = autocvar_g_chat_flood_burst_team;
726 flood_lmax = autocvar_g_chat_flood_lmax_team;
727 flood_field = floodcontrol_chatteam;
731 flood_spl = autocvar_g_chat_flood_spl;
732 flood_burst = autocvar_g_chat_flood_burst;
733 flood_lmax = autocvar_g_chat_flood_lmax;
734 flood_field = floodcontrol_chat;
736 flood_burst = max(0, flood_burst - 1);
737 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
739 // do flood control for the default line size
742 getWrappedLine_remaining = msgstr;
745 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
747 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
750 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
752 if(getWrappedLine_remaining != "")
754 msgstr = strcat(msgstr, "\n");
758 if(time >= source.flood_field)
760 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
770 if(time >= source.flood_field)
771 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
776 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
777 source.flood_field = flood = 0;
780 if(flood == 2) // cannot happen for empty msgstr
782 if(autocvar_g_chat_flood_notify_flooder)
784 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
789 sourcemsgstr = fullmsgstr;
790 sourcecmsgstr = fullcmsgstr;
796 sourcemsgstr = msgstr;
797 sourcecmsgstr = cmsgstr;
801 if (!IS_PLAYER(source))
803 if (!intermission_running)
804 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
805 teamsay = -1; // spectators
809 print("NOTE: ", playername(source), "^7 is flooding.\n");
811 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
813 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
817 // always fake the message
822 if(autocvar_g_chat_flood_notify_flooder)
824 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
835 if(sourcemsgstr != "" && ret != 0)
837 if(ret < 0) // faked message, because the player is muted
839 sprint(source, sourcemsgstr);
840 if(sourcecmsgstr != "" && !privatesay)
841 centerprint(source, sourcecmsgstr);
843 else if(privatesay) // private message, between 2 people only
845 sprint(source, sourcemsgstr);
846 sprint(privatesay, msgstr);
847 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
849 centerprint(privatesay, cmsgstr);
851 else if(teamsay > 0) // team message, only sent to team mates
853 sprint(source, sourcemsgstr);
854 dedicated_print(msgstr); // send to server console too
855 if(sourcecmsgstr != "")
856 centerprint(source, sourcecmsgstr);
857 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
860 sprint(head, msgstr);
862 centerprint(head, cmsgstr);
865 else if(teamsay < 0) // spectator message, only sent to spectators
867 sprint(source, sourcemsgstr);
868 dedicated_print(msgstr); // send to server console too
869 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
871 sprint(head, msgstr);
873 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
875 sprint(source, sourcemsgstr);
876 dedicated_print(msgstr); // send to server console too
877 FOR_EACH_REALCLIENT(head)
879 sprint(head, msgstr);
882 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
888 float GetVoiceMessageVoiceType(string type)
891 return VOICETYPE_TAUNT;
892 if(type == "teamshoot")
893 return VOICETYPE_LASTATTACKER;
894 return VOICETYPE_TEAMRADIO;
897 string allvoicesamples;
898 .string GetVoiceMessageSampleField(string type)
900 GetPlayerSoundSampleField_notFound = 0;
903 #define _VOICEMSG(m) case #m: return playersound_##m;
907 GetPlayerSoundSampleField_notFound = 1;
908 return playersound_taunt;
911 .string GetPlayerSoundSampleField(string type)
913 GetPlayerSoundSampleField_notFound = 0;
916 #define _VOICEMSG(m) case #m: return playersound_##m;
920 GetPlayerSoundSampleField_notFound = 1;
921 return playersound_taunt;
924 void PrecacheGlobalSound(string samplestring)
927 tokenize_console(samplestring);
931 for(i = 1; i <= n; ++i)
932 precache_sound(strcat(argv(0), ftos(i), ".wav"));
936 precache_sound(strcat(argv(0), ".wav"));
940 void PrecachePlayerSounds(string f)
944 fh = fopen(f, FILE_READ);
947 while((s = fgets(fh)))
949 if(tokenize_console(s) != 3)
951 dprint("Invalid sound info line: ", s, "\n");
954 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
958 if (!allvoicesamples)
960 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
963 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
967 void ClearPlayerSounds()
969 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
975 float LoadPlayerSounds(string f, float first)
980 fh = fopen(f, FILE_READ);
983 dprint("Player sound file not found: ", f, "\n");
986 while((s = fgets(fh)))
988 if(tokenize_console(s) != 3)
990 field = GetPlayerSoundSampleField(argv(0));
991 if(GetPlayerSoundSampleField_notFound)
992 field = GetVoiceMessageSampleField(argv(0));
993 if(GetPlayerSoundSampleField_notFound)
996 strunzone(self.field);
997 self.field = strzone(strcat(argv(1), " ", argv(2)));
1003 .float modelindex_for_playersound;
1004 .float skin_for_playersound;
1005 void UpdatePlayerSounds()
1007 if(self.modelindex == self.modelindex_for_playersound)
1008 if(self.skin == self.skin_for_playersound)
1010 self.modelindex_for_playersound = self.modelindex;
1011 self.skin_for_playersound = self.skin;
1012 ClearPlayerSounds();
1013 LoadPlayerSounds("sound/player/default.sounds", 1);
1014 if(!autocvar_g_debug_defaultsounds)
1015 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1016 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1019 void FakeGlobalSound(string sample, float chan, float voicetype)
1027 tokenize_console(sample);
1030 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1032 sample = strcat(argv(0), ".wav"); // randomization
1036 case VOICETYPE_LASTATTACKER_ONLY:
1038 case VOICETYPE_LASTATTACKER:
1042 if(IS_REAL_CLIENT(msg_entity))
1043 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1046 case VOICETYPE_TEAMRADIO:
1048 if(msg_entity.cvar_cl_voice_directional == 1)
1049 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1051 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1053 case VOICETYPE_AUTOTAUNT:
1058 if(autocvar_sv_gentle)
1060 tauntrand = random();
1062 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1064 if (msg_entity.cvar_cl_voice_directional >= 1)
1065 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1067 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1070 case VOICETYPE_TAUNT:
1072 if(self.deadflag == DEAD_NO)
1073 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1076 if(autocvar_sv_gentle)
1079 if (msg_entity.cvar_cl_voice_directional >= 1)
1080 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1082 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1084 case VOICETYPE_PLAYERSOUND:
1086 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1089 backtrace("Invalid voice type!");
1094 void GlobalSound(string sample, float chan, float voicetype)
1102 tokenize_console(sample);
1105 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1107 sample = strcat(argv(0), ".wav"); // randomization
1111 case VOICETYPE_LASTATTACKER_ONLY:
1114 msg_entity = self.pusher;
1115 if(IS_REAL_CLIENT(msg_entity))
1117 if(msg_entity.cvar_cl_voice_directional == 1)
1118 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1120 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1124 case VOICETYPE_LASTATTACKER:
1127 msg_entity = self.pusher;
1128 if(IS_REAL_CLIENT(msg_entity))
1130 if(msg_entity.cvar_cl_voice_directional == 1)
1131 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1133 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1136 if(IS_REAL_CLIENT(msg_entity))
1137 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1140 case VOICETYPE_TEAMRADIO:
1141 FOR_EACH_REALCLIENT(msg_entity)
1142 if(!teamplay || msg_entity.team == self.team)
1144 if(msg_entity.cvar_cl_voice_directional == 1)
1145 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1147 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1150 case VOICETYPE_AUTOTAUNT:
1155 if(autocvar_sv_gentle)
1157 tauntrand = random();
1158 FOR_EACH_REALCLIENT(msg_entity)
1159 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1161 if (msg_entity.cvar_cl_voice_directional >= 1)
1162 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1164 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1167 case VOICETYPE_TAUNT:
1169 if(self.deadflag == DEAD_NO)
1170 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1173 if(autocvar_sv_gentle)
1175 FOR_EACH_REALCLIENT(msg_entity)
1177 if (msg_entity.cvar_cl_voice_directional >= 1)
1178 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1180 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1183 case VOICETYPE_PLAYERSOUND:
1184 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1187 backtrace("Invalid voice type!");
1192 void PlayerSound(.string samplefield, float chan, float voicetype)
1194 GlobalSound(self.samplefield, chan, voicetype);
1197 void VoiceMessage(string type, string msg)
1200 float voicetype, ownteam;
1202 sample = GetVoiceMessageSampleField(type);
1204 if(GetPlayerSoundSampleField_notFound)
1206 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1210 voicetype = GetVoiceMessageVoiceType(type);
1211 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1213 flood = Say(self, ownteam, world, msg, 1);
1216 GlobalSound(self.sample, CH_VOICE, voicetype);
1218 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1221 void MoveToTeam(entity client, float team_colour, float type)
1223 float lockteams_backup;
1225 lockteams_backup = lockteams; // backup any team lock
1227 lockteams = 0; // disable locked teams
1229 TeamchangeFrags(client); // move the players frags
1230 SetPlayerColors(client, team_colour - 1); // set the players colour
1231 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1233 lockteams = lockteams_backup; // restore the team lock
1235 LogTeamchange(client.playerid, client.team, type);