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;
69 vector animparseline(float animfile)
76 line = fgets(animfile);
77 c = tokenize_sane(line);
80 animparseerror = TRUE;
83 anim_x = stof(argv(0));
84 anim_y = stof(argv(1));
85 anim_z = stof(argv(2));
86 // don't allow completely bogus values
87 if (anim_x < 0 || anim_y < 1 || anim_z < 0.001)
92 void player_setupanimsformodel()
94 local string animfilename;
96 // defaults for legacy .zym models without animinfo files
97 self.anim_die1 = '0 1 0.5'; // 2 seconds
98 self.anim_die2 = '1 1 0.5'; // 2 seconds
99 self.anim_draw = '2 1 3'; // TODO: analyze models and set framerate
100 self.anim_duck = '3 1 100'; // this anim seems bogus in most models, so make it play VERY briefly!
101 self.anim_duckwalk = '4 1 1';
102 self.anim_duckjump = '5 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
103 self.anim_duckidle = '6 1 1';
104 self.anim_idle = '7 1 1';
105 self.anim_jump = '8 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
106 self.anim_pain1 = '9 1 2'; // 0.5 seconds
107 self.anim_pain2 = '10 1 2'; // 0.5 seconds
108 self.anim_shoot = '11 1 5'; // TODO: analyze models and set framerate
109 self.anim_taunt = '12 1 1'; // FIXME? there is no code using this anim
110 self.anim_run = '13 1 1';
111 self.anim_runbackwards = '14 1 1';
112 self.anim_strafeleft = '15 1 1';
113 self.anim_straferight = '16 1 1';
114 self.anim_dead1 = '17 1 1';
115 self.anim_dead2 = '18 1 1';
116 self.anim_forwardright = '19 1 1';
117 self.anim_forwardleft = '20 1 1';
118 self.anim_backright = '21 1 1';
119 self.anim_backleft = '22 1 1';
120 animparseerror = FALSE;
121 animfilename = strcat(self.model, ".animinfo");
122 animfile = fopen(animfilename, FILE_READ);
125 self.anim_die1 = animparseline(animfile);
126 self.anim_die2 = animparseline(animfile);
127 self.anim_draw = animparseline(animfile);
128 self.anim_duck = animparseline(animfile);
129 self.anim_duckwalk = animparseline(animfile);
130 self.anim_duckjump = animparseline(animfile);
131 self.anim_duckidle = animparseline(animfile);
132 self.anim_idle = animparseline(animfile);
133 self.anim_jump = animparseline(animfile);
134 self.anim_pain1 = animparseline(animfile);
135 self.anim_pain2 = animparseline(animfile);
136 self.anim_shoot = animparseline(animfile);
137 self.anim_taunt = animparseline(animfile);
138 self.anim_run = animparseline(animfile);
139 self.anim_runbackwards = animparseline(animfile);
140 self.anim_strafeleft = animparseline(animfile);
141 self.anim_straferight = animparseline(animfile);
142 self.anim_forwardright = animparseline(animfile);
143 self.anim_forwardleft = animparseline(animfile);
144 self.anim_backright = animparseline(animfile);
145 self.anim_backleft = animparseline(animfile);
149 self.anim_dead1 = '0 1 1' + '1 0 0' * (self.anim_die1_x + self.anim_die1_y - 1);
150 self.anim_dead2 = '0 1 1' + '1 0 0' * (self.anim_die2_x + self.anim_die2_y - 1);
153 print("Parse error in ", animfilename, ", some player animations are broken\n");
156 dprint("File ", animfilename, " not found, assuming legacy .zym model animation timings\n");
157 // reset animstate now
158 player_setanim(self.anim_idle, TRUE, FALSE, TRUE);
161 void player_setanim(vector anim, float looping, float override, float restart)
164 if (anim_x == self.animstate_startframe)
165 if (anim_y == self.animstate_numframes)
166 if (anim_z == self.animstate_framerate)
168 self.animstate_startframe = anim_x;
169 self.animstate_numframes = anim_y;
170 self.animstate_framerate = anim_z;
171 self.animstate_starttime = time;
172 self.animstate_endtime = time + self.animstate_numframes / self.animstate_framerate;
173 self.animstate_looping = looping;
174 self.animstate_override = override;
175 self.frame = self.animstate_startframe;
178 void player_updateframe()
180 if (time >= self.animstate_endtime)
182 if (self.animstate_looping)
184 self.animstate_starttime = self.animstate_endtime;
185 self.animstate_endtime = self.animstate_endtime + self.animstate_numframes / self.animstate_framerate;
187 self.animstate_override = FALSE;
189 self.frame = self.animstate_startframe + bound(0, (time - self.animstate_starttime) * self.animstate_framerate, self.animstate_numframes - 1);
192 void player_anim (void)
194 player_updateframe();
196 if (self.deadflag != DEAD_NO)
198 if (time > self.animstate_endtime)
203 setsize(self, self.mins, self.maxs);
205 self.frame = self.dead_frame;
210 if (!self.animstate_override)
212 if (!(self.flags & FL_ONGROUND))
215 player_setanim(self.anim_duckjump, FALSE, TRUE, FALSE);
217 player_setanim(self.anim_jump, FALSE, TRUE, FALSE);
219 else if (self.crouch)
221 if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
222 player_setanim(self.anim_duckwalk, TRUE, FALSE, FALSE);
224 player_setanim(self.anim_duckidle, TRUE, FALSE, FALSE);
226 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
228 if (self.movement_x > 0 && self.movement_y == 0)
229 player_setanim(self.anim_run, TRUE, FALSE, FALSE);
230 else if (self.movement_x < 0 && self.movement_y == 0)
231 player_setanim(self.anim_runbackwards, TRUE, FALSE, FALSE);
232 else if (self.movement_x == 0 && self.movement_y > 0)
233 player_setanim(self.anim_straferight, TRUE, FALSE, FALSE);
234 else if (self.movement_x == 0 && self.movement_y < 0)
235 player_setanim(self.anim_strafeleft, TRUE, FALSE, FALSE);
236 else if (self.movement_x > 0 && self.movement_y > 0)
237 player_setanim(self.anim_forwardright, TRUE, FALSE, FALSE);
238 else if (self.movement_x > 0 && self.movement_y < 0)
239 player_setanim(self.anim_forwardleft, TRUE, FALSE, FALSE);
240 else if (self.movement_x < 0 && self.movement_y > 0)
241 player_setanim(self.anim_backright, TRUE, FALSE, FALSE);
242 else if (self.movement_x < 0 && self.movement_y < 0)
243 player_setanim(self.anim_backleft, TRUE, FALSE, FALSE);
245 player_setanim(self.anim_run, TRUE, FALSE, FALSE);
248 player_setanim(self.anim_idle, TRUE, FALSE, FALSE);
251 //End change by Supajoe on 11:44 PM EST 11/16/03 (Subject: Player animations)
253 void SpawnThrownWeapon (vector org, float w)
255 W_ThrowWeapon(randomvec() * 100 + '0 0 200', org - self.origin, FALSE);
258 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
260 local float take, save;
261 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
263 // damage resistance (ignore most of the damage from a bullet or similar)
264 damage = max(damage - 5, 1);
266 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
267 take = bound(0, damage - save, damage);
270 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
272 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
274 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
277 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
279 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
281 if (!(self.flags & FL_GODMODE))
283 self.armorvalue = self.armorvalue - save;
284 self.health = self.health - take;
285 // pause regeneration for 5 seconds
286 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
288 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
289 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
290 self.dmg_inflictor = inflictor;
292 if (self.health <= -75 && self.modelindex != 0)
294 // don't use any animations as a gib
297 // view just above the floor
298 self.view_ofs = '0 0 4';
300 Violence_GibSplash(self, 1, 1);
301 self.modelindex = 0; // restore later
302 self.solid = SOLID_NOT; // restore later
306 void ClientKill_Now_TeamChange();
308 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
310 local float take, save, waves, sdelay;
312 if(!DEATH_ISSPECIAL(deathtype))
314 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
316 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
319 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
327 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
328 take = bound(0, damage - save, damage);
337 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
339 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
341 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
344 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
346 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
348 if (time > self.spawnshieldtime)
350 if (!(self.flags & FL_GODMODE))
352 self.armorvalue = self.armorvalue - save;
353 self.health = self.health - take;
354 // pause regeneration for 5 seconds
355 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
357 if (time > self.pain_finished) //Don't switch pain sequences like crazy
359 self.pain_finished = time + 0.5; //Supajoe
363 player_setanim(self.anim_pain1, FALSE, TRUE, TRUE);
365 player_setanim(self.anim_pain2, FALSE, TRUE, TRUE);
367 if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
368 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
370 if(self.health > 75) // TODO make a "gentle" version?
371 PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
372 else if(self.health > 50)
373 PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
374 else if(self.health > 25)
375 PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
376 else if(self.health > 1)
377 PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
381 // throw off bot aim temporarily
383 shake = damage * 5 / (bound(0,skill,100) + 1);
384 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
385 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
389 self.max_armorvalue += (save + take);
391 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
392 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
393 self.dmg_inflictor = inflictor;
397 // don't reset pushltime for self damage as it may be an attempt to
398 // escape a lava pit or similar
399 //self.pushltime = 0;
401 else if(attacker.classname == "player" || attacker.classname == "gib")
403 self.pusher = attacker;
404 self.pushltime = time + cvar("g_maxpushtime");
406 else if(time < self.pushltime)
408 attacker = self.pusher;
409 self.pushltime = max(self.pushltime, time + 0.6);
416 float defer_ClientKill_Now_TeamChange;
417 defer_ClientKill_Now_TeamChange = FALSE;
419 if(sv_gentle < 1) // TODO make a "gentle" version?
421 if(deathtype == DEATH_DROWN)
422 PlayerSound(playersound_drown, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
424 PlayerSound(playersound_death, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
427 // get rid of kill indicator
428 if(self.killindicator)
430 remove(self.killindicator);
431 self.killindicator = world;
432 if(self.killindicator_teamchange)
433 defer_ClientKill_Now_TeamChange = TRUE;
435 if(self.classname == "body")
436 if(deathtype == DEATH_KILL)
438 // for the lemmings fans, a small harmless explosion
439 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
443 // become fully visible
445 // clear selected player display
446 ClearSelectedPlayer();
448 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
449 // print an obituary message
450 Obituary (attacker, inflictor, self, deathtype);
454 kh_Key_DropAll(self, TRUE);
455 else if(attacker.classname == "player" || attacker.classname == "gib")
456 kh_Key_DropAll(self, FALSE);
458 kh_Key_DropAll(self, TRUE);
461 if(attacker.classname != "player" && attacker.classname != "gib")
462 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
463 else if(attacker.team == self.team)
464 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
466 DropFlag(self.flagcarried, world, attacker);
468 Portal_ClearAllLater(self);
470 WaypointSprite_PlayerDead();
471 // make the corpse upright (not tilted)
475 self.avelocity = '0 0 0';
476 // view from the floor
477 self.view_ofs = '0 0 -8';
479 self.movetype = MOVETYPE_TOSS;
481 self.solid = SOLID_CORPSE;
482 // don't stick to the floor
483 self.flags = self.flags - (self.flags & FL_ONGROUND);
485 self.deadflag = DEAD_DYING;
486 // when to allow respawn
489 if(cvar("g_respawn_mapsettings"))
491 sdelay = cvar("g_respawn_mapsettings_delay");
492 waves = cvar("g_respawn_mapsettings_waves");
495 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
497 sdelay = cvar("g_respawn_delay");
499 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
501 waves = cvar("g_respawn_waves");
503 self.death_time = ceil((time + sdelay) / waves) * waves;
505 self.death_time = time + sdelay;
506 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
507 self.respawn_countdown = 10; // first number to count down from is 10
509 self.respawn_countdown = -1; // do not count down
512 player_setanim(self.anim_die1, FALSE, TRUE, TRUE);
513 self.dead_frame = self.anim_dead1_x;
517 player_setanim(self.anim_die2, FALSE, TRUE, TRUE);
518 self.dead_frame = self.anim_dead2_x;
520 // set damage function to corpse damage
521 self.event_damage = PlayerCorpseDamage;
522 // call the corpse damage function just in case it wants to gib
523 self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
524 // set up to fade out later
525 SUB_SetFade (self, time + 12 + random () * 4, 1);
528 if(self.weaponentity)
529 if(self.weaponentity.lasertarget)
530 remove(self.weaponentity.lasertarget);
532 if(clienttype(self) == CLIENTTYPE_REAL)
534 self.fixangle = TRUE;
536 //WriteByte (MSG_ONE, SVC_SETANGLE);
537 //WriteAngle (MSG_ONE, self.v_angle_x);
538 //WriteAngle (MSG_ONE, self.v_angle_y);
539 //WriteAngle (MSG_ONE, 80);
543 Spawnqueue_Unmark(self);
545 if(defer_ClientKill_Now_TeamChange)
546 ClientKill_Now_TeamChange();
550 PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
555 float UpdateSelectedPlayer_countvalue(float v)
557 return max(0, (v - 1.0) / 0.5);
560 // returns: -2 if no hit, otherwise cos of the angle
561 // uses the global v_angle
562 float UpdateSelectedPlayer_canSee(entity p, float mincosangle, float maxdist)
573 so = self.origin + self.view_ofs;
577 if(dist_point_line(d, '0 0 0', v_forward) > maxdist)
580 // now find the cos of the angle...
581 c = normalize(d) * v_forward;
586 traceline(so, p.origin, MOVE_NOMONSTERS, self);
587 if(trace_fraction < 1)
593 void ClearSelectedPlayer()
595 if(self.selected_player)
597 centerprint_expire(self, CENTERPRIO_POINT);
598 self.selected_player = world;
599 self.selected_player_display_needs_update = FALSE;
603 void UpdateSelectedPlayer()
606 float selected_score;
608 selected_score = 0.95; // 18 degrees
610 if(!cvar("sv_allow_shownames"))
613 if(clienttype(self) != CLIENTTYPE_REAL)
616 if(self.cvar_cl_shownames == 0)
619 if(self.cvar_cl_shownames == 1 && !teams_matter)
622 makevectors(self.v_angle); // sets v_forward
624 // 1. cursor trace is always right
625 if(self.cursor_trace_ent && self.cursor_trace_ent.classname == "player" && !self.cursor_trace_ent.deadflag)
627 selected = self.cursor_trace_ent;
631 // 2. if we don't have a cursor trace, find the player which is least
637 c = UpdateSelectedPlayer_canSee(p, selected_score, 100); // 100 = 2.5 meters
648 self.selected_player_display_timeout = time + self.cvar_scr_centertime;
652 if(time < self.selected_player_display_timeout)
653 if(UpdateSelectedPlayer_canSee(self.selected_player, 0.7, 200) >= -1) // 5 meters, 45 degrees
654 selected = self.selected_player;
659 if(selected == self.selected_player)
662 save = UpdateSelectedPlayer_countvalue(self.selected_player_count);
663 self.selected_player_count = self.selected_player_count + frametime;
664 if(save != UpdateSelectedPlayer_countvalue(self.selected_player_count))
666 string namestr, healthstr;
667 namestr = playername(selected);
670 healthstr = ftos(floor(selected.health));
671 if(self.team == selected.team)
673 namestr = strcat(namestr, " (", healthstr, "%)");
674 self.selected_player_display_needs_update = TRUE;
677 centerprint_atprio(self, CENTERPRIO_POINT, namestr);
682 ClearSelectedPlayer();
683 self.selected_player = selected;
684 self.selected_player_time = time;
685 self.selected_player_count = 0;
686 self.selected_player_display_needs_update = FALSE;
691 ClearSelectedPlayer();
694 if(self.selected_player)
695 self.last_selected_player = self.selected_player;
698 .float floodcontrol_chat;
699 .float floodcontrol_chatteam;
700 void Say(entity source, float teamsay, string msgin, float floodcontrol)
702 string msgstr, colorstr, cmsgstr, namestr;
706 if(Ban_MaybeEnforceBan(source))
710 if(substring(msgin, 0, 1) == " ")
711 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
713 msgin = formatmessage(msgin);
718 if(source.classname != "player")
719 colorstr = "^0"; // black for spectators
720 else if(teams_matter)
721 colorstr = Team_ColorCode(source.team);
725 if(intermission_running)
729 * using bprint solves this... me stupid
730 // how can we prevent the message from appearing in a listen server?
731 // for now, just give "say" back and only handle say_team
734 clientcommand(self, strcat("say ", msgin));
739 if(cvar("g_chat_teamcolors"))
740 namestr = playername(source);
742 namestr = source.netname;
745 msgstr = strzone(strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin, "\n"));
746 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", wordwrap(msgin, 50));
749 msgstr = strzone(strcat("\{1}", namestr, "^7: ", msgin, "\n"));
758 var .float flood_field;
762 flood_spl = cvar("g_chat_flood_spl_team");
763 flood_burst = cvar("g_chat_flood_burst_team");
764 flood_lmax = cvar("g_chat_flood_lmax_team");
765 flood_field = floodcontrol_chatteam;
769 flood_spl = cvar("g_chat_flood_spl");
770 flood_burst = cvar("g_chat_flood_burst");
771 flood_lmax = cvar("g_chat_flood_lmax");
772 flood_field = floodcontrol_chat;
774 flood_burst = max(0, flood_burst - 1);
775 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
776 lines = ceil(strlennocol(msgstr) / 75);
777 if(flood_lmax && lines > flood_lmax)
779 else if(time >= self.flood_field)
780 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
787 if(cvar("g_chat_flood_notify_flooder"))
790 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
792 sprint(self, "^3FLOOD CONTROL: ^7message too long\n");
795 sprint(self, msgstr);
796 print("NOTE: ", playername(self), "^7 is flooding.\n");
800 if(source.classname == "player")
802 FOR_EACH_REALPLAYER(head)
804 if(head.team == source.team)
806 sprint(head, msgstr);
807 centerprint(head, cmsgstr);
813 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
815 sprint(head, msgstr);
816 centerprint(head, cmsgstr);
822 // TODO invent a cvar name for allowing global chat by spectators during warmup anyway
823 if(cvar("g_chat_nospectators") && source.classname != "player") {
824 FOR_EACH_REALCLIENT(head) if(head.classname != "player") {
825 sprint(head, msgstr);
835 float GetVoiceMessageVoiceType(string type)
838 return VOICETYPE_TAUNT;
839 if(type == "teamshoot")
840 return VOICETYPE_LASTATTACKER;
841 return VOICETYPE_TEAMRADIO;
844 string allvoicesamples;
845 float GetPlayerSoundSampleField_notFound;
846 float GetPlayerSoundSampleField_fixed;
847 .string GetVoiceMessageSampleField(string type)
849 GetPlayerSoundSampleField_notFound = 0;
850 GetPlayerSoundSampleField_fixed = 0;
853 #define _VOICEMSG(m) case #m: return playersound_##m;
857 GetPlayerSoundSampleField_notFound = 1;
858 return playersound_taunt;
861 .string GetPlayerSoundSampleField(string type)
863 GetPlayerSoundSampleField_notFound = 0;
864 GetPlayerSoundSampleField_fixed = 0;
867 #define _VOICEMSG(m) case #m: return playersound_##m;
871 GetPlayerSoundSampleField_notFound = 1;
872 return playersound_taunt;
875 void PrecacheGlobalSound(string samplestring)
878 tokenize_sane(samplestring);
882 for(i = 1; i <= n; ++i)
883 precache_sound(strcat(argv(0), ftos(i), ".wav"));
887 precache_sound(strcat(argv(0), ".wav"));
891 void PrecachePlayerSounds(string f)
895 fh = fopen(f, FILE_READ);
898 while((s = fgets(fh)))
900 if(tokenize_sane(s) != 3)
902 dprint("Invalid sound info line: ", s, "\n");
905 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
909 if not(allvoicesamples)
911 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
914 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
918 void ClearPlayerSounds()
920 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
926 void LoadPlayerSounds(string f, float first)
931 fh = fopen(f, FILE_READ);
934 while((s = fgets(fh)))
936 if(tokenize_sane(s) != 3)
938 field = GetPlayerSoundSampleField(argv(0));
939 if(GetPlayerSoundSampleField_notFound)
940 field = GetVoiceMessageSampleField(argv(0));
941 if(GetPlayerSoundSampleField_notFound)
943 if(GetPlayerSoundSampleField_fixed)
947 strunzone(self.field);
948 self.field = strzone(strcat(argv(1), " ", argv(2)));
953 .float modelindex_for_playersound;
954 void UpdatePlayerSounds()
956 if(self.modelindex == self.modelindex_for_playersound)
958 self.modelindex_for_playersound = self.modelindex;
960 LoadPlayerSounds("sound/player/default.sounds", 1);
961 LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
964 void GlobalSound(string sample, float chan, float voicetype)
972 tokenize_sane(sample);
975 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
977 sample = strcat(argv(0), ".wav"); // randomization
981 case VOICETYPE_LASTATTACKER_ONLY:
983 if(self.pusher.team == self.team)
985 msg_entity = self.pusher;
986 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
988 if(msg_entity.cvar_cl_voice_directional == 1)
989 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
991 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
995 case VOICETYPE_LASTATTACKER:
997 if(self.pusher.team == self.team)
999 msg_entity = self.pusher;
1000 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1002 if(msg_entity.cvar_cl_voice_directional == 1)
1003 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1005 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1008 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1009 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1012 case VOICETYPE_TEAMRADIO:
1013 FOR_EACH_REALCLIENT(msg_entity)
1014 if(!teams_matter || msg_entity.team == self.team)
1016 if(msg_entity.cvar_cl_voice_directional == 1)
1017 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1019 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1022 case VOICETYPE_AUTOTAUNT:
1023 tauntrand = random();
1024 FOR_EACH_REALCLIENT(msg_entity)
1025 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1027 if (msg_entity.cvar_cl_voice_directional >= 1)
1028 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1030 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1033 case VOICETYPE_TAUNT:
1034 FOR_EACH_REALCLIENT(msg_entity)
1036 if (msg_entity.cvar_cl_voice_directional >= 1)
1037 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1039 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1041 case VOICETYPE_PLAYERSOUND:
1042 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1045 backtrace("Invalid voice type!");
1050 void PlayerSound(.string samplefield, float chan, float voicetype)
1053 sample = self.samplefield;
1054 GlobalSound(sample, chan, voicetype);
1057 .float floodcontrol_voice;
1058 .float floodcontrol_voiceteam;
1059 void VoiceMessage(string type, string msg)
1062 var float voicetype, ownteam;
1063 sample = GetVoiceMessageSampleField(type);
1065 if(GetPlayerSoundSampleField_notFound)
1067 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1071 voicetype = GetVoiceMessageVoiceType(type);
1072 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1076 var .float flood_field;
1081 flood_spv = cvar("g_voice_flood_spv_team");
1082 flood_field = floodcontrol_voiceteam;
1086 flood_spv = cvar("g_voice_flood_spv");
1087 flood_field = floodcontrol_voice;
1090 if(time >= self.flood_field)
1091 self.flood_field = max(time, self.flood_field) + flood_spv;
1096 Say(self, ownteam, msg, 0);
1099 PlayerSound(sample, CHAN_VOICE, voicetype);