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));
122 // Decide on which death animation to use.
124 deadbits = ANIMSTATE_DEAD1;
126 deadbits = ANIMSTATE_DEAD2;
129 // Clear a previous death animation.
132 float animbits = deadbits;
134 animbits |= ANIMSTATE_FROZEN;
136 animbits |= ANIMSTATE_DUCK;
137 animdecide_setstate(self, animbits, FALSE);
138 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
140 if (self.weaponentity)
142 updateanim(self.weaponentity);
143 if (!self.weaponentity.animstate_override)
144 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
148 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
152 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
154 // damage resistance (ignore most of the damage from a bullet or similar)
155 damage = max(damage - 5, 1);
157 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
161 if(sound_allowed(MSG_BROADCAST, attacker))
164 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
166 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
168 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
172 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
174 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
176 if (!(self.flags & FL_GODMODE))
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;
203 // If 0, default is used.
205 // Otherwise, g_str (default value) is used.
206 // For consistency, negative values there are mapped to zero too.
207 #define GAMETYPE_DEFAULTED_SETTING(str) \
208 ((gametype_setting_tmp = cvar(strcat("g_", GetGametype(), "_" #str))), \
209 (gametype_setting_tmp < 0) ? 0 : \
210 (gametype_setting_tmp == 0) ? max(0, autocvar_g_##str) : \
211 gametype_setting_tmp)
214 void calculate_player_respawn_time()
216 float gametype_setting_tmp;
217 float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
218 float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
219 float sdelay_large = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large);
220 float sdelay_small_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small_count);
221 float sdelay_large_count = GAMETYPE_DEFAULTED_SETTING(respawn_delay_large_count);
222 float waves = GAMETYPE_DEFAULTED_SETTING(respawn_waves);
224 float pcount = 1; // Include myself whether or not team is already set right and I'm a "player".
230 if (pl.team == self.team)
232 if (sdelay_small_count == 0)
233 sdelay_small_count = 1;
234 if (sdelay_large_count == 0)
235 sdelay_large_count = 1;
242 if (sdelay_small_count == 0)
246 // Players play independently. No point in requiring enemies.
247 sdelay_small_count = 1;
251 // Players play AGAINST each other. Enemies required.
252 sdelay_small_count = 2;
255 if (sdelay_large_count == 0)
259 // Players play independently. No point in requiring enemies.
260 sdelay_large_count = 1;
264 // Players play AGAINST each other. Enemies required.
265 sdelay_large_count = 2;
272 if (pcount <= sdelay_small_count)
273 sdelay = sdelay_small;
274 else if (pcount >= sdelay_large_count)
275 sdelay = sdelay_large;
276 else // NOTE: this case implies sdelay_large_count > sdelay_small_count.
277 sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
280 self.respawn_time = ceil((time + sdelay) / waves) * waves;
282 self.respawn_time = time + sdelay;
284 if(sdelay < sdelay_max)
285 self.respawn_time_max = time + sdelay_max;
287 self.respawn_time_max = self.respawn_time;
289 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
290 self.respawn_countdown = 10; // first number to count down from is 10
292 self.respawn_countdown = -1; // do not count down
294 if(autocvar_g_forced_respawn)
295 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
298 void ClientKill_Now_TeamChange();
300 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
302 float take, save, dh, da, j;
304 float valid_damage_for_weaponstats;
307 dh = max(self.health, 0);
308 da = max(self.armorvalue, 0);
310 if(!DEATH_ISSPECIAL(deathtype))
312 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
314 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
317 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
319 // tuba causes blood to come out of the ears
324 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
326 makevectors(self.angles);
327 ear1 += v_right * -10;
328 ear2 += v_right * +10;
329 d = inflictor.origin - self.origin;
331 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
333 f = 0; // Assum ecenter.
334 force = v_right * vlen(force);
335 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
336 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
345 // force is already good
349 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
352 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
358 // don't reset pushltime for self damage as it may be an attempt to
359 // escape a lava pit or similar
360 //self.pushltime = 0;
363 else if(IS_PLAYER(attacker))
365 self.pusher = attacker;
366 self.pushltime = time + autocvar_g_maxpushtime;
367 self.istypefrag = self.BUTTON_CHAT;
369 else if(time < self.pushltime)
371 attacker = self.pusher;
372 self.pushltime = max(self.pushltime, time + 0.6);
380 frag_inflictor = inflictor;
381 frag_attacker = attacker;
383 frag_damage = damage;
386 damage_force = force;
387 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
388 take = bound(0, damage_take, self.health);
389 save = bound(0, damage_save, self.armorvalue);
390 excess = max(0, damage - take - save);
392 if(sound_allowed(MSG_BROADCAST, attacker))
395 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
397 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
399 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
403 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
405 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
407 if (time >= self.spawnshieldtime)
409 if (!(self.flags & FL_GODMODE))
411 self.armorvalue = self.armorvalue - save;
412 self.health = self.health - take;
413 // pause regeneration for 5 seconds
415 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
417 if (time > self.pain_finished) //Don't switch pain sequences like crazy
419 self.pain_finished = time + 0.5; //Supajoe
421 if(autocvar_sv_gentle < 1) {
422 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
424 if (!self.animstate_override)
427 animdecide_setaction(self, ANIMACTION_PAIN1, TRUE);
429 animdecide_setaction(self, ANIMACTION_PAIN2, TRUE);
433 if(sound_allowed(MSG_BROADCAST, attacker))
434 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
436 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
438 if(deathtype == DEATH_FALL)
439 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
440 else if(self.health > 75) // TODO make a "gentle" version?
441 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
442 else if(self.health > 50)
443 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
444 else if(self.health > 25)
445 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
447 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
452 // throw off bot aim temporarily
454 if(IS_BOT_CLIENT(self) && self.health >= 1)
456 shake = damage * 5 / (bound(0,skill,100) + 1);
457 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
458 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
459 self.v_angle_x = bound(-90, self.v_angle_x, 90);
463 self.max_armorvalue += (save + take);
465 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
466 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
467 self.dmg_inflictor = inflictor;
469 float abot, vbot, awep;
470 abot = (IS_BOT_CLIENT(attacker));
471 vbot = (IS_BOT_CLIENT(self));
473 valid_damage_for_weaponstats = 0;
476 if(vbot || IS_REAL_CLIENT(self))
477 if(abot || IS_REAL_CLIENT(attacker))
478 if(attacker && self != attacker)
479 if(DIFF_TEAM(self, attacker))
481 if(DEATH_ISSPECIAL(deathtype))
482 awep = attacker.weapon;
484 awep = DEATH_WEAPONOF(deathtype);
485 valid_damage_for_weaponstats = 1;
488 if(valid_damage_for_weaponstats)
490 dh = dh - max(self.health, 0);
491 da = da - max(self.armorvalue, 0);
492 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
497 float defer_ClientKill_Now_TeamChange;
498 defer_ClientKill_Now_TeamChange = FALSE;
502 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
506 if(valid_damage_for_weaponstats)
507 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
509 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
510 if(sound_allowed(MSG_BROADCAST, attacker))
512 if(deathtype == DEATH_DROWN)
513 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
515 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
518 // get rid of kill indicator
519 if(self.killindicator)
521 remove(self.killindicator);
522 self.killindicator = world;
523 if(self.killindicator_teamchange)
524 defer_ClientKill_Now_TeamChange = TRUE;
526 if(self.classname == "body")
527 if(deathtype == DEATH_KILL)
529 // for the lemmings fans, a small harmless explosion
530 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
534 // print an obituary message
535 Obituary (attacker, inflictor, self, deathtype);
537 // increment frag counter for used weapon type
539 w = DEATH_WEAPONOF(deathtype);
541 if(accuracy_isgooddamage(attacker, self))
542 attacker.accuracy.(accuracy_frags[w-1]) += 1;
544 frag_attacker = attacker;
545 frag_inflictor = inflictor;
547 frag_deathtype = deathtype;
548 MUTATOR_CALLHOOK(PlayerDies);
550 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
552 RemoveGrapplingHook(self);
554 Portal_ClearAllLater(self);
556 self.fixangle = TRUE;
558 if(defer_ClientKill_Now_TeamChange)
559 ClientKill_Now_TeamChange(); // can turn player into spectator
561 // player could have been miraculously resuscitated ;)
562 // e.g. players in freezetag get frozen, they don't really die
563 if(self.health >= 1 || !IS_PLAYER(self))
566 // when we get here, player actually dies
568 Unfreeze(self); // remove any icy remains
569 self.health = 0; // Unfreeze resets health, so we need to set it back
572 WaypointSprite_PlayerDead();
574 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
576 // become fully visible
577 self.alpha = default_player_alpha;
578 // make the corpse upright (not tilted)
582 self.avelocity = '0 0 0';
583 // view from the floor
584 self.view_ofs = '0 0 -8';
586 self.movetype = MOVETYPE_TOSS;
588 self.solid = SOLID_CORPSE;
589 self.ballistics_density = autocvar_g_ballistics_density_corpse;
590 // don't stick to the floor
591 self.flags &= ~FL_ONGROUND;
593 self.deadflag = DEAD_DYING;
594 // when to allow respawn
595 calculate_player_respawn_time();
597 self.death_time = time;
599 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, TRUE);
601 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, TRUE);
605 setsize(self, self.mins, self.maxs);
607 // set damage function to corpse damage
608 self.event_damage = PlayerCorpseDamage;
609 // call the corpse damage function just in case it wants to gib
610 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
611 // set up to fade out later
612 SUB_SetFade (self, time + 6 + random (), 1);
614 if(autocvar_sv_gentle > 0 || autocvar_ekg) {
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 muted; // to be used by prvm_edictset server playernumber muted 1
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 allvoicesamples;
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 .float modelindex_for_playersound;
1017 .float skin_for_playersound;
1018 void UpdatePlayerSounds()
1020 if(self.modelindex == self.modelindex_for_playersound)
1021 if(self.skin == self.skin_for_playersound)
1023 self.modelindex_for_playersound = self.modelindex;
1024 self.skin_for_playersound = self.skin;
1025 ClearPlayerSounds();
1026 LoadPlayerSounds("sound/player/default.sounds", 1);
1027 if(!autocvar_g_debug_defaultsounds)
1028 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1029 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1032 void FakeGlobalSound(string sample, float chan, float voicetype)
1040 tokenize_console(sample);
1043 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1045 sample = strcat(argv(0), ".wav"); // randomization
1049 case VOICETYPE_LASTATTACKER_ONLY:
1051 case VOICETYPE_LASTATTACKER:
1055 if(IS_REAL_CLIENT(msg_entity))
1056 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1059 case VOICETYPE_TEAMRADIO:
1061 if(msg_entity.cvar_cl_voice_directional == 1)
1062 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1064 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1066 case VOICETYPE_AUTOTAUNT:
1071 if(autocvar_sv_gentle)
1073 tauntrand = random();
1075 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1077 if (msg_entity.cvar_cl_voice_directional >= 1)
1078 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1080 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1083 case VOICETYPE_TAUNT:
1085 if(self.deadflag == DEAD_NO)
1086 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1089 if(autocvar_sv_gentle)
1092 if (msg_entity.cvar_cl_voice_directional >= 1)
1093 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1095 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1097 case VOICETYPE_PLAYERSOUND:
1099 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1102 backtrace("Invalid voice type!");
1107 void GlobalSound(string sample, float chan, float voicetype)
1115 tokenize_console(sample);
1118 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1120 sample = strcat(argv(0), ".wav"); // randomization
1124 case VOICETYPE_LASTATTACKER_ONLY:
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);
1137 case VOICETYPE_LASTATTACKER:
1140 msg_entity = self.pusher;
1141 if(IS_REAL_CLIENT(msg_entity))
1143 if(msg_entity.cvar_cl_voice_directional == 1)
1144 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1146 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1149 if(IS_REAL_CLIENT(msg_entity))
1150 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1153 case VOICETYPE_TEAMRADIO:
1154 FOR_EACH_REALCLIENT(msg_entity)
1155 if(!teamplay || msg_entity.team == self.team)
1157 if(msg_entity.cvar_cl_voice_directional == 1)
1158 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1160 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1163 case VOICETYPE_AUTOTAUNT:
1168 if(autocvar_sv_gentle)
1170 tauntrand = random();
1171 FOR_EACH_REALCLIENT(msg_entity)
1172 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1174 if (msg_entity.cvar_cl_voice_directional >= 1)
1175 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1177 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1180 case VOICETYPE_TAUNT:
1182 if(self.deadflag == DEAD_NO)
1183 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1186 if(autocvar_sv_gentle)
1188 FOR_EACH_REALCLIENT(msg_entity)
1190 if (msg_entity.cvar_cl_voice_directional >= 1)
1191 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1193 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1196 case VOICETYPE_PLAYERSOUND:
1197 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1200 backtrace("Invalid voice type!");
1205 void PlayerSound(.string samplefield, float chan, float voicetype)
1207 GlobalSound(self.samplefield, chan, voicetype);
1210 void VoiceMessage(string type, string msg)
1213 float voicetype, ownteam;
1215 sample = GetVoiceMessageSampleField(type);
1217 if(GetPlayerSoundSampleField_notFound)
1219 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1223 voicetype = GetVoiceMessageVoiceType(type);
1224 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1226 flood = Say(self, ownteam, world, msg, 1);
1229 GlobalSound(self.sample, CH_VOICE, voicetype);
1231 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1234 void MoveToTeam(entity client, float team_colour, float type)
1236 float lockteams_backup;
1238 lockteams_backup = lockteams; // backup any team lock
1240 lockteams = 0; // disable locked teams
1242 TeamchangeFrags(client); // move the players frags
1243 SetPlayerColors(client, team_colour - 1); // set the players colour
1244 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1246 lockteams = lockteams_backup; // restore the team lock
1248 LogTeamchange(client.playerid, client.team, type);