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;
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);
432 Portal_ClearAllLater(self);
434 WaypointSprite_PlayerDead();
435 // make the corpse upright (not tilted)
439 self.avelocity = '0 0 0';
440 // view from the floor
441 self.view_ofs = '0 0 -8';
443 self.movetype = MOVETYPE_TOSS;
445 self.solid = SOLID_CORPSE;
446 // don't stick to the floor
447 self.flags &~= FL_ONGROUND;
449 self.deadflag = DEAD_DYING;
450 // when to allow respawn
453 if(cvar("g_respawn_mapsettings"))
455 sdelay = cvar("g_respawn_mapsettings_delay");
456 waves = cvar("g_respawn_mapsettings_waves");
459 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
461 sdelay = cvar("g_respawn_delay");
463 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
465 waves = cvar("g_respawn_waves");
467 self.death_time = ceil((time + sdelay) / waves) * waves;
469 self.death_time = time + sdelay;
470 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
471 self.respawn_countdown = 10; // first number to count down from is 10
473 self.respawn_countdown = -1; // do not count down
476 setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
477 self.dead_frame = self.anim_dead1_x;
481 setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
482 self.dead_frame = self.anim_dead2_x;
484 // set damage function to corpse damage
485 self.event_damage = PlayerCorpseDamage;
486 // call the corpse damage function just in case it wants to gib
487 self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
488 // set up to fade out later
489 SUB_SetFade (self, time + 12 + random () * 4, 1);
492 if(self.weaponentity)
493 if(self.weaponentity.lasertarget)
494 remove(self.weaponentity.lasertarget);
496 if(clienttype(self) == CLIENTTYPE_REAL)
498 self.fixangle = TRUE;
500 //WriteByte (MSG_ONE, SVC_SETANGLE);
501 //WriteAngle (MSG_ONE, self.v_angle_x);
502 //WriteAngle (MSG_ONE, self.v_angle_y);
503 //WriteAngle (MSG_ONE, 80);
507 Spawnqueue_Unmark(self);
509 if(defer_ClientKill_Now_TeamChange)
510 ClientKill_Now_TeamChange();
514 PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
519 float UpdateSelectedPlayer_countvalue(float v)
521 return max(0, (v - 1.0) / 0.5);
524 // returns: -2 if no hit, otherwise cos of the angle
525 // uses the global v_angle
526 float UpdateSelectedPlayer_canSee(entity p, float mincosangle, float maxdist)
537 so = self.origin + self.view_ofs;
541 if(dist_point_line(d, '0 0 0', v_forward) > maxdist)
544 // now find the cos of the angle...
545 c = normalize(d) * v_forward;
550 // not visible in any way? forget it
554 traceline(so, p.origin, MOVE_NOMONSTERS, self);
555 if(trace_fraction < 1)
561 void ClearSelectedPlayer()
563 if(self.selected_player)
565 centerprint_expire(self, CENTERPRIO_POINT);
566 self.selected_player = world;
567 self.selected_player_display_needs_update = FALSE;
571 void UpdateSelectedPlayer()
574 float selected_score;
576 selected_score = 0.95; // 18 degrees
578 if(!cvar("sv_allow_shownames"))
581 if(clienttype(self) != CLIENTTYPE_REAL)
584 if(self.cvar_cl_shownames == 0)
587 if(self.cvar_cl_shownames == 1 && !teams_matter)
590 makevectors(self.v_angle); // sets v_forward
592 // 1. cursor trace is always right
593 if(self.cursor_trace_ent && self.cursor_trace_ent.classname == "player" && !self.cursor_trace_ent.deadflag)
595 selected = self.cursor_trace_ent;
599 // 2. if we don't have a cursor trace, find the player which is least
605 c = UpdateSelectedPlayer_canSee(p, selected_score, 100); // 100 = 2.5 meters
616 self.selected_player_display_timeout = time + self.cvar_scr_centertime;
620 if(time < self.selected_player_display_timeout)
621 if(UpdateSelectedPlayer_canSee(self.selected_player, 0.7, 200) >= -1) // 5 meters, 45 degrees
622 selected = self.selected_player;
627 if(selected == self.selected_player)
630 save = UpdateSelectedPlayer_countvalue(self.selected_player_count);
631 self.selected_player_count = self.selected_player_count + frametime;
632 if(save != UpdateSelectedPlayer_countvalue(self.selected_player_count))
634 string namestr, healthstr;
635 namestr = playername(selected);
638 healthstr = ftos(floor(selected.health));
639 if(self.team == selected.team)
641 namestr = strcat(namestr, " (", healthstr, "%)");
642 self.selected_player_display_needs_update = TRUE;
645 centerprint_atprio(self, CENTERPRIO_POINT, namestr);
650 ClearSelectedPlayer();
651 self.selected_player = selected;
652 self.selected_player_time = time;
653 self.selected_player_count = 0;
654 self.selected_player_display_needs_update = FALSE;
659 ClearSelectedPlayer();
662 if(self.selected_player)
663 self.last_selected_player = self.selected_player;
666 .float floodcontrol_chat;
667 .float floodcontrol_chatteam;
668 void Say(entity source, float teamsay, string msgin, float floodcontrol)
670 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr;
674 if(Ban_MaybeEnforceBan(source))
678 if(substring(msgin, 0, 1) == " ")
679 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
681 msgin = formatmessage(msgin);
686 if(source.classname != "player")
687 colorstr = "^0"; // black for spectators
688 else if(teams_matter)
689 colorstr = Team_ColorCode(source.team);
693 if(intermission_running)
697 * using bprint solves this... me stupid
698 // how can we prevent the message from appearing in a listen server?
699 // for now, just give "say" back and only handle say_team
702 clientcommand(self, strcat("say ", msgin));
707 if(cvar("g_chat_teamcolors"))
708 namestr = playername(source);
710 namestr = source.netname;
713 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
714 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
718 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
722 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
724 fullcmsgstr = cmsgstr;
733 var .float flood_field;
737 flood_spl = cvar("g_chat_flood_spl_team");
738 flood_burst = cvar("g_chat_flood_burst_team");
739 flood_lmax = cvar("g_chat_flood_lmax_team");
740 flood_field = floodcontrol_chatteam;
744 flood_spl = cvar("g_chat_flood_spl");
745 flood_burst = cvar("g_chat_flood_burst");
746 flood_lmax = cvar("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
753 getWrappedLine_remaining = msgstr;
756 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
758 msgstr = strcat(msgstr, " ", getWrappedLine(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
761 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
763 if(getWrappedLine_remaining != "")
766 if(time >= self.flood_field)
767 self.flood_field = max(time - flood_burst * flood_spl, self.flood_field) + lines * flood_spl;
774 if(cvar("g_chat_flood_notify_flooder"))
776 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
781 sourcemsgstr = fullmsgstr;
782 sourcecmsgstr = fullcmsgstr;
788 sourcemsgstr = msgstr;
789 sourcecmsgstr = cmsgstr;
792 if(source.classname != "player")
794 if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
795 teamsay = -1; // spectators
799 print("NOTE: ", playername(self), "^7 is flooding.\n");
803 if(cvar("g_chat_flood_notify_flooder"))
804 sprint(self, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(self.flood_field - time), "^3 seconds\n"));
806 sprint(self, fullmsgstr);
810 sprint(source, sourcemsgstr);
811 if(sourcecmsgstr != "")
812 centerprint(source, sourcecmsgstr);
813 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
816 sprint(head, msgstr);
818 centerprint(head, cmsgstr);
823 sprint(source, sourcemsgstr);
824 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
826 sprint(head, msgstr);
828 else if(sourcemsgstr != msgstr)
830 sprint(source, sourcemsgstr);
831 FOR_EACH_REALCLIENT(head)
833 sprint(head, msgstr);
839 float GetVoiceMessageVoiceType(string type)
842 return VOICETYPE_TAUNT;
843 if(type == "teamshoot")
844 return VOICETYPE_LASTATTACKER;
845 return VOICETYPE_TEAMRADIO;
848 string allvoicesamples;
849 float GetPlayerSoundSampleField_notFound;
850 float GetPlayerSoundSampleField_fixed;
851 .string GetVoiceMessageSampleField(string type)
853 GetPlayerSoundSampleField_notFound = 0;
854 GetPlayerSoundSampleField_fixed = 0;
857 #define _VOICEMSG(m) case #m: return playersound_##m;
861 GetPlayerSoundSampleField_notFound = 1;
862 return playersound_taunt;
865 .string GetPlayerSoundSampleField(string type)
867 GetPlayerSoundSampleField_notFound = 0;
868 GetPlayerSoundSampleField_fixed = 0;
871 #define _VOICEMSG(m) case #m: return playersound_##m;
875 GetPlayerSoundSampleField_notFound = 1;
876 return playersound_taunt;
879 void PrecacheGlobalSound(string samplestring)
882 tokenize_sane(samplestring);
886 for(i = 1; i <= n; ++i)
887 precache_sound(strcat(argv(0), ftos(i), ".wav"));
891 precache_sound(strcat(argv(0), ".wav"));
895 void PrecachePlayerSounds(string f)
899 fh = fopen(f, FILE_READ);
902 while((s = fgets(fh)))
904 if(tokenize_sane(s) != 3)
906 dprint("Invalid sound info line: ", s, "\n");
909 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
913 if not(allvoicesamples)
915 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
918 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
922 void ClearPlayerSounds()
924 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
930 void LoadPlayerSounds(string f, float first)
935 fh = fopen(f, FILE_READ);
938 while((s = fgets(fh)))
940 if(tokenize_sane(s) != 3)
942 field = GetPlayerSoundSampleField(argv(0));
943 if(GetPlayerSoundSampleField_notFound)
944 field = GetVoiceMessageSampleField(argv(0));
945 if(GetPlayerSoundSampleField_notFound)
947 if(GetPlayerSoundSampleField_fixed)
951 strunzone(self.field);
952 self.field = strzone(strcat(argv(1), " ", argv(2)));
957 .float modelindex_for_playersound;
958 void UpdatePlayerSounds()
960 if(self.modelindex == self.modelindex_for_playersound)
962 self.modelindex_for_playersound = self.modelindex;
964 LoadPlayerSounds("sound/player/default.sounds", 1);
965 LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
968 void GlobalSound(string sample, float chan, float voicetype)
976 tokenize_sane(sample);
979 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
981 sample = strcat(argv(0), ".wav"); // randomization
985 case VOICETYPE_LASTATTACKER_ONLY:
987 if(self.pusher.team == self.team)
989 msg_entity = self.pusher;
990 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
992 if(msg_entity.cvar_cl_voice_directional == 1)
993 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
995 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
999 case VOICETYPE_LASTATTACKER:
1001 if(self.pusher.team == self.team)
1003 msg_entity = self.pusher;
1004 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1006 if(msg_entity.cvar_cl_voice_directional == 1)
1007 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1009 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1012 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1013 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1016 case VOICETYPE_TEAMRADIO:
1017 FOR_EACH_REALCLIENT(msg_entity)
1018 if(!teams_matter || msg_entity.team == self.team)
1020 if(msg_entity.cvar_cl_voice_directional == 1)
1021 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1023 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1026 case VOICETYPE_AUTOTAUNT:
1027 tauntrand = random();
1028 FOR_EACH_REALCLIENT(msg_entity)
1029 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1031 if (msg_entity.cvar_cl_voice_directional >= 1)
1032 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1034 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1037 case VOICETYPE_TAUNT:
1038 FOR_EACH_REALCLIENT(msg_entity)
1040 if (msg_entity.cvar_cl_voice_directional >= 1)
1041 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1043 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1045 case VOICETYPE_PLAYERSOUND:
1046 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1049 backtrace("Invalid voice type!");
1054 void PlayerSound(.string samplefield, float chan, float voicetype)
1057 sample = self.samplefield;
1058 GlobalSound(sample, chan, voicetype);
1061 .float floodcontrol_voice;
1062 .float floodcontrol_voiceteam;
1063 void VoiceMessage(string type, string msg)
1066 var float voicetype, ownteam;
1067 sample = GetVoiceMessageSampleField(type);
1069 if(GetPlayerSoundSampleField_notFound)
1071 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1075 voicetype = GetVoiceMessageVoiceType(type);
1076 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1080 var .float flood_field;
1085 flood_spv = cvar("g_voice_flood_spv_team");
1086 flood_field = floodcontrol_voiceteam;
1090 flood_spv = cvar("g_voice_flood_spv");
1091 flood_field = floodcontrol_voice;
1094 if(time >= self.flood_field)
1095 self.flood_field = max(time, self.flood_field) + flood_spv;
1100 Say(self, ownteam, msg, 0);
1103 PlayerSound(sample, CHAN_VOICE, voicetype);