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.species = oldself.species;
49 self.movetype = oldself.movetype;
50 self.nextthink = oldself.nextthink;
51 self.skin = oldself.skin;
52 self.solid = oldself.solid;
53 self.takedamage = oldself.takedamage;
54 self.think = oldself.think;
55 self.customizeentityforclient = oldself.customizeentityforclient;
56 if (keepvelocity == 1)
57 self.velocity = oldself.velocity;
58 self.oldvelocity = self.velocity;
59 self.fade_time = oldself.fade_time;
60 self.fade_rate = oldself.fade_rate;
61 //self.weapon = oldself.weapon;
62 setorigin(self, oldself.origin);
63 setsize(self, oldself.mins, oldself.maxs);
64 self.prevorigin = oldself.origin;
65 self.reset = SUB_Remove;
67 Drag_MoveDrag(oldself, self);
72 float player_getspecies()
74 local float glob, i, j, fh, len, s, sk;
79 glob = search_begin("models/player/*.txt", TRUE, TRUE);
82 for(j = 0; j <= 1; ++j)
84 for(i = 0; i < search_getsize(glob); ++i)
86 fn = search_getfilename(glob, i);
87 fh = fopen(fn, FILE_READ);
92 if(sk == (j ? 0 : self.skin)) // 2nd pass skips the skin test
93 if(fgets(fh) == self.model)
96 len = tokenize_console(l);
99 if (argv(0) != "species")
103 case "human": s = SPECIES_HUMAN; break;
104 case "alien": s = SPECIES_ALIEN; break;
105 case "robot_shiny": s = SPECIES_ROBOT_SHINY; break;
106 case "robot_rusty": s = SPECIES_ROBOT_RUSTY; break;
107 case "animal": s = SPECIES_ANIMAL; break;
108 case "reserved": s = SPECIES_RESERVED; break;
125 void player_setupanimsformodel()
127 local string animfilename;
128 local float animfile;
129 // defaults for legacy .zym models without animinfo files
130 self.anim_die1 = '0 1 0.5'; // 2 seconds
131 self.anim_die2 = '1 1 0.5'; // 2 seconds
132 self.anim_draw = '2 1 3'; // TODO: analyze models and set framerate
133 self.anim_duck = '3 1 100'; // this anim seems bogus in most models, so make it play VERY briefly!
134 self.anim_duckwalk = '4 1 1';
135 self.anim_duckjump = '5 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
136 self.anim_duckidle = '6 1 1';
137 self.anim_idle = '7 1 1';
138 self.anim_jump = '8 1 100'; // zym anims keep playing until changed, so this only has to start the anim, landing will end it
139 self.anim_pain1 = '9 1 2'; // 0.5 seconds
140 self.anim_pain2 = '10 1 2'; // 0.5 seconds
141 self.anim_shoot = '11 1 5'; // TODO: analyze models and set framerate
142 self.anim_taunt = '12 1 1'; // FIXME? there is no code using this anim
143 self.anim_run = '13 1 1';
144 self.anim_runbackwards = '14 1 1';
145 self.anim_strafeleft = '15 1 1';
146 self.anim_straferight = '16 1 1';
147 self.anim_dead1 = '17 1 1';
148 self.anim_dead2 = '18 1 1';
149 self.anim_forwardright = '19 1 1';
150 self.anim_forwardleft = '20 1 1';
151 self.anim_backright = '21 1 1';
152 self.anim_backleft = '22 1 1';
153 animparseerror = FALSE;
154 animfilename = strcat(self.model, ".animinfo");
155 animfile = fopen(animfilename, FILE_READ);
158 self.anim_die1 = animparseline(animfile);
159 self.anim_die2 = animparseline(animfile);
160 self.anim_draw = animparseline(animfile);
161 self.anim_duck = animparseline(animfile);
162 self.anim_duckwalk = animparseline(animfile);
163 self.anim_duckjump = animparseline(animfile);
164 self.anim_duckidle = animparseline(animfile);
165 self.anim_idle = animparseline(animfile);
166 self.anim_jump = animparseline(animfile);
167 self.anim_pain1 = animparseline(animfile);
168 self.anim_pain2 = animparseline(animfile);
169 self.anim_shoot = animparseline(animfile);
170 self.anim_taunt = animparseline(animfile);
171 self.anim_run = animparseline(animfile);
172 self.anim_runbackwards = animparseline(animfile);
173 self.anim_strafeleft = animparseline(animfile);
174 self.anim_straferight = animparseline(animfile);
175 self.anim_forwardright = animparseline(animfile);
176 self.anim_forwardleft = animparseline(animfile);
177 self.anim_backright = animparseline(animfile);
178 self.anim_backleft = animparseline(animfile);
182 self.anim_dead1 = '0 1 1' + '1 0 0' * (self.anim_die1_x + self.anim_die1_y - 1);
183 self.anim_dead2 = '0 1 1' + '1 0 0' * (self.anim_die2_x + self.anim_die2_y - 1);
186 print("Parse error in ", animfilename, ", some player animations are broken\n");
189 dprint("File ", animfilename, " not found, assuming legacy .zym model animation timings\n");
190 // reset animstate now
191 setanim(self, self.anim_idle, TRUE, FALSE, TRUE);
194 void player_anim (void)
197 if (self.weaponentity)
198 updateanim(self.weaponentity);
200 if (self.deadflag != DEAD_NO)
202 if (time > self.animstate_endtime)
207 setsize(self, self.mins, self.maxs);
209 self.frame = self.dead_frame;
214 if (!self.animstate_override)
216 if (!(self.flags & FL_ONGROUND))
219 setanim(self, self.anim_duckjump, FALSE, TRUE, FALSE);
221 setanim(self, self.anim_jump, FALSE, TRUE, FALSE);
223 else if (self.crouch)
225 if (self.movement_x * self.movement_x + self.movement_y * self.movement_y > 20)
226 setanim(self, self.anim_duckwalk, TRUE, FALSE, FALSE);
228 setanim(self, self.anim_duckidle, TRUE, FALSE, FALSE);
230 else if ((self.movement_x * self.movement_x + self.movement_y * self.movement_y) > 20)
232 if (self.movement_x > 0 && self.movement_y == 0)
233 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
234 else if (self.movement_x < 0 && self.movement_y == 0)
235 setanim(self, self.anim_runbackwards, TRUE, FALSE, FALSE);
236 else if (self.movement_x == 0 && self.movement_y > 0)
237 setanim(self, self.anim_straferight, TRUE, FALSE, FALSE);
238 else if (self.movement_x == 0 && self.movement_y < 0)
239 setanim(self, self.anim_strafeleft, TRUE, FALSE, FALSE);
240 else if (self.movement_x > 0 && self.movement_y > 0)
241 setanim(self, self.anim_forwardright, TRUE, FALSE, FALSE);
242 else if (self.movement_x > 0 && self.movement_y < 0)
243 setanim(self, self.anim_forwardleft, TRUE, FALSE, FALSE);
244 else if (self.movement_x < 0 && self.movement_y > 0)
245 setanim(self, self.anim_backright, TRUE, FALSE, FALSE);
246 else if (self.movement_x < 0 && self.movement_y < 0)
247 setanim(self, self.anim_backleft, TRUE, FALSE, FALSE);
249 setanim(self, self.anim_run, TRUE, FALSE, FALSE);
252 setanim(self, self.anim_idle, TRUE, FALSE, FALSE);
255 if (self.weaponentity)
256 if (!self.weaponentity.animstate_override)
257 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
260 void SpawnThrownWeapon (vector org, float w)
265 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
267 if(self.weapons & W_WeaponBit(j))
268 if(W_IsWeaponThrowable(j))
269 W_ThrowNewWeapon(self, j, FALSE, self.origin, randomvec() * 175 + '0 0 325');
273 W_ThrowWeapon(randomvec() * 125 + '0 0 200', org - self.origin, FALSE);
276 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
278 local float take, save;
279 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16);
281 // damage resistance (ignore most of the damage from a bullet or similar)
282 damage = max(damage - 5, 1);
284 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
285 take = bound(0, damage - save, damage);
288 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
290 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
292 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM);
295 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1);
297 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1);
299 if (!(self.flags & FL_GODMODE))
301 self.armorvalue = self.armorvalue - save;
302 self.health = self.health - take;
303 // pause regeneration for 5 seconds
304 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
306 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
307 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
308 self.dmg_inflictor = inflictor;
310 if (self.health <= -75 && self.modelindex != 0)
312 // don't use any animations as a gib
315 // view just above the floor
316 self.view_ofs = '0 0 4';
318 Violence_GibSplash(self, 1, 1);
319 self.modelindex = 0; // restore later
320 self.solid = SOLID_NOT; // restore later
324 void ClientKill_Now_TeamChange();
326 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
328 local float take, save, waves, sdelay;
330 if(!DEATH_ISSPECIAL(deathtype))
332 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
334 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
337 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
339 // tuba causes blood to come out of the ears
340 print(ftos(self.health), "\n");
345 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
347 makevectors(self.angles);
348 ear1 += v_right * -10;
349 ear2 += v_right * +10;
350 d = inflictor.origin - self.origin;
351 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
352 force = v_right * vlen(force);
353 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f));
354 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f));
363 // force is already good
367 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16);
375 save = bound(0, damage * cvar("g_balance_armor_blockpercent"), self.armorvalue);
376 take = bound(0, damage - save, damage);
385 sound (self, CHAN_PROJECTILE, "misc/armorimpact.wav", VOL_BASE, ATTN_NORM);
387 sound (self, CHAN_PROJECTILE, "misc/bodyimpact2.wav", VOL_BASE, ATTN_NORM);
389 sound (self, CHAN_PROJECTILE, "misc/bodyimpact1.wav", VOL_BASE, ATTN_NORM); // FIXME possibly remove them?
392 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1);
394 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1);
396 if (time > self.spawnshieldtime)
398 if (!(self.flags & FL_GODMODE))
400 self.armorvalue = self.armorvalue - save;
401 self.health = self.health - take;
402 // pause regeneration for 5 seconds
403 self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
405 if (time > self.pain_finished) //Don't switch pain sequences like crazy
407 self.pain_finished = time + 0.5; //Supajoe
410 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
413 setanim(self, self.anim_pain1, FALSE, TRUE, TRUE);
415 setanim(self, self.anim_pain2, FALSE, TRUE, TRUE);
418 if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
419 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
421 if(self.health > 75) // TODO make a "gentle" version?
422 PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
423 else if(self.health > 50)
424 PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
425 else if(self.health > 25)
426 PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
427 else if(self.health > 1)
428 PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
432 // throw off bot aim temporarily
434 shake = damage * 5 / (bound(0,skill,100) + 1);
435 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
436 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
440 self.max_armorvalue += (save + take);
442 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
443 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
444 self.dmg_inflictor = inflictor;
448 // don't reset pushltime for self damage as it may be an attempt to
449 // escape a lava pit or similar
450 //self.pushltime = 0;
452 else if(attacker.classname == "player" || attacker.classname == "gib")
454 self.pusher = attacker;
455 self.pushltime = time + cvar("g_maxpushtime");
457 else if(time < self.pushltime)
459 attacker = self.pusher;
460 self.pushltime = max(self.pushltime, time + 0.6);
467 float defer_ClientKill_Now_TeamChange;
468 defer_ClientKill_Now_TeamChange = FALSE;
470 if(sv_gentle < 1) // TODO make a "gentle" version?
472 if(deathtype == DEATH_DROWN)
473 PlayerSound(playersound_drown, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
475 PlayerSound(playersound_death, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
478 // get rid of kill indicator
479 if(self.killindicator)
481 remove(self.killindicator);
482 self.killindicator = world;
483 if(self.killindicator_teamchange)
484 defer_ClientKill_Now_TeamChange = TRUE;
486 if(self.classname == "body")
487 if(deathtype == DEATH_KILL)
489 // for the lemmings fans, a small harmless explosion
490 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
494 // become fully visible
496 // clear selected player display
497 ClearSelectedPlayer();
499 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
500 // print an obituary message
501 Obituary (attacker, inflictor, self, deathtype);
505 kh_Key_DropAll(self, TRUE);
506 else if(attacker.classname == "player" || attacker.classname == "gib")
507 kh_Key_DropAll(self, FALSE);
509 kh_Key_DropAll(self, TRUE);
512 if(attacker.classname != "player" && attacker.classname != "gib")
513 DropFlag(self.flagcarried, self, attacker); // penalty for flag loss by suicide
514 else if(attacker.team == self.team)
515 DropFlag(self.flagcarried, attacker, attacker); // penalty for flag loss by suicide/teamkill
517 DropFlag(self.flagcarried, world, attacker);
520 DropBall(self.ballcarried, self.origin, self.velocity);
521 Portal_ClearAllLater(self);
523 WaypointSprite_PlayerDead();
524 // make the corpse upright (not tilted)
528 self.avelocity = '0 0 0';
529 // view from the floor
530 self.view_ofs = '0 0 -8';
532 self.movetype = MOVETYPE_TOSS;
534 self.solid = SOLID_CORPSE;
535 // don't stick to the floor
536 self.flags &~= FL_ONGROUND;
538 self.deadflag = DEAD_DYING;
539 // when to allow respawn
542 if(cvar("g_respawn_mapsettings"))
544 sdelay = cvar("g_respawn_mapsettings_delay");
545 waves = cvar("g_respawn_mapsettings_waves");
548 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
550 sdelay = cvar("g_respawn_delay");
552 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
554 waves = cvar("g_respawn_waves");
556 self.death_time = ceil((time + sdelay) / waves) * waves;
558 self.death_time = time + sdelay;
559 if((sdelay + waves >= 5.0) && (self.death_time - time > 1.75))
560 self.respawn_countdown = 10; // first number to count down from is 10
562 self.respawn_countdown = -1; // do not count down
565 setanim(self, self.anim_die1, FALSE, TRUE, TRUE);
566 self.dead_frame = self.anim_dead1_x;
570 setanim(self, self.anim_die2, FALSE, TRUE, TRUE);
571 self.dead_frame = self.anim_dead2_x;
573 // set damage function to corpse damage
574 self.event_damage = PlayerCorpseDamage;
575 // call the corpse damage function just in case it wants to gib
576 self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
577 // set up to fade out later
578 SUB_SetFade (self, time + 12 + random () * 4, 1);
581 if(self.weaponentity)
582 if(self.weaponentity.lasertarget)
583 remove(self.weaponentity.lasertarget);
585 if(clienttype(self) == CLIENTTYPE_REAL)
587 self.fixangle = TRUE;
589 //WriteByte (MSG_ONE, SVC_SETANGLE);
590 //WriteAngle (MSG_ONE, self.v_angle_x);
591 //WriteAngle (MSG_ONE, self.v_angle_y);
592 //WriteAngle (MSG_ONE, 80);
596 Spawnqueue_Unmark(self);
598 if(defer_ClientKill_Now_TeamChange)
599 ClientKill_Now_TeamChange();
603 PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
608 float UpdateSelectedPlayer_countvalue(float v)
610 return max(0, (v - 1.0) / 0.5);
613 // returns: -2 if no hit, otherwise cos of the angle
614 // uses the global v_angle
615 float UpdateSelectedPlayer_canSee(entity p, float mincosangle, float maxdist)
626 so = self.origin + self.view_ofs;
630 if(dist_point_line(d, '0 0 0', v_forward) > maxdist)
633 // now find the cos of the angle...
634 c = normalize(d) * v_forward;
639 // not visible in any way? forget it
643 traceline(so, p.origin, MOVE_NOMONSTERS, self);
644 if(trace_fraction < 1)
650 void ClearSelectedPlayer()
652 if(self.selected_player)
654 centerprint_expire(self, CENTERPRIO_POINT);
655 self.selected_player = world;
656 self.selected_player_display_needs_update = FALSE;
660 void UpdateSelectedPlayer()
663 float selected_score;
665 selected_score = 0.95; // 18 degrees
667 if(!cvar("sv_allow_shownames"))
670 if(clienttype(self) != CLIENTTYPE_REAL)
673 if(self.cvar_cl_shownames == 0)
676 if(self.cvar_cl_shownames == 1 && !teams_matter)
679 makevectors(self.v_angle); // sets v_forward
681 // 1. cursor trace is always right
682 if(self.cursor_trace_ent && self.cursor_trace_ent.classname == "player" && !self.cursor_trace_ent.deadflag)
684 selected = self.cursor_trace_ent;
688 // 2. if we don't have a cursor trace, find the player which is least
694 c = UpdateSelectedPlayer_canSee(p, selected_score, 100); // 100 = 2.5 meters
705 self.selected_player_display_timeout = time + self.cvar_scr_centertime;
709 if(time < self.selected_player_display_timeout)
710 if(UpdateSelectedPlayer_canSee(self.selected_player, 0.7, 200) >= -1) // 5 meters, 45 degrees
711 selected = self.selected_player;
716 if(selected == self.selected_player)
719 save = UpdateSelectedPlayer_countvalue(self.selected_player_count);
720 self.selected_player_count = self.selected_player_count + frametime;
721 if(save != UpdateSelectedPlayer_countvalue(self.selected_player_count))
723 string namestr, healthstr;
724 namestr = playername(selected);
727 healthstr = ftos(floor(selected.health));
728 if(self.team == selected.team)
730 namestr = strcat(namestr, " (", healthstr, "%)");
731 self.selected_player_display_needs_update = TRUE;
734 centerprint_atprio(self, CENTERPRIO_POINT, namestr);
739 ClearSelectedPlayer();
740 self.selected_player = selected;
741 self.selected_player_time = time;
742 self.selected_player_count = 0;
743 self.selected_player_display_needs_update = FALSE;
748 ClearSelectedPlayer();
751 if(self.selected_player)
752 self.last_selected_player = self.selected_player;
755 .float muted; // to be used by prvm_edictset server playernumber muted 1
756 void Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
758 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, privatemsgprefix;
759 float flood, privatemsgprefixlen;
762 if(Ban_MaybeEnforceBan(source))
765 if(!teamsay && !privatesay)
766 if(substring(msgin, 0, 1) == " ")
767 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
769 msgin = formatmessage(msgin);
774 if(source.classname != "player")
775 colorstr = "^0"; // black for spectators
776 else if(teams_matter)
777 colorstr = Team_ColorCode(source.team);
781 if(intermission_running)
785 * using bprint solves this... me stupid
786 // how can we prevent the message from appearing in a listen server?
787 // for now, just give "say" back and only handle say_team
790 clientcommand(self, strcat("say ", msgin));
795 if(cvar("g_chat_teamcolors"))
796 namestr = playername(source);
798 namestr = source.netname;
802 msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
803 privatemsgprefixlen = strlen(msgstr);
804 msgstr = strcat(msgstr, msgin);
805 cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
806 if(cvar("g_chat_teamcolors"))
807 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
809 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
813 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
814 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
818 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
822 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
824 fullcmsgstr = cmsgstr;
833 var .float flood_field;
837 flood_spl = cvar("g_chat_flood_spl_tell");
838 flood_burst = cvar("g_chat_flood_burst_tell");
839 flood_lmax = cvar("g_chat_flood_lmax_tell");
840 flood_field = floodcontrol_chattell;
844 flood_spl = cvar("g_chat_flood_spl_team");
845 flood_burst = cvar("g_chat_flood_burst_team");
846 flood_lmax = cvar("g_chat_flood_lmax_team");
847 flood_field = floodcontrol_chatteam;
851 flood_spl = cvar("g_chat_flood_spl");
852 flood_burst = cvar("g_chat_flood_burst");
853 flood_lmax = cvar("g_chat_flood_lmax");
854 flood_field = floodcontrol_chat;
856 flood_burst = max(0, flood_burst - 1);
857 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
859 // do flood control for the default line size
860 getWrappedLine_remaining = msgstr;
863 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
865 msgstr = strcat(msgstr, " ", getWrappedLine(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
868 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
870 if(getWrappedLine_remaining != "")
872 msgstr = strcat(msgstr, "\n");
876 if(time >= source.flood_field)
878 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
887 if (timeoutStatus == 2) //when game is paused, no flood protection
888 source.flood_field = flood = 0;
892 if(cvar("g_chat_flood_notify_flooder"))
894 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
899 sourcemsgstr = fullmsgstr;
900 sourcecmsgstr = fullcmsgstr;
906 sourcemsgstr = msgstr;
907 sourcecmsgstr = cmsgstr;
911 if(source.classname != "player")
913 if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
914 teamsay = -1; // spectators
918 print("NOTE: ", playername(source), "^7 is flooding.\n");
920 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
922 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
926 // always fake the message
927 sprint(source, sourcemsgstr);
928 if(cmsgstr != "" && !privatesay)
929 centerprint(source, sourcecmsgstr);
933 if(cvar("g_chat_flood_notify_flooder"))
934 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
937 sprint(source, sourcemsgstr);
938 if(cmsgstr != "" && !privatesay)
939 centerprint(source, sourcecmsgstr);
944 sprint(source, sourcemsgstr);
945 sprint(privatesay, msgstr);
947 centerprint(privatesay, cmsgstr);
951 sprint(source, sourcemsgstr);
952 if(sourcecmsgstr != "")
953 centerprint(source, sourcecmsgstr);
954 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
957 sprint(head, msgstr);
959 centerprint(head, cmsgstr);
964 sprint(source, sourcemsgstr);
965 FOR_EACH_REALCLIENT(head) if(head.classname != "player")
967 sprint(head, msgstr);
969 else if(sourcemsgstr != msgstr)
971 sprint(source, sourcemsgstr);
972 FOR_EACH_REALCLIENT(head)
974 sprint(head, msgstr);
980 float GetVoiceMessageVoiceType(string type)
983 return VOICETYPE_TAUNT;
984 if(type == "teamshoot")
985 return VOICETYPE_LASTATTACKER;
986 return VOICETYPE_TEAMRADIO;
989 string allvoicesamples;
990 float GetPlayerSoundSampleField_notFound;
991 float GetPlayerSoundSampleField_fixed;
992 .string GetVoiceMessageSampleField(string type)
994 GetPlayerSoundSampleField_notFound = 0;
995 GetPlayerSoundSampleField_fixed = 0;
998 #define _VOICEMSG(m) case #m: return playersound_##m;
1002 GetPlayerSoundSampleField_notFound = 1;
1003 return playersound_taunt;
1006 .string GetPlayerSoundSampleField(string type)
1008 GetPlayerSoundSampleField_notFound = 0;
1009 GetPlayerSoundSampleField_fixed = 0;
1012 #define _VOICEMSG(m) case #m: return playersound_##m;
1016 GetPlayerSoundSampleField_notFound = 1;
1017 return playersound_taunt;
1020 void PrecacheGlobalSound(string samplestring)
1023 tokenize_console(samplestring);
1027 for(i = 1; i <= n; ++i)
1028 precache_sound(strcat(argv(0), ftos(i), ".wav"));
1032 precache_sound(strcat(argv(0), ".wav"));
1036 void PrecachePlayerSounds(string f)
1040 fh = fopen(f, FILE_READ);
1043 while((s = fgets(fh)))
1045 if(tokenize_console(s) != 3)
1047 dprint("Invalid sound info line: ", s, "\n");
1050 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1054 if not(allvoicesamples)
1056 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1059 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1063 void ClearPlayerSounds()
1065 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1071 void LoadPlayerSounds(string f, float first)
1076 fh = fopen(f, FILE_READ);
1079 while((s = fgets(fh)))
1081 if(tokenize_console(s) != 3)
1083 field = GetPlayerSoundSampleField(argv(0));
1084 if(GetPlayerSoundSampleField_notFound)
1085 field = GetVoiceMessageSampleField(argv(0));
1086 if(GetPlayerSoundSampleField_notFound)
1088 if(GetPlayerSoundSampleField_fixed)
1092 strunzone(self.field);
1093 self.field = strzone(strcat(argv(1), " ", argv(2)));
1098 .float modelindex_for_playersound;
1099 void UpdatePlayerSounds()
1101 if(self.modelindex == self.modelindex_for_playersound)
1103 self.modelindex_for_playersound = self.modelindex;
1104 ClearPlayerSounds();
1105 LoadPlayerSounds("sound/player/default.sounds", 1);
1106 LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
1109 void GlobalSound(string sample, float chan, float voicetype)
1117 tokenize_console(sample);
1120 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1122 sample = strcat(argv(0), ".wav"); // randomization
1126 case VOICETYPE_LASTATTACKER_ONLY:
1128 if(self.pusher.team == self.team)
1130 msg_entity = self.pusher;
1131 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1133 if(msg_entity.cvar_cl_voice_directional == 1)
1134 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1136 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1140 case VOICETYPE_LASTATTACKER:
1142 if(self.pusher.team == self.team)
1144 msg_entity = self.pusher;
1145 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1147 if(msg_entity.cvar_cl_voice_directional == 1)
1148 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1150 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1153 if(clienttype(msg_entity) == CLIENTTYPE_REAL)
1154 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
1157 case VOICETYPE_TEAMRADIO:
1158 FOR_EACH_REALCLIENT(msg_entity)
1159 if(!teams_matter || msg_entity.team == self.team)
1161 if(msg_entity.cvar_cl_voice_directional == 1)
1162 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
1164 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1167 case VOICETYPE_AUTOTAUNT:
1168 tauntrand = random();
1169 FOR_EACH_REALCLIENT(msg_entity)
1170 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1172 if (msg_entity.cvar_cl_voice_directional >= 1)
1173 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1175 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1178 case VOICETYPE_TAUNT:
1179 FOR_EACH_REALCLIENT(msg_entity)
1181 if (msg_entity.cvar_cl_voice_directional >= 1)
1182 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
1184 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
1186 case VOICETYPE_PLAYERSOUND:
1187 sound(self, chan, sample, VOL_BASE, ATTN_NORM);
1190 backtrace("Invalid voice type!");
1195 void PlayerSound(.string samplefield, float chan, float voicetype)
1198 sample = self.samplefield;
1199 GlobalSound(sample, chan, voicetype);
1202 void VoiceMessage(string type, string msg)
1205 var float voicetype, ownteam;
1206 sample = GetVoiceMessageSampleField(type);
1208 if(GetPlayerSoundSampleField_notFound)
1210 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1214 voicetype = GetVoiceMessageVoiceType(type);
1215 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1219 var .float flood_field;
1224 flood_spv = cvar("g_voice_flood_spv_team");
1225 flood_field = floodcontrol_voiceteam;
1229 flood_spv = cvar("g_voice_flood_spv");
1230 flood_field = floodcontrol_voice;
1233 if(time >= self.flood_field)
1234 self.flood_field = max(time, self.flood_field) + flood_spv;
1238 if (timeoutStatus == 2) //when game is paused, no flood protection
1239 self.flood_field = flood = 0;
1242 Say(self, ownteam, world, msg, 0);
1245 PlayerSound(sample, CHAN_VOICE, voicetype);