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.prevorigin = oldself.origin;
64 self.reset = SUB_Remove;
66 Drag_MoveDrag(oldself, self);
71 void player_setupanimsformodel()
73 local string animfilename;
75 // defaults for legacy .zym models without animinfo files
76 self.anim_die1 = '0 1 0.5'; // 2 seconds
77 self.anim_die2 = '1 1 0.5'; // 2 seconds
78 self.anim_draw = '2 1 3'; // TODO: analyze models and set framerate
79 self.anim_duck = '3 1 100'; // this anim seems bogus in most models, so make it play VERY briefly!
80 self.anim_duckwalk = '4 1 1';
81 self.anim_duckjump = '5 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
82 self.anim_duckidle = '6 1 1';
83 self.anim_idle = '7 1 1';
84 self.anim_jump = '8 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
85 self.anim_pain1 = '9 1 2'; // 0.5 seconds
86 self.anim_pain2 = '10 1 2'; // 0.5 seconds
87 self.anim_shoot = '11 1 5'; // TODO: analyze models and set framerate
88 self.anim_taunt = '12 1 1'; // FIXME? there is no code using this anim
89 self.anim_run = '13 1 1';
90 self.anim_runbackwards = '14 1 1';
91 self.anim_strafeleft = '15 1 1';
92 self.anim_straferight = '16 1 1';
93 self.anim_dead1 = '17 1 1';
94 self.anim_dead2 = '18 1 1';
95 self.anim_forwardright = '19 1 1';
96 self.anim_forwardleft = '20 1 1';
97 self.anim_backright = '21 1 1';
98 self.anim_backleft = '22 1 1';
99 animparseerror = FALSE;
100 animfilename = strcat(self.model, ".animinfo");
101 animfile = fopen(animfilename, FILE_READ);
104 self.anim_die1 = animparseline(animfile);
105 self.anim_die2 = animparseline(animfile);
106 self.anim_draw = animparseline(animfile);
107 self.anim_duck = animparseline(animfile);
108 self.anim_duckwalk = animparseline(animfile);
109 self.anim_duckjump = animparseline(animfile);
110 self.anim_duckidle = animparseline(animfile);
111 self.anim_idle = animparseline(animfile);
112 self.anim_jump = animparseline(animfile);
113 self.anim_pain1 = animparseline(animfile);
114 self.anim_pain2 = animparseline(animfile);
115 self.anim_shoot = animparseline(animfile);
116 self.anim_taunt = animparseline(animfile);
117 self.anim_run = animparseline(animfile);
118 self.anim_runbackwards = animparseline(animfile);
119 self.anim_strafeleft = animparseline(animfile);
120 self.anim_straferight = animparseline(animfile);
121 self.anim_forwardright = animparseline(animfile);
122 self.anim_forwardleft = animparseline(animfile);
123 self.anim_backright = animparseline(animfile);
124 self.anim_backleft = animparseline(animfile);
128 self.anim_dead1 = '0 1 1' + '1 0 0' * (self.anim_die1_x + self.anim_die1_y - 1);
129 self.anim_dead2 = '0 1 1' + '1 0 0' * (self.anim_die2_x + self.anim_die2_y - 1);
132 print("Parse error in ", animfilename, ", some player animations are broken\n");
135 dprint("File ", animfilename, " not found, assuming legacy .zym model animation timings\n");
136 // reset animstate now
137 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
140 void player_anim (void)
143 if (self.weaponentity)
144 updateanim(self.weaponentity);
146 if (self.deadflag != DEAD_NO)
148 if (time > self.animstate_endtime)
153 setsize(self, self.mins, self.maxs);
155 self.frame = self.dead_frame;
160 if (!self.animstate_override)
162 if (!(self.flags & FL_ONGROUND))
165 setanim(self, self.anim_duckjump, FALSE, TRUE, FALSE);
167 setanim(self, self.anim_jump, FALSE, TRUE, FALSE);
169 else if (self.crouch)
171 if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
172 setanim(self, self.anim_duckwalk, TRUE, FALSE, FALSE);
174 setanim(self, self.anim_duckidle, TRUE, FALSE, FALSE);
176 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
178 if (self.movement_x > 0 && self.movement_y == 0)
179 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
180 else if (self.movement_x < 0 && self.movement_y == 0)
181 setanim(self, self.anim_runbackwards, TRUE, FALSE, FALSE);
182 else if (self.movement_x == 0 && self.movement_y > 0)
183 setanim(self, self.anim_straferight, TRUE, FALSE, FALSE);
184 else if (self.movement_x == 0 && self.movement_y < 0)
185 setanim(self, self.anim_strafeleft, TRUE, FALSE, FALSE);
186 else if (self.movement_x > 0 && self.movement_y > 0)
187 setanim(self, self.anim_forwardright, TRUE, FALSE, FALSE);
188 else if (self.movement_x > 0 && self.movement_y < 0)
189 setanim(self, self.anim_forwardleft, TRUE, FALSE, FALSE);
190 else if (self.movement_x < 0 && self.movement_y > 0)
191 setanim(self, self.anim_backright, TRUE, FALSE, FALSE);
192 else if (self.movement_x < 0 && self.movement_y < 0)
193 setanim(self, self.anim_backleft, TRUE, FALSE, FALSE);
195 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
198 setanim(self, self.anim_idle, TRUE, FALSE, FALSE);
201 if (self.weaponentity)
202 if (!self.weaponentity.animstate_override)
203 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
206 void SpawnThrownWeapon (vector org, float w)
211 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
213 if(self.weapons & W_WeaponBit(j))
214 if(W_IsWeaponThrowable(j))
215 W_ThrowNewWeapon(self, j, FALSE, self.origin, randomvec() * 175 + '0 0 325');
219 W_ThrowWeapon(randomvec() * 125 + '0 0 200', org - self.origin, FALSE);
222 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
224 local float take, save;
225 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
227 // damage resistance (ignore most of the damage from a bullet or similar)
228 damage = max(damage - 5, 1);
230 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
231 take = bound(0, damage - save, damage);
234 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
236 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
238 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
241 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
243 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
245 if (!(self.flags & FL_GODMODE))
247 self.armorvalue = self.armorvalue - save;
248 self.health = self.health - take;
249 // pause regeneration for 5 seconds
250 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
252 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
253 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
254 self.dmg_inflictor = inflictor;
256 if (self.health <= -75 && self.modelindex != 0)
258 // don't use any animations as a gib
261 // view just above the floor
262 self.view_ofs = '0 0 4';
264 Violence_GibSplash(self, 1, 1);
265 self.modelindex = 0; // restore later
266 self.solid = SOLID_NOT; // restore later
270 void ClientKill_Now_TeamChange();
272 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
274 local float take, save, waves, sdelay;
276 if(!DEATH_ISSPECIAL(deathtype))
278 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
280 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
283 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force, 2, bound(0, damage, 200) / 16);
291 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
292 take = bound(0, damage - save, damage);
301 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
303 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
305 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
308 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.1, 3, 1);
310 Violence_GibSplash_At(hitloc, '0 0 0', '0 0 0', force * -0.2, 3, 1);
312 if (time > self.spawnshieldtime)
314 if (!(self.flags & FL_GODMODE))
316 self.armorvalue = self.armorvalue - save;
317 self.health = self.health - take;
318 // pause regeneration for 5 seconds
319 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
321 if (time > self.pain_finished) //Don't switch pain sequences like crazy
323 self.pain_finished = time + 0.5; //Supajoe
327 setanim(self, self.anim_pain1, FALSE, TRUE, TRUE);
329 setanim(self, self.anim_pain2, FALSE, TRUE, TRUE);
331 if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
332 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
334 if(self.health > 75) // TODO make a "gentle" version?
335 PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
336 else if(self.health > 50)
337 PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
338 else if(self.health > 25)
339 PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
340 else if(self.health > 1)
341 PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
345 // throw off bot aim temporarily
347 shake = damage * 5 / (bound(0,skill,100) + 1);
348 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
349 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
353 self.max_armorvalue += (save + take);
355 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
356 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
357 self.dmg_inflictor = inflictor;
361 // don't reset pushltime for self damage as it may be an attempt to
362 // escape a lava pit or similar
363 //self.pushltime = 0;
365 else if(attacker.classname == "player" || attacker.classname == "gib")
367 self.pusher = attacker;
368 self.pushltime = time + cvar("g_maxpushtime");
370 else if(time < self.pushltime)
372 attacker = self.pusher;
373 self.pushltime = max(self.pushltime, time + 0.6);
380 float defer_ClientKill_Now_TeamChange;
381 defer_ClientKill_Now_TeamChange = FALSE;
383 if(sv_gentle < 1) // TODO make a "gentle" version?
385 if(deathtype == DEATH_DROWN)
386 PlayerSound(playersound_drown, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
388 PlayerSound(playersound_death, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
391 // get rid of kill indicator
392 if(self.killindicator)
394 remove(self.killindicator);
395 self.killindicator = world;
396 if(self.killindicator_teamchange)
397 defer_ClientKill_Now_TeamChange = TRUE;
399 if(self.classname == "body")
400 if(deathtype == DEATH_KILL)
402 // for the lemmings fans, a small harmless explosion
403 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
407 // become fully visible
409 // clear selected player display
410 ClearSelectedPlayer();
412 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
413 // print an obituary message
414 Obituary (attacker, inflictor, self, deathtype);
418 kh_Key_DropAll(self, TRUE);
419 else if(attacker.classname == "player" || attacker.classname == "gib")
420 kh_Key_DropAll(self, FALSE);
422 kh_Key_DropAll(self, TRUE);
425 if(attacker.classname != "player" && attacker.classname != "gib")
426 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
427 else if(attacker.team == self.team)
428 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
430 DropFlag(self.flagcarried, world, attacker);
433 DropBall(self.ballcarried, self.origin, self.velocity);
434 Portal_ClearAllLater(self);
436 WaypointSprite_PlayerDead();
437 // make the corpse upright (not tilted)
441 self.avelocity = '0 0 0';
442 // view from the floor
443 self.view_ofs = '0 0 -8';
445 self.movetype = MOVETYPE_TOSS;
447 self.solid = SOLID_CORPSE;
448 // don't stick to the floor
449 self.flags &~= FL_ONGROUND;
451 self.deadflag = DEAD_DYING;
452 // when to allow respawn
455 if(cvar("g_respawn_mapsettings"))
457 sdelay = cvar("g_respawn_mapsettings_delay");
458 waves = cvar("g_respawn_mapsettings_waves");
461 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
463 sdelay = cvar("g_respawn_delay");
465 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
467 waves = cvar("g_respawn_waves");
469 self.death_time = ceil((time + sdelay) / waves) * waves;
471 self.death_time = time + sdelay;
472 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
473 self.respawn_countdown = 10; // first number to count down from is 10
475 self.respawn_countdown = -1; // do not count down
478 setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
479 self.dead_frame = self.anim_dead1_x;
483 setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
484 self.dead_frame = self.anim_dead2_x;
486 // set damage function to corpse damage
487 self.event_damage = PlayerCorpseDamage;
488 // call the corpse damage function just in case it wants to gib
489 self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
490 // set up to fade out later
491 SUB_SetFade (self, time + 12 + random () * 4, 1);
494 if(self.weaponentity)
495 if(self.weaponentity.lasertarget)
496 remove(self.weaponentity.lasertarget);
498 if(clienttype(self) == CLIENTTYPE_REAL)
500 self.fixangle = TRUE;
502 //WriteByte (MSG_ONE, SVC_SETANGLE);
503 //WriteAngle (MSG_ONE, self.v_angle_x);
504 //WriteAngle (MSG_ONE, self.v_angle_y);
505 //WriteAngle (MSG_ONE, 80);
509 Spawnqueue_Unmark(self);
511 if(defer_ClientKill_Now_TeamChange)
512 ClientKill_Now_TeamChange();
516 PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
521 float UpdateSelectedPlayer_countvalue(float v)
523 return max(0, (v - 1.0) / 0.5);
526 // returns: -2 if no hit, otherwise cos of the angle
527 // uses the global v_angle
528 float UpdateSelectedPlayer_canSee(entity p, float mincosangle, float maxdist)
539 so = self.origin + self.view_ofs;
543 if(dist_point_line(d, '0 0 0', v_forward) > maxdist)
546 // now find the cos of the angle...
547 c = normalize(d) * v_forward;
552 // not visible in any way? forget it
556 traceline(so, p.origin, MOVE_NOMONSTERS, self);
557 if(trace_fraction < 1)
563 void ClearSelectedPlayer()
565 if(self.selected_player)
567 centerprint_expire(self, CENTERPRIO_POINT);
568 self.selected_player = world;
569 self.selected_player_display_needs_update = FALSE;
573 void UpdateSelectedPlayer()
576 float selected_score;
578 selected_score = 0.95; // 18 degrees
580 if(!cvar("sv_allow_shownames"))
583 if(clienttype(self) != CLIENTTYPE_REAL)
586 if(self.cvar_cl_shownames == 0)
589 if(self.cvar_cl_shownames == 1 && !teams_matter)
592 makevectors(self.v_angle); // sets v_forward
594 // 1. cursor trace is always right
595 if(self.cursor_trace_ent && self.cursor_trace_ent.classname == "player" && !self.cursor_trace_ent.deadflag)
597 selected = self.cursor_trace_ent;
601 // 2. if we don't have a cursor trace, find the player which is least
607 c = UpdateSelectedPlayer_canSee(p, selected_score, 100); // 100 = 2.5 meters
618 self.selected_player_display_timeout = time + self.cvar_scr_centertime;
622 if(time < self.selected_player_display_timeout)
623 if(UpdateSelectedPlayer_canSee(self.selected_player, 0.7, 200) >= -1) // 5 meters, 45 degrees
624 selected = self.selected_player;
629 if(selected == self.selected_player)
632 save = UpdateSelectedPlayer_countvalue(self.selected_player_count);
633 self.selected_player_count = self.selected_player_count + frametime;
634 if(save != UpdateSelectedPlayer_countvalue(self.selected_player_count))
636 string namestr, healthstr;
637 namestr = playername(selected);
640 healthstr = ftos(floor(selected.health));
641 if(self.team == selected.team)
643 namestr = strcat(namestr, " (", healthstr, "%)");
644 self.selected_player_display_needs_update = TRUE;
647 centerprint_atprio(self, CENTERPRIO_POINT, namestr);
652 ClearSelectedPlayer();
653 self.selected_player = selected;
654 self.selected_player_time = time;
655 self.selected_player_count = 0;
656 self.selected_player_display_needs_update = FALSE;
661 ClearSelectedPlayer();
664 if(self.selected_player)
665 self.last_selected_player = self.selected_player;
668 .float floodcontrol_chat;
669 .float floodcontrol_chatteam;
670 void Say(entity source, float teamsay, string msgin, float floodcontrol)
672 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr;
676 if(Ban_MaybeEnforceBan(source))
680 if(substring(msgin, 0, 1) == " ")
681 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
683 msgin = formatmessage(msgin);
688 if(source.classname != "player")
689 colorstr = "^0"; // black for spectators
690 else if(teams_matter)
691 colorstr = Team_ColorCode(source.team);
695 if(intermission_running)
699 * using bprint solves this... me stupid
700 // how can we prevent the message from appearing in a listen server?
701 // for now, just give "say" back and only handle say_team
704 clientcommand(self, strcat("say ", msgin));
709 if(cvar("g_chat_teamcolors"))
710 namestr = playername(source);
712 namestr = source.netname;
715 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
716 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
720 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
724 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
726 fullcmsgstr = cmsgstr;
735 var .float flood_field;
739 flood_spl = cvar("g_chat_flood_spl_team");
740 flood_burst = cvar("g_chat_flood_burst_team");
741 flood_lmax = cvar("g_chat_flood_lmax_team");
742 flood_field = floodcontrol_chatteam;
746 flood_spl = cvar("g_chat_flood_spl");
747 flood_burst = cvar("g_chat_flood_burst");
748 flood_lmax = cvar("g_chat_flood_lmax");
749 flood_field = floodcontrol_chat;
751 flood_burst = max(0, flood_burst - 1);
752 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
754 // 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, " ", getWrappedLine(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
763 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
765 if(getWrappedLine_remaining != "")
768 if(time >= self.flood_field)
769 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
776 if(cvar("g_chat_flood_notify_flooder"))
778 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
783 sourcemsgstr = fullmsgstr;
784 sourcecmsgstr = fullcmsgstr;
790 sourcemsgstr = msgstr;
791 sourcecmsgstr = cmsgstr;
794 if(source.classname != "player")
796 if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
797 teamsay = -1; // spectators
801 print("NOTE: ", playername(self), "^7 is flooding.\n");
805 if(cvar("g_chat_flood_notify_flooder"))
806 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
808 sprint(self, fullmsgstr);
812 sprint(source, sourcemsgstr);
813 if(sourcecmsgstr != "")
814 centerprint(source, sourcecmsgstr);
815 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
818 sprint(head, msgstr);
820 centerprint(head, cmsgstr);
825 sprint(source, sourcemsgstr);
826 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
828 sprint(head, msgstr);
830 else if(sourcemsgstr != msgstr)
832 sprint(source, sourcemsgstr);
833 FOR_EACH_REALCLIENT(head)
835 sprint(head, msgstr);
841 float GetVoiceMessageVoiceType(string type)
844 return VOICETYPE_TAUNT;
845 if(type == "teamshoot")
846 return VOICETYPE_LASTATTACKER;
847 return VOICETYPE_TEAMRADIO;
850 string allvoicesamples;
851 float GetPlayerSoundSampleField_notFound;
852 float GetPlayerSoundSampleField_fixed;
853 .string GetVoiceMessageSampleField(string type)
855 GetPlayerSoundSampleField_notFound = 0;
856 GetPlayerSoundSampleField_fixed = 0;
859 #define _VOICEMSG(m) case #m: return playersound_##m;
863 GetPlayerSoundSampleField_notFound = 1;
864 return playersound_taunt;
867 .string GetPlayerSoundSampleField(string type)
869 GetPlayerSoundSampleField_notFound = 0;
870 GetPlayerSoundSampleField_fixed = 0;
873 #define _VOICEMSG(m) case #m: return playersound_##m;
877 GetPlayerSoundSampleField_notFound = 1;
878 return playersound_taunt;
881 void PrecacheGlobalSound(string samplestring)
884 tokenize_console(samplestring);
888 for(i = 1; i <= n; ++i)
889 precache_sound(strcat(argv(0), ftos(i), ".wav"));
893 precache_sound(strcat(argv(0), ".wav"));
897 void PrecachePlayerSounds(string f)
901 fh = fopen(f, FILE_READ);
904 while((s = fgets(fh)))
906 if(tokenize_console(s) != 3)
908 dprint("Invalid sound info line: ", s, "\n");
911 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
915 if not(allvoicesamples)
917 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
920 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
924 void ClearPlayerSounds()
926 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
932 void LoadPlayerSounds(string f, float first)
937 fh = fopen(f, FILE_READ);
940 while((s = fgets(fh)))
942 if(tokenize_console(s) != 3)
944 field = GetPlayerSoundSampleField(argv(0));
945 if(GetPlayerSoundSampleField_notFound)
946 field = GetVoiceMessageSampleField(argv(0));
947 if(GetPlayerSoundSampleField_notFound)
949 if(GetPlayerSoundSampleField_fixed)
953 strunzone(self.field);
954 self.field = strzone(strcat(argv(1), " ", argv(2)));
959 .float modelindex_for_playersound;
960 void UpdatePlayerSounds()
962 if(self.modelindex == self.modelindex_for_playersound)
964 self.modelindex_for_playersound = self.modelindex;
966 LoadPlayerSounds("sound/player/default.sounds", 1);
967 LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
970 void GlobalSound(string sample, float chan, float voicetype)
978 tokenize_console(sample);
981 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
983 sample = strcat(argv(0), ".wav"); // randomization
987 case VOICETYPE_LASTATTACKER_ONLY:
989 if(self.pusher.team == self.team)
991 msg_entity = self.pusher;
992 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
994 if(msg_entity.cvar_cl_voice_directional == 1)
995 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
997 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1001 case VOICETYPE_LASTATTACKER:
1003 if(self.pusher.team == self.team)
1005 msg_entity = self.pusher;
1006 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1008 if(msg_entity.cvar_cl_voice_directional == 1)
1009 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1011 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1014 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1015 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1018 case VOICETYPE_TEAMRADIO:
1019 FOR_EACH_REALCLIENT(msg_entity)
1020 if(!teams_matter || msg_entity.team == self.team)
1022 if(msg_entity.cvar_cl_voice_directional == 1)
1023 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1025 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1028 case VOICETYPE_AUTOTAUNT:
1029 tauntrand = random();
1030 FOR_EACH_REALCLIENT(msg_entity)
1031 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1033 if (msg_entity.cvar_cl_voice_directional >= 1)
1034 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1036 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1039 case VOICETYPE_TAUNT:
1040 FOR_EACH_REALCLIENT(msg_entity)
1042 if (msg_entity.cvar_cl_voice_directional >= 1)
1043 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1045 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1047 case VOICETYPE_PLAYERSOUND:
1048 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1051 backtrace("Invalid voice type!");
1056 void PlayerSound(.string samplefield, float chan, float voicetype)
1059 sample = self.samplefield;
1060 GlobalSound(sample, chan, voicetype);
1063 .float floodcontrol_voice;
1064 .float floodcontrol_voiceteam;
1065 void VoiceMessage(string type, string msg)
1068 var float voicetype, ownteam;
1069 sample = GetVoiceMessageSampleField(type);
1071 if(GetPlayerSoundSampleField_notFound)
1073 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1077 voicetype = GetVoiceMessageVoiceType(type);
1078 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1082 var .float flood_field;
1087 flood_spv = cvar("g_voice_flood_spv_team");
1088 flood_field = floodcontrol_voiceteam;
1092 flood_spv = cvar("g_voice_flood_spv");
1093 flood_field = floodcontrol_voice;
1096 if(time >= self.flood_field)
1097 self.flood_field = max(time, self.flood_field) + flood_spv;
1102 Say(self, ownteam, msg, 0);
1105 PlayerSound(sample, CHAN_VOICE, voicetype);