5 .float CopyBody_nextthink;
6 .void(void) CopyBody_think;
7 void CopyBody_Think(void)
9 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
11 self.CopyBody_think();
14 self.CopyBody_nextthink = self.nextthink;
15 self.CopyBody_think = self.think;
16 self.think = CopyBody_Think;
18 CSQCMODEL_AUTOUPDATE();
19 self.nextthink = time;
21 void CopyBody(float keepvelocity)
24 if (self.effects & EF_NODRAW)
29 self.lip = oldself.lip;
30 self.colormap = oldself.colormap;
31 self.iscreature = oldself.iscreature;
32 self.teleportable = oldself.teleportable;
33 self.damagedbycontents = oldself.damagedbycontents;
34 self.angles = oldself.angles;
35 self.avelocity = oldself.avelocity;
36 self.classname = "body";
37 self.damageforcescale = oldself.damageforcescale;
38 self.effects = oldself.effects;
39 self.glowmod = oldself.glowmod;
40 self.event_damage = oldself.event_damage;
41 self.anim_state = oldself.anim_state;
42 self.anim_time = oldself.anim_time;
43 self.anim_lower_action = oldself.anim_lower_action;
44 self.anim_lower_time = oldself.anim_lower_time;
45 self.anim_upper_action = oldself.anim_upper_action;
46 self.anim_upper_time = oldself.anim_upper_time;
47 self.anim_implicit_state = oldself.anim_implicit_state;
48 self.anim_implicit_time = oldself.anim_implicit_time;
49 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
50 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
51 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
52 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
53 self.dphitcontentsmask = oldself.dphitcontentsmask;
54 self.death_time = oldself.death_time;
55 self.pain_finished = oldself.pain_finished;
56 self.health = oldself.health;
57 self.armorvalue = oldself.armorvalue;
58 self.armortype = oldself.armortype;
59 self.model = oldself.model;
60 self.modelindex = oldself.modelindex;
61 self.skin = oldself.skin;
62 self.species = oldself.species;
63 self.movetype = oldself.movetype;
64 self.solid = oldself.solid;
65 self.ballistics_density = oldself.ballistics_density;
66 self.takedamage = oldself.takedamage;
67 self.customizeentityforclient = oldself.customizeentityforclient;
68 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
69 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
70 if (keepvelocity == 1)
71 self.velocity = oldself.velocity;
72 self.oldvelocity = self.velocity;
73 self.alpha = oldself.alpha;
74 self.fade_time = oldself.fade_time;
75 self.fade_rate = oldself.fade_rate;
76 //self.weapon = oldself.weapon;
77 setorigin(self, oldself.origin);
78 setsize(self, oldself.mins, oldself.maxs);
79 self.prevorigin = oldself.origin;
80 self.reset = SUB_Remove;
82 Drag_MoveDrag(oldself, self);
84 if(self.colormap <= maxclients && self.colormap > 0)
85 self.colormap = 1024 + oldself.clientcolors;
88 self.CopyBody_nextthink = oldself.nextthink;
89 self.CopyBody_think = oldself.think;
90 self.nextthink = time;
91 self.think = CopyBody_Think;
92 // "bake" the current animation frame for clones (they don't get clientside animation)
93 animdecide_setframes(self, FALSE, frame, frame1time, frame2, frame2time);
98 float player_getspecies()
101 get_model_parameters(self.model, self.skin);
102 s = get_model_parameters_species;
103 get_model_parameters(string_null, 0);
105 return SPECIES_HUMAN;
109 void player_setupanimsformodel()
111 // load animation info
112 animdecide_init(self);
113 animdecide_setstate(self, 0, FALSE);
116 void player_anim (void)
118 float deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
119 if(self.deadflag && !deadbits)
121 deadbits = ANIMSTATE_DEAD1;
123 deadbits = ANIMSTATE_DEAD2;
124 float animbits = deadbits;
125 if(self.freezetag_frozen)
126 animbits |= ANIMSTATE_FROZEN;
128 animbits |= ANIMSTATE_DUCK;
129 animdecide_setstate(self, animbits, FALSE);
130 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
132 if (self.weaponentity)
134 updateanim(self.weaponentity);
135 if (!self.weaponentity.animstate_override)
136 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
140 void SpawnThrownWeapon (vector org, float w)
142 if(self.weapons & WepSet_FromWeapon(self.weapon))
143 if(W_IsWeaponThrowable(self.weapon))
144 W_ThrowNewWeapon(self, self.weapon, FALSE, org, randomvec() * 125 + '0 0 200');
147 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
151 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
153 // damage resistance (ignore most of the damage from a bullet or similar)
154 damage = max(damage - 5, 1);
156 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
160 if(sound_allowed(MSG_BROADCAST, attacker))
163 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
165 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
167 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
171 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
173 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
175 if (!(self.flags & FL_GODMODE))
177 self.armorvalue = self.armorvalue - save;
178 self.health = self.health - take;
179 // pause regeneration for 5 seconds
180 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
182 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
183 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
184 self.dmg_inflictor = inflictor;
186 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
188 // don't use any animations as a gib
190 // view just above the floor
191 self.view_ofs = '0 0 4';
193 Violence_GibSplash(self, 1, 1, attacker);
195 self.solid = SOLID_NOT; // restore later
196 self.takedamage = DAMAGE_NO; // restore later
197 self.damagedbycontents = FALSE;
201 void ClientKill_Now_TeamChange();
203 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
205 float take, save, waves, sdelay, dh, da, j;
207 float valid_damage_for_weaponstats;
210 dh = max(self.health, 0);
211 da = max(self.armorvalue, 0);
213 if(!DEATH_ISSPECIAL(deathtype))
215 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
217 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
220 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
222 // tuba causes blood to come out of the ears
227 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
229 makevectors(self.angles);
230 ear1 += v_right * -10;
231 ear2 += v_right * +10;
232 d = inflictor.origin - self.origin;
234 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
236 f = 0; // Assum ecenter.
237 force = v_right * vlen(force);
238 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
239 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
248 // force is already good
252 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
255 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
261 // don't reset pushltime for self damage as it may be an attempt to
262 // escape a lava pit or similar
263 //self.pushltime = 0;
266 else if(IS_PLAYER(attacker))
268 self.pusher = attacker;
269 self.pushltime = time + autocvar_g_maxpushtime;
270 self.istypefrag = self.BUTTON_CHAT;
272 else if(time < self.pushltime)
274 attacker = self.pusher;
275 self.pushltime = max(self.pushltime, time + 0.6);
283 frag_inflictor = inflictor;
284 frag_attacker = attacker;
286 frag_damage = damage;
289 damage_force = force;
290 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
291 take = bound(0, damage_take, self.health);
292 save = bound(0, damage_save, self.armorvalue);
293 excess = max(0, damage - take - save);
295 if(sound_allowed(MSG_BROADCAST, attacker))
298 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
300 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
302 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
306 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
308 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
310 if (time >= self.spawnshieldtime)
312 if (!(self.flags & FL_GODMODE))
314 self.armorvalue = self.armorvalue - save;
315 self.health = self.health - take;
316 // pause regeneration for 5 seconds
318 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
320 if (time > self.pain_finished) //Don't switch pain sequences like crazy
322 self.pain_finished = time + 0.5; //Supajoe
324 if(autocvar_sv_gentle < 1) {
325 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
327 if (!self.animstate_override)
330 animdecide_setaction(self, ANIMACTION_PAIN1, TRUE);
332 animdecide_setaction(self, ANIMACTION_PAIN2, TRUE);
336 if(sound_allowed(MSG_BROADCAST, attacker))
337 if(!DEATH_ISWEAPON(deathtype, WEP_BLASTER) || attacker != self || self.health < 2 * WEP_CVAR_PRI(blaster, damage) * autocvar_g_balance_selfdamagepercent + 1) // WEAPONTODO: create separate limit for pain notification with laser
339 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
341 if(deathtype == DEATH_FALL)
342 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
343 else if(self.health > 75) // TODO make a "gentle" version?
344 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
345 else if(self.health > 50)
346 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
347 else if(self.health > 25)
348 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
350 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
354 // throw off bot aim temporarily
356 shake = damage * 5 / (bound(0,skill,100) + 1);
357 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
358 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
362 self.max_armorvalue += (save + take);
364 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
365 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
366 self.dmg_inflictor = inflictor;
368 float abot, vbot, awep;
369 abot = (IS_BOT_CLIENT(attacker));
370 vbot = (IS_BOT_CLIENT(self));
372 valid_damage_for_weaponstats = 0;
375 if(vbot || IS_REAL_CLIENT(self))
376 if(abot || IS_REAL_CLIENT(attacker))
377 if(attacker && self != attacker)
378 if(DIFF_TEAM(self, attacker))
380 if(DEATH_ISSPECIAL(deathtype))
381 awep = attacker.weapon;
383 awep = DEATH_WEAPONOF(deathtype);
384 valid_damage_for_weaponstats = 1;
387 if(valid_damage_for_weaponstats)
389 dh = dh - max(self.health, 0);
390 da = da - max(self.armorvalue, 0);
391 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
396 float defer_ClientKill_Now_TeamChange;
397 defer_ClientKill_Now_TeamChange = FALSE;
401 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
405 if(valid_damage_for_weaponstats)
406 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
408 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
409 if(sound_allowed(MSG_BROADCAST, attacker))
411 if(deathtype == DEATH_DROWN)
412 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
414 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
417 // get rid of kill indicator
418 if(self.killindicator)
420 remove(self.killindicator);
421 self.killindicator = world;
422 if(self.killindicator_teamchange)
423 defer_ClientKill_Now_TeamChange = TRUE;
425 if(self.classname == "body")
426 if(deathtype == DEATH_KILL)
428 // for the lemmings fans, a small harmless explosion
429 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
433 // print an obituary message
434 Obituary (attacker, inflictor, self, deathtype);
437 // increment frag counter for used weapon type
439 w = DEATH_WEAPONOF(deathtype);
441 if(accuracy_isgooddamage(attacker, self))
442 attacker.accuracy.(accuracy_frags[w-1]) += 1;
444 frag_attacker = attacker;
445 frag_inflictor = inflictor;
447 frag_deathtype = deathtype;
448 MUTATOR_CALLHOOK(PlayerDies);
450 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
452 RemoveGrapplingHook(self);
454 Portal_ClearAllLater(self);
456 if(IS_REAL_CLIENT(self))
458 self.fixangle = TRUE;
460 //WriteByte (MSG_ONE, SVC_SETANGLE);
461 //WriteAngle (MSG_ONE, self.v_angle_x);
462 //WriteAngle (MSG_ONE, self.v_angle_y);
463 //WriteAngle (MSG_ONE, 80);
466 if(defer_ClientKill_Now_TeamChange)
467 ClientKill_Now_TeamChange(); // can turn player into spectator
469 // player could have been miraculously resuscitated ;)
470 // e.g. players in freezetag get frozen, they don't really die
471 if(self.health >= 1 || !IS_PLAYER(self))
474 // when we get here, player actually dies
477 WaypointSprite_PlayerDead();
479 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
481 // become fully visible
482 self.alpha = default_player_alpha;
483 // make the corpse upright (not tilted)
487 self.avelocity = '0 0 0';
488 // view from the floor
489 self.view_ofs = '0 0 -8';
491 self.movetype = MOVETYPE_TOSS;
493 self.solid = SOLID_CORPSE;
494 self.ballistics_density = autocvar_g_ballistics_density_corpse;
495 // don't stick to the floor
496 self.flags &= ~FL_ONGROUND;
498 self.deadflag = DEAD_DYING;
499 // when to allow respawn
502 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
506 sdelay = 0; // no respawn delay in CTS
508 sdelay = autocvar_g_respawn_delay;
510 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
512 waves = autocvar_g_respawn_waves;
514 self.respawn_time = ceil((time + sdelay) / waves) * waves;
516 self.respawn_time = time + sdelay;
517 if(autocvar_g_respawn_delay_max > sdelay)
518 self.respawn_time_max = time + autocvar_g_respawn_delay_max;
520 self.respawn_time_max = self.respawn_time;
521 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
522 self.respawn_countdown = 10; // first number to count down from is 10
524 self.respawn_countdown = -1; // do not count down
526 if(g_cts || autocvar_g_forced_respawn)
527 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
529 self.death_time = time;
531 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, TRUE);
533 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, TRUE);
537 setsize(self, self.mins, self.maxs);
539 // set damage function to corpse damage
540 self.event_damage = PlayerCorpseDamage;
541 // call the corpse damage function just in case it wants to gib
542 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
543 // set up to fade out later
544 SUB_SetFade (self, time + 6 + random (), 1);
546 if(autocvar_sv_gentle > 0 || autocvar_ekg) {
548 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
551 // reset fields the weapons may use just in case
552 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
554 WEP_ACTION(j, WR_RESETPLAYER);
555 ATTACK_FINISHED_FOR(self, j) = 0;
560 .float muted; // to be used by prvm_edictset server playernumber muted 1
561 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
562 // message "": do not say, just test flood control
568 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr;
570 var .float flood_field;
573 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
575 if(!teamsay && !privatesay)
576 if(substring(msgin, 0, 1) == " ")
577 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
579 msgin = formatmessage(msgin);
581 if (!IS_PLAYER(source))
582 colorstr = "^0"; // black for spectators
584 colorstr = Team_ColorCode(source.team);
591 if(intermission_running)
595 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
598 * using bprint solves this... me stupid
599 // how can we prevent the message from appearing in a listen server?
600 // for now, just give "say" back and only handle say_team
603 clientcommand(self, strcat("say ", msgin));
608 if(autocvar_g_chat_teamcolors)
609 namestr = playername(source);
611 namestr = source.netname;
617 msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
618 privatemsgprefixlen = strlen(msgstr);
619 msgstr = strcat(msgstr, msgin);
620 cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
621 if(autocvar_g_chat_teamcolors)
622 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
624 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
628 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
629 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
633 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
636 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
640 msgstr = cmsgstr = "";
644 fullcmsgstr = cmsgstr;
648 flood_field = floodcontrol_chat;
657 flood_spl = autocvar_g_chat_flood_spl_tell;
658 flood_burst = autocvar_g_chat_flood_burst_tell;
659 flood_lmax = autocvar_g_chat_flood_lmax_tell;
660 flood_field = floodcontrol_chattell;
664 flood_spl = autocvar_g_chat_flood_spl_team;
665 flood_burst = autocvar_g_chat_flood_burst_team;
666 flood_lmax = autocvar_g_chat_flood_lmax_team;
667 flood_field = floodcontrol_chatteam;
671 flood_spl = autocvar_g_chat_flood_spl;
672 flood_burst = autocvar_g_chat_flood_burst;
673 flood_lmax = autocvar_g_chat_flood_lmax;
674 flood_field = floodcontrol_chat;
676 flood_burst = max(0, flood_burst - 1);
677 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
679 // do flood control for the default line size
682 getWrappedLine_remaining = msgstr;
685 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
687 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
690 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
692 if(getWrappedLine_remaining != "")
694 msgstr = strcat(msgstr, "\n");
698 if(time >= source.flood_field)
700 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
710 if(time >= source.flood_field)
711 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
716 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
717 source.flood_field = flood = 0;
720 if(flood == 2) // cannot happen for empty msgstr
722 if(autocvar_g_chat_flood_notify_flooder)
724 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
729 sourcemsgstr = fullmsgstr;
730 sourcecmsgstr = fullcmsgstr;
736 sourcemsgstr = msgstr;
737 sourcecmsgstr = cmsgstr;
741 if (!IS_PLAYER(source))
743 if (!intermission_running)
744 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
745 teamsay = -1; // spectators
749 print("NOTE: ", playername(source), "^7 is flooding.\n");
751 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
753 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
757 // always fake the message
762 if(autocvar_g_chat_flood_notify_flooder)
764 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
775 if(sourcemsgstr != "" && ret != 0)
777 if(ret < 0) // faked message, because the player is muted
779 sprint(source, sourcemsgstr);
780 if(sourcecmsgstr != "" && !privatesay)
781 centerprint(source, sourcecmsgstr);
783 else if(privatesay) // private message, between 2 people only
785 sprint(source, sourcemsgstr);
786 sprint(privatesay, msgstr);
787 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
789 centerprint(privatesay, cmsgstr);
791 else if(teamsay > 0) // team message, only sent to team mates
793 sprint(source, sourcemsgstr);
794 dedicated_print(msgstr); // send to server console too
795 if(sourcecmsgstr != "")
796 centerprint(source, sourcecmsgstr);
797 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
800 sprint(head, msgstr);
802 centerprint(head, cmsgstr);
805 else if(teamsay < 0) // spectator message, only sent to spectators
807 sprint(source, sourcemsgstr);
808 dedicated_print(msgstr); // send to server console too
809 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
811 sprint(head, msgstr);
813 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
815 sprint(source, sourcemsgstr);
816 dedicated_print(msgstr); // send to server console too
817 FOR_EACH_REALCLIENT(head)
819 sprint(head, msgstr);
822 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
828 float GetVoiceMessageVoiceType(string type)
831 return VOICETYPE_TAUNT;
832 if(type == "teamshoot")
833 return VOICETYPE_LASTATTACKER;
834 return VOICETYPE_TEAMRADIO;
837 string allvoicesamples;
838 .string GetVoiceMessageSampleField(string type)
840 GetPlayerSoundSampleField_notFound = 0;
843 #define _VOICEMSG(m) case #m: return playersound_##m;
847 GetPlayerSoundSampleField_notFound = 1;
848 return playersound_taunt;
851 .string GetPlayerSoundSampleField(string type)
853 GetPlayerSoundSampleField_notFound = 0;
856 #define _VOICEMSG(m) case #m: return playersound_##m;
860 GetPlayerSoundSampleField_notFound = 1;
861 return playersound_taunt;
864 void PrecacheGlobalSound(string samplestring)
867 tokenize_console(samplestring);
871 for(i = 1; i <= n; ++i)
872 precache_sound(strcat(argv(0), ftos(i), ".wav"));
876 precache_sound(strcat(argv(0), ".wav"));
880 void PrecachePlayerSounds(string f)
884 fh = fopen(f, FILE_READ);
887 while((s = fgets(fh)))
889 if(tokenize_console(s) != 3)
891 dprint("Invalid sound info line: ", s, "\n");
894 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
898 if (!allvoicesamples)
900 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
903 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
907 void ClearPlayerSounds()
909 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
915 float LoadPlayerSounds(string f, float first)
920 fh = fopen(f, FILE_READ);
923 dprint("Player sound file not found: ", f, "\n");
926 while((s = fgets(fh)))
928 if(tokenize_console(s) != 3)
930 field = GetPlayerSoundSampleField(argv(0));
931 if(GetPlayerSoundSampleField_notFound)
932 field = GetVoiceMessageSampleField(argv(0));
933 if(GetPlayerSoundSampleField_notFound)
936 strunzone(self.field);
937 self.field = strzone(strcat(argv(1), " ", argv(2)));
943 .float modelindex_for_playersound;
944 .float skin_for_playersound;
945 void UpdatePlayerSounds()
947 if(self.modelindex == self.modelindex_for_playersound)
948 if(self.skin == self.skin_for_playersound)
950 self.modelindex_for_playersound = self.modelindex;
951 self.skin_for_playersound = self.skin;
953 LoadPlayerSounds("sound/player/default.sounds", 1);
954 if(!autocvar_g_debug_defaultsounds)
955 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
956 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
959 void FakeGlobalSound(string sample, float chan, float voicetype)
967 tokenize_console(sample);
970 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
972 sample = strcat(argv(0), ".wav"); // randomization
976 case VOICETYPE_LASTATTACKER_ONLY:
978 case VOICETYPE_LASTATTACKER:
982 if(IS_REAL_CLIENT(msg_entity))
983 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
986 case VOICETYPE_TEAMRADIO:
988 if(msg_entity.cvar_cl_voice_directional == 1)
989 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
991 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
993 case VOICETYPE_AUTOTAUNT:
998 if(autocvar_sv_gentle)
1000 tauntrand = random();
1002 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1004 if (msg_entity.cvar_cl_voice_directional >= 1)
1005 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1007 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1010 case VOICETYPE_TAUNT:
1012 if(self.deadflag == DEAD_NO)
1013 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1016 if(autocvar_sv_gentle)
1019 if (msg_entity.cvar_cl_voice_directional >= 1)
1020 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1022 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1024 case VOICETYPE_PLAYERSOUND:
1026 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1029 backtrace("Invalid voice type!");
1034 void GlobalSound(string sample, float chan, float voicetype)
1042 tokenize_console(sample);
1045 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1047 sample = strcat(argv(0), ".wav"); // randomization
1051 case VOICETYPE_LASTATTACKER_ONLY:
1054 msg_entity = self.pusher;
1055 if(IS_REAL_CLIENT(msg_entity))
1057 if(msg_entity.cvar_cl_voice_directional == 1)
1058 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1060 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1064 case VOICETYPE_LASTATTACKER:
1067 msg_entity = self.pusher;
1068 if(IS_REAL_CLIENT(msg_entity))
1070 if(msg_entity.cvar_cl_voice_directional == 1)
1071 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1073 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1076 if(IS_REAL_CLIENT(msg_entity))
1077 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1080 case VOICETYPE_TEAMRADIO:
1081 FOR_EACH_REALCLIENT(msg_entity)
1082 if(!teamplay || msg_entity.team == self.team)
1084 if(msg_entity.cvar_cl_voice_directional == 1)
1085 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1087 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1090 case VOICETYPE_AUTOTAUNT:
1095 if(autocvar_sv_gentle)
1097 tauntrand = random();
1098 FOR_EACH_REALCLIENT(msg_entity)
1099 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1101 if (msg_entity.cvar_cl_voice_directional >= 1)
1102 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1104 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1107 case VOICETYPE_TAUNT:
1109 if(self.deadflag == DEAD_NO)
1110 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1113 if(autocvar_sv_gentle)
1115 FOR_EACH_REALCLIENT(msg_entity)
1117 if (msg_entity.cvar_cl_voice_directional >= 1)
1118 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1120 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1123 case VOICETYPE_PLAYERSOUND:
1124 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1127 backtrace("Invalid voice type!");
1132 void PlayerSound(.string samplefield, float chan, float voicetype)
1134 GlobalSound(self.samplefield, chan, voicetype);
1137 void VoiceMessage(string type, string msg)
1140 float voicetype, ownteam;
1142 sample = GetVoiceMessageSampleField(type);
1144 if(GetPlayerSoundSampleField_notFound)
1146 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1150 voicetype = GetVoiceMessageVoiceType(type);
1151 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1153 flood = Say(self, ownteam, world, msg, 1);
1156 GlobalSound(self.sample, CH_VOICE, voicetype);
1158 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1161 void MoveToTeam(entity client, float team_colour, float type)
1163 float lockteams_backup;
1165 lockteams_backup = lockteams; // backup any team lock
1167 lockteams = 0; // disable locked teams
1169 TeamchangeFrags(client); // move the players frags
1170 SetPlayerColors(client, team_colour - 1); // set the players colour
1171 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1173 lockteams = lockteams_backup; // restore the team lock
1175 LogTeamchange(client.playerid, client.team, type);