2 // changes by LordHavoc on 03/29/04 and 03/30/04 at Vermeulen's request
3 // merged player_run and player_stand to player_anim
4 // added death animations to player_anim
5 // can now spawn thrown weapons from anywhere, not just from players
6 // thrown weapons now fade out after 20 seconds
7 // created PlayerGib function
8 // PlayerDie no longer uses hitloc or damage
9 // PlayerDie now supports dying animations as well as gibbing
10 // cleaned up PlayerDie a lot
16 void CopyBody(float keepvelocity)
19 if (self.effects & EF_NODRAW)
24 self.lip = oldself.lip;
25 self.colormap = oldself.colormap;
26 self.iscreature = oldself.iscreature;
27 self.angles = oldself.angles;
28 self.avelocity = oldself.avelocity;
29 self.classname = "body";
30 self.damageforcescale = oldself.damageforcescale;
31 self.effects = oldself.effects;
32 self.event_damage = oldself.event_damage;
33 self.animstate_startframe = oldself.animstate_startframe;
34 self.animstate_numframes = oldself.animstate_numframes;
35 self.animstate_framerate = oldself.animstate_framerate;
36 self.animstate_starttime = oldself.animstate_starttime;
37 self.animstate_endtime = oldself.animstate_endtime;
38 self.animstate_override = oldself.animstate_override;
39 self.animstate_looping = oldself.animstate_looping;
40 self.frame = oldself.frame;
41 self.dead_frame = oldself.dead_frame;
42 self.pain_finished = oldself.pain_finished;
43 self.health = oldself.health;
44 self.armorvalue = oldself.armorvalue;
45 self.armortype = oldself.armortype;
46 self.model = oldself.model;
47 self.modelindex = oldself.modelindex;
48 self.movetype = oldself.movetype;
49 self.nextthink = oldself.nextthink;
50 self.skin = oldself.skin;
51 self.solid = oldself.solid;
52 self.takedamage = oldself.takedamage;
53 self.think = oldself.think;
54 self.customizeentityforclient = oldself.customizeentityforclient;
55 if (keepvelocity == 1)
56 self.velocity = oldself.velocity;
57 self.oldvelocity = self.velocity;
58 self.fade_time = oldself.fade_time;
59 self.fade_rate = oldself.fade_rate;
60 //self.weapon = oldself.weapon;
61 setorigin(self, oldself.origin);
62 setsize(self, oldself.mins, oldself.maxs);
63 self.oldorigin = oldself.origin;
64 self.reset = SUB_Remove;
68 void player_setupanimsformodel()
70 local string animfilename;
72 // defaults for legacy .zym models without animinfo files
73 self.anim_die1 = '0 1 0.5'; // 2 seconds
74 self.anim_die2 = '1 1 0.5'; // 2 seconds
75 self.anim_draw = '2 1 3'; // TODO: analyze models and set framerate
76 self.anim_duck = '3 1 100'; // this anim seems bogus in most models, so make it play VERY briefly!
77 self.anim_duckwalk = '4 1 1';
78 self.anim_duckjump = '5 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
79 self.anim_duckidle = '6 1 1';
80 self.anim_idle = '7 1 1';
81 self.anim_jump = '8 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
82 self.anim_pain1 = '9 1 2'; // 0.5 seconds
83 self.anim_pain2 = '10 1 2'; // 0.5 seconds
84 self.anim_shoot = '11 1 5'; // TODO: analyze models and set framerate
85 self.anim_taunt = '12 1 1'; // FIXME? there is no code using this anim
86 self.anim_run = '13 1 1';
87 self.anim_runbackwards = '14 1 1';
88 self.anim_strafeleft = '15 1 1';
89 self.anim_straferight = '16 1 1';
90 self.anim_dead1 = '17 1 1';
91 self.anim_dead2 = '18 1 1';
92 self.anim_forwardright = '19 1 1';
93 self.anim_forwardleft = '20 1 1';
94 self.anim_backright = '21 1 1';
95 self.anim_backleft = '22 1 1';
96 animparseerror = FALSE;
97 animfilename = strcat(self.model, ".animinfo");
98 animfile = fopen(animfilename, FILE_READ);
101 self.anim_die1 = animparseline(animfile);
102 self.anim_die2 = animparseline(animfile);
103 self.anim_draw = animparseline(animfile);
104 self.anim_duck = animparseline(animfile);
105 self.anim_duckwalk = animparseline(animfile);
106 self.anim_duckjump = animparseline(animfile);
107 self.anim_duckidle = animparseline(animfile);
108 self.anim_idle = animparseline(animfile);
109 self.anim_jump = animparseline(animfile);
110 self.anim_pain1 = animparseline(animfile);
111 self.anim_pain2 = animparseline(animfile);
112 self.anim_shoot = animparseline(animfile);
113 self.anim_taunt = animparseline(animfile);
114 self.anim_run = animparseline(animfile);
115 self.anim_runbackwards = animparseline(animfile);
116 self.anim_strafeleft = animparseline(animfile);
117 self.anim_straferight = animparseline(animfile);
118 self.anim_forwardright = animparseline(animfile);
119 self.anim_forwardleft = animparseline(animfile);
120 self.anim_backright = animparseline(animfile);
121 self.anim_backleft = animparseline(animfile);
125 self.anim_dead1 = '0 1 1' + '1 0 0' * (self.anim_die1_x + self.anim_die1_y - 1);
126 self.anim_dead2 = '0 1 1' + '1 0 0' * (self.anim_die2_x + self.anim_die2_y - 1);
129 print("Parse error in ", animfilename, ", some player animations are broken\n");
132 dprint("File ", animfilename, " not found, assuming legacy .zym model animation timings\n");
133 // reset animstate now
134 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
137 void player_anim (void)
140 if (self.weaponentity)
141 updateanim(self.weaponentity);
143 if (self.deadflag != DEAD_NO)
145 if (time > self.animstate_endtime)
150 setsize(self, self.mins, self.maxs);
152 self.frame = self.dead_frame;
157 if (!self.animstate_override)
159 if (!(self.flags & FL_ONGROUND))
162 setanim(self, self.anim_duckjump, FALSE, TRUE, FALSE);
164 setanim(self, self.anim_jump, FALSE, TRUE, FALSE);
166 else if (self.crouch)
168 if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
169 setanim(self, self.anim_duckwalk, TRUE, FALSE, FALSE);
171 setanim(self, self.anim_duckidle, TRUE, FALSE, FALSE);
173 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
175 if (self.movement_x > 0 && self.movement_y == 0)
176 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
177 else if (self.movement_x < 0 && self.movement_y == 0)
178 setanim(self, self.anim_runbackwards, TRUE, FALSE, FALSE);
179 else if (self.movement_x == 0 && self.movement_y > 0)
180 setanim(self, self.anim_straferight, TRUE, FALSE, FALSE);
181 else if (self.movement_x == 0 && self.movement_y < 0)
182 setanim(self, self.anim_strafeleft, TRUE, FALSE, FALSE);
183 else if (self.movement_x > 0 && self.movement_y > 0)
184 setanim(self, self.anim_forwardright, TRUE, FALSE, FALSE);
185 else if (self.movement_x > 0 && self.movement_y < 0)
186 setanim(self, self.anim_forwardleft, TRUE, FALSE, FALSE);
187 else if (self.movement_x < 0 && self.movement_y > 0)
188 setanim(self, self.anim_backright, TRUE, FALSE, FALSE);
189 else if (self.movement_x < 0 && self.movement_y < 0)
190 setanim(self, self.anim_backleft, TRUE, FALSE, FALSE);
192 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
195 setanim(self, self.anim_idle, TRUE, FALSE, FALSE);
198 if (self.weaponentity)
199 if (!self.weaponentity.animstate_override)
200 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
203 void SpawnThrownWeapon (vector org, float w)
208 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
210 if(self.weapons & W_WeaponBit(j))
211 if(W_IsWeaponThrowable(j))
212 W_ThrowNewWeapon(self, j, FALSE, self.origin, randomvec() * 175 + '0 0 325');
216 W_ThrowWeapon(randomvec() * 125 + '0 0 200', org - self.origin, FALSE);
219 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
221 local float take, save;
222 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
224 // damage resistance (ignore most of the damage from a bullet or similar)
225 damage = max(damage - 5, 1);
227 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
228 take = bound(0, damage - save, damage);
231 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
233 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
235 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
238 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
240 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
242 if (!(self.flags & FL_GODMODE))
244 self.armorvalue = self.armorvalue - save;
245 self.health = self.health - take;
246 // pause regeneration for 5 seconds
247 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
249 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
250 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
251 self.dmg_inflictor = inflictor;
253 if (self.health <= -75 && self.modelindex != 0)
255 // don't use any animations as a gib
258 // view just above the floor
259 self.view_ofs = '0 0 4';
261 Violence_GibSplash(self, 1, 1);
262 self.modelindex = 0; // restore later
263 self.solid = SOLID_NOT; // restore later
267 void ClientKill_Now_TeamChange();
269 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
271 local float take, save, waves, sdelay;
273 if(!DEATH_ISSPECIAL(deathtype))
275 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
277 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
280 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
288 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
289 take = bound(0, damage - save, damage);
298 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
300 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
302 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
305 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
307 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
309 if (time > self.spawnshieldtime)
311 if (!(self.flags & FL_GODMODE))
313 self.armorvalue = self.armorvalue - save;
314 self.health = self.health - take;
315 // pause regeneration for 5 seconds
316 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
318 if (time > self.pain_finished) //Don't switch pain sequences like crazy
320 self.pain_finished = time + 0.5; //Supajoe
324 setanim(self, self.anim_pain1, FALSE, TRUE, TRUE);
326 setanim(self, self.anim_pain2, FALSE, TRUE, TRUE);
328 if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
329 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
331 if(self.health > 75) // TODO make a "gentle" version?
332 PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
333 else if(self.health > 50)
334 PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
335 else if(self.health > 25)
336 PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
337 else if(self.health > 1)
338 PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
342 // throw off bot aim temporarily
344 shake = damage * 5 / (bound(0,skill,100) + 1);
345 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
346 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
350 self.max_armorvalue += (save + take);
352 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
353 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
354 self.dmg_inflictor = inflictor;
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;
362 else if(attacker.classname == "player" || attacker.classname == "gib")
364 self.pusher = attacker;
365 self.pushltime = time + cvar("g_maxpushtime");
367 else if(time < self.pushltime)
369 attacker = self.pusher;
370 self.pushltime = max(self.pushltime, time + 0.6);
377 float defer_ClientKill_Now_TeamChange;
378 defer_ClientKill_Now_TeamChange = FALSE;
380 if(sv_gentle < 1) // TODO make a "gentle" version?
382 if(deathtype == DEATH_DROWN)
383 PlayerSound(playersound_drown, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
385 PlayerSound(playersound_death, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
388 // get rid of kill indicator
389 if(self.killindicator)
391 remove(self.killindicator);
392 self.killindicator = world;
393 if(self.killindicator_teamchange)
394 defer_ClientKill_Now_TeamChange = TRUE;
396 if(self.classname == "body")
397 if(deathtype == DEATH_KILL)
399 // for the lemmings fans, a small harmless explosion
400 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
404 // become fully visible
406 // clear selected player display
407 ClearSelectedPlayer();
409 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
410 // print an obituary message
411 Obituary (attacker, inflictor, self, deathtype);
415 kh_Key_DropAll(self, TRUE);
416 else if(attacker.classname == "player" || attacker.classname == "gib")
417 kh_Key_DropAll(self, FALSE);
419 kh_Key_DropAll(self, TRUE);
422 if(attacker.classname != "player" && attacker.classname != "gib")
423 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
424 else if(attacker.team == self.team)
425 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
427 DropFlag(self.flagcarried, world, attacker);
429 Portal_ClearAllLater(self);
431 WaypointSprite_PlayerDead();
432 // make the corpse upright (not tilted)
436 self.avelocity = '0 0 0';
437 // view from the floor
438 self.view_ofs = '0 0 -8';
440 self.movetype = MOVETYPE_TOSS;
442 self.solid = SOLID_CORPSE;
443 // don't stick to the floor
444 self.flags &~= FL_ONGROUND;
446 self.deadflag = DEAD_DYING;
447 // when to allow respawn
450 if(cvar("g_respawn_mapsettings"))
452 sdelay = cvar("g_respawn_mapsettings_delay");
453 waves = cvar("g_respawn_mapsettings_waves");
456 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
458 sdelay = cvar("g_respawn_delay");
460 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
462 waves = cvar("g_respawn_waves");
464 self.death_time = ceil((time + sdelay) / waves) * waves;
466 self.death_time = time + sdelay;
467 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
468 self.respawn_countdown = 10; // first number to count down from is 10
470 self.respawn_countdown = -1; // do not count down
473 setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
474 self.dead_frame = self.anim_dead1_x;
478 setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
479 self.dead_frame = self.anim_dead2_x;
481 // set damage function to corpse damage
482 self.event_damage = PlayerCorpseDamage;
483 // call the corpse damage function just in case it wants to gib
484 self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
485 // set up to fade out later
486 SUB_SetFade (self, time + 12 + random () * 4, 1);
489 if(self.weaponentity)
490 if(self.weaponentity.lasertarget)
491 remove(self.weaponentity.lasertarget);
493 if(clienttype(self) == CLIENTTYPE_REAL)
495 self.fixangle = TRUE;
497 //WriteByte (MSG_ONE, SVC_SETANGLE);
498 //WriteAngle (MSG_ONE, self.v_angle_x);
499 //WriteAngle (MSG_ONE, self.v_angle_y);
500 //WriteAngle (MSG_ONE, 80);
504 Spawnqueue_Unmark(self);
506 if(defer_ClientKill_Now_TeamChange)
507 ClientKill_Now_TeamChange();
511 PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
516 float UpdateSelectedPlayer_countvalue(float v)
518 return max(0, (v - 1.0) / 0.5);
521 // returns: -2 if no hit, otherwise cos of the angle
522 // uses the global v_angle
523 float UpdateSelectedPlayer_canSee(entity p, float mincosangle, float maxdist)
534 so = self.origin + self.view_ofs;
538 if(dist_point_line(d, '0 0 0', v_forward) > maxdist)
541 // now find the cos of the angle...
542 c = normalize(d) * v_forward;
547 // not visible in any way? forget it
551 traceline(so, p.origin, MOVE_NOMONSTERS, self);
552 if(trace_fraction < 1)
558 void ClearSelectedPlayer()
560 if(self.selected_player)
562 centerprint_expire(self, CENTERPRIO_POINT);
563 self.selected_player = world;
564 self.selected_player_display_needs_update = FALSE;
568 void UpdateSelectedPlayer()
571 float selected_score;
573 selected_score = 0.95; // 18 degrees
575 if(!cvar("sv_allow_shownames"))
578 if(clienttype(self) != CLIENTTYPE_REAL)
581 if(self.cvar_cl_shownames == 0)
584 if(self.cvar_cl_shownames == 1 && !teams_matter)
587 makevectors(self.v_angle); // sets v_forward
589 // 1. cursor trace is always right
590 if(self.cursor_trace_ent && self.cursor_trace_ent.classname == "player" && !self.cursor_trace_ent.deadflag)
592 selected = self.cursor_trace_ent;
596 // 2. if we don't have a cursor trace, find the player which is least
602 c = UpdateSelectedPlayer_canSee(p, selected_score, 100); // 100 = 2.5 meters
613 self.selected_player_display_timeout = time + self.cvar_scr_centertime;
617 if(time < self.selected_player_display_timeout)
618 if(UpdateSelectedPlayer_canSee(self.selected_player, 0.7, 200) >= -1) // 5 meters, 45 degrees
619 selected = self.selected_player;
624 if(selected == self.selected_player)
627 save = UpdateSelectedPlayer_countvalue(self.selected_player_count);
628 self.selected_player_count = self.selected_player_count + frametime;
629 if(save != UpdateSelectedPlayer_countvalue(self.selected_player_count))
631 string namestr, healthstr;
632 namestr = playername(selected);
635 healthstr = ftos(floor(selected.health));
636 if(self.team == selected.team)
638 namestr = strcat(namestr, " (", healthstr, "%)");
639 self.selected_player_display_needs_update = TRUE;
642 centerprint_atprio(self, CENTERPRIO_POINT, namestr);
647 ClearSelectedPlayer();
648 self.selected_player = selected;
649 self.selected_player_time = time;
650 self.selected_player_count = 0;
651 self.selected_player_display_needs_update = FALSE;
656 ClearSelectedPlayer();
659 if(self.selected_player)
660 self.last_selected_player = self.selected_player;
663 .float floodcontrol_chat;
664 .float floodcontrol_chatteam;
665 void Say(entity source, float teamsay, string msgin, float floodcontrol)
667 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr;
671 if(Ban_MaybeEnforceBan(source))
675 if(substring(msgin, 0, 1) == " ")
676 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
678 msgin = formatmessage(msgin);
683 if(source.classname != "player")
684 colorstr = "^0"; // black for spectators
685 else if(teams_matter)
686 colorstr = Team_ColorCode(source.team);
690 if(intermission_running)
694 * using bprint solves this... me stupid
695 // how can we prevent the message from appearing in a listen server?
696 // for now, just give "say" back and only handle say_team
699 clientcommand(self, strcat("say ", msgin));
704 if(cvar("g_chat_teamcolors"))
705 namestr = playername(source);
707 namestr = source.netname;
710 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
711 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
715 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
719 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
721 fullcmsgstr = cmsgstr;
730 var .float flood_field;
734 flood_spl = cvar("g_chat_flood_spl_team");
735 flood_burst = cvar("g_chat_flood_burst_team");
736 flood_lmax = cvar("g_chat_flood_lmax_team");
737 flood_field = floodcontrol_chatteam;
741 flood_spl = cvar("g_chat_flood_spl");
742 flood_burst = cvar("g_chat_flood_burst");
743 flood_lmax = cvar("g_chat_flood_lmax");
744 flood_field = floodcontrol_chat;
746 flood_burst = max(0, flood_burst - 1);
747 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
749 // do flood control for the default line size
750 getWrappedLine_remaining = msgstr;
753 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
755 msgstr = strcat(msgstr, " ", getWrappedLine(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
758 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
760 if(getWrappedLine_remaining != "")
763 if(time >= self.flood_field)
764 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
771 if(cvar("g_chat_flood_notify_flooder"))
773 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
778 sourcemsgstr = fullmsgstr;
779 sourcecmsgstr = fullcmsgstr;
785 sourcemsgstr = msgstr;
786 sourcecmsgstr = cmsgstr;
789 if(source.classname != "player")
791 if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
792 teamsay = -1; // spectators
796 print("NOTE: ", playername(self), "^7 is flooding.\n");
800 if(cvar("g_chat_flood_notify_flooder"))
801 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
803 sprint(self, fullmsgstr);
807 sprint(source, sourcemsgstr);
808 if(sourcecmsgstr != "")
809 centerprint(source, sourcecmsgstr);
810 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
813 sprint(head, msgstr);
815 centerprint(head, cmsgstr);
820 sprint(source, sourcemsgstr);
821 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
823 sprint(head, msgstr);
825 else if(sourcemsgstr != msgstr)
827 sprint(source, sourcemsgstr);
828 FOR_EACH_REALCLIENT(head)
830 sprint(head, msgstr);
836 float GetVoiceMessageVoiceType(string type)
839 return VOICETYPE_TAUNT;
840 if(type == "teamshoot")
841 return VOICETYPE_LASTATTACKER;
842 return VOICETYPE_TEAMRADIO;
845 string allvoicesamples;
846 float GetPlayerSoundSampleField_notFound;
847 float GetPlayerSoundSampleField_fixed;
848 .string GetVoiceMessageSampleField(string type)
850 GetPlayerSoundSampleField_notFound = 0;
851 GetPlayerSoundSampleField_fixed = 0;
854 #define _VOICEMSG(m) case #m: return playersound_##m;
858 GetPlayerSoundSampleField_notFound = 1;
859 return playersound_taunt;
862 .string GetPlayerSoundSampleField(string type)
864 GetPlayerSoundSampleField_notFound = 0;
865 GetPlayerSoundSampleField_fixed = 0;
868 #define _VOICEMSG(m) case #m: return playersound_##m;
872 GetPlayerSoundSampleField_notFound = 1;
873 return playersound_taunt;
876 void PrecacheGlobalSound(string samplestring)
879 tokenize_sane(samplestring);
883 for(i = 1; i <= n; ++i)
884 precache_sound(strcat(argv(0), ftos(i), ".wav"));
888 precache_sound(strcat(argv(0), ".wav"));
892 void PrecachePlayerSounds(string f)
896 fh = fopen(f, FILE_READ);
899 while((s = fgets(fh)))
901 if(tokenize_sane(s) != 3)
903 dprint("Invalid sound info line: ", s, "\n");
906 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
910 if not(allvoicesamples)
912 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
915 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
919 void ClearPlayerSounds()
921 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
927 void LoadPlayerSounds(string f, float first)
932 fh = fopen(f, FILE_READ);
935 while((s = fgets(fh)))
937 if(tokenize_sane(s) != 3)
939 field = GetPlayerSoundSampleField(argv(0));
940 if(GetPlayerSoundSampleField_notFound)
941 field = GetVoiceMessageSampleField(argv(0));
942 if(GetPlayerSoundSampleField_notFound)
944 if(GetPlayerSoundSampleField_fixed)
948 strunzone(self.field);
949 self.field = strzone(strcat(argv(1), " ", argv(2)));
954 .float modelindex_for_playersound;
955 void UpdatePlayerSounds()
957 if(self.modelindex == self.modelindex_for_playersound)
959 self.modelindex_for_playersound = self.modelindex;
961 LoadPlayerSounds("sound/player/default.sounds", 1);
962 LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
965 void GlobalSound(string sample, float chan, float voicetype)
973 tokenize_sane(sample);
976 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
978 sample = strcat(argv(0), ".wav"); // randomization
982 case VOICETYPE_LASTATTACKER_ONLY:
984 if(self.pusher.team == self.team)
986 msg_entity = self.pusher;
987 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
989 if(msg_entity.cvar_cl_voice_directional == 1)
990 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
992 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
996 case VOICETYPE_LASTATTACKER:
998 if(self.pusher.team == self.team)
1000 msg_entity = self.pusher;
1001 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1003 if(msg_entity.cvar_cl_voice_directional == 1)
1004 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1006 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1009 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1010 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1013 case VOICETYPE_TEAMRADIO:
1014 FOR_EACH_REALCLIENT(msg_entity)
1015 if(!teams_matter || msg_entity.team == self.team)
1017 if(msg_entity.cvar_cl_voice_directional == 1)
1018 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1020 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1023 case VOICETYPE_AUTOTAUNT:
1024 tauntrand = random();
1025 FOR_EACH_REALCLIENT(msg_entity)
1026 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1028 if (msg_entity.cvar_cl_voice_directional >= 1)
1029 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1031 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1034 case VOICETYPE_TAUNT:
1035 FOR_EACH_REALCLIENT(msg_entity)
1037 if (msg_entity.cvar_cl_voice_directional >= 1)
1038 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1040 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1042 case VOICETYPE_PLAYERSOUND:
1043 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1046 backtrace("Invalid voice type!");
1051 void PlayerSound(.string samplefield, float chan, float voicetype)
1054 sample = self.samplefield;
1055 GlobalSound(sample, chan, voicetype);
1058 .float floodcontrol_voice;
1059 .float floodcontrol_voiceteam;
1060 void VoiceMessage(string type, string msg)
1063 var float voicetype, ownteam;
1064 sample = GetVoiceMessageSampleField(type);
1066 if(GetPlayerSoundSampleField_notFound)
1068 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1072 voicetype = GetVoiceMessageVoiceType(type);
1073 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1077 var .float flood_field;
1082 flood_spv = cvar("g_voice_flood_spv_team");
1083 flood_field = floodcontrol_voiceteam;
1087 flood_spv = cvar("g_voice_flood_spv");
1088 flood_field = floodcontrol_voice;
1091 if(time >= self.flood_field)
1092 self.flood_field = max(time, self.flood_field) + flood_spv;
1097 Say(self, ownteam, msg, 0);
1100 PlayerSound(sample, CHAN_VOICE, voicetype);