1 float weaponstats_buffer;
3 void WeaponStats_Init()
5 if(autocvar_sv_weaponstats_file != "")
6 weaponstats_buffer = buf_create();
8 weaponstats_buffer = -1;
11 #define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot))
13 void WeaponStats_ready(entity fh, entity pass, float status)
15 float i, j, n, ibot, jbot, idx;
20 case URL_READY_CANWRITE:
22 prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
23 url_fputs(fh, "#begin statsfile\n");
24 url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
26 url_fputs(fh, strcat("#version ", WATERMARK, "\n"));
28 url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_purechanges)), "\n"));
29 url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n"));
30 n = tokenizebyseparator(cvar_purechanges, "\n");
31 for(i = 0; i < n; ++i)
32 url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n"));
33 for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot)
34 for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot)
36 idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot);
37 v = stov(bufstr_get(weaponstats_buffer, idx));
40 //vector is: kills hits damage
41 url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
42 url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
45 url_fputs(fh, "#end\n\n");
48 case URL_READY_CANREAD:
49 // url_fclose is processing, we got a response for writing the data
50 // this must come from HTTP
51 print("Got response from weapon stats server:\n");
52 while((s = url_fgets(fh)))
54 print("End of response.\n");
57 case URL_READY_CLOSED:
58 // url_fclose has finished
59 print("Weapon stats written\n");
60 buf_del(weaponstats_buffer);
61 weaponstats_buffer = -1;
65 print("Weapon stats writing failed: ", ftos(status), "\n");
66 buf_del(weaponstats_buffer);
67 weaponstats_buffer = -1;
72 void WeaponStats_Shutdown()
74 if(weaponstats_buffer < 0)
76 if(autocvar_sv_weaponstats_file != "")
78 url_multi_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world);
82 buf_del(weaponstats_buffer);
83 weaponstats_buffer = -1;
87 void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item)
90 if(weaponstats_buffer < 0)
92 if(awep < WEP_FIRST || vwep < WEP_FIRST)
94 if(awep > WEP_LAST || vwep > WEP_LAST)
96 idx = WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot);
97 bufstr_set(weaponstats_buffer, idx, vtos(stov(bufstr_get(weaponstats_buffer, idx)) + item));
99 void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage)
102 error("negative damage?");
103 WeaponStats_LogItem(awep, abot, vwep, vbot, '0 0 1' * damage + '0 1 0');
105 void WeaponStats_LogKill(float awep, float abot, float vwep, float vbot)
107 WeaponStats_LogItem(awep, abot, vwep, vbot, '1 0 0');
114 .float CopyBody_nextthink;
115 .void(void) CopyBody_think;
116 void CopyBody_Think(void)
118 if(self.CopyBody_nextthink && time > self.CopyBody_nextthink)
120 self.CopyBody_think();
123 self.CopyBody_nextthink = self.nextthink;
124 self.CopyBody_think = self.think;
125 self.think = CopyBody_Think;
127 CSQCMODEL_AUTOUPDATE();
128 self.nextthink = time;
130 void CopyBody(float keepvelocity)
133 if (self.effects & EF_NODRAW)
137 self.enemy = oldself;
138 self.lip = oldself.lip;
139 self.colormap = oldself.colormap;
140 self.iscreature = oldself.iscreature;
141 self.teleportable = oldself.teleportable;
142 self.damagedbycontents = oldself.damagedbycontents;
143 self.angles = oldself.angles;
144 self.avelocity = oldself.avelocity;
145 self.classname = "body";
146 self.damageforcescale = oldself.damageforcescale;
147 self.effects = oldself.effects;
148 self.glowmod = oldself.glowmod;
149 self.event_damage = oldself.event_damage;
150 self.anim_state = oldself.anim_state;
151 self.anim_time = oldself.anim_time;
152 self.anim_lower_action = oldself.anim_lower_action;
153 self.anim_lower_time = oldself.anim_lower_time;
154 self.anim_upper_action = oldself.anim_upper_action;
155 self.anim_upper_time = oldself.anim_upper_time;
156 self.anim_implicit_state = oldself.anim_implicit_state;
157 self.anim_implicit_time = oldself.anim_implicit_time;
158 self.anim_lower_implicit_action = oldself.anim_lower_implicit_action;
159 self.anim_lower_implicit_time = oldself.anim_lower_implicit_time;
160 self.anim_upper_implicit_action = oldself.anim_upper_implicit_action;
161 self.anim_upper_implicit_time = oldself.anim_upper_implicit_time;
162 self.dphitcontentsmask = oldself.dphitcontentsmask;
163 self.death_time = oldself.death_time;
164 self.pain_finished = oldself.pain_finished;
165 self.health = oldself.health;
166 self.armorvalue = oldself.armorvalue;
167 self.armortype = oldself.armortype;
168 self.model = oldself.model;
169 self.modelindex = oldself.modelindex;
170 self.skin = oldself.skin;
171 self.species = oldself.species;
172 self.movetype = oldself.movetype;
173 self.solid = oldself.solid;
174 self.ballistics_density = oldself.ballistics_density;
175 self.takedamage = oldself.takedamage;
176 self.customizeentityforclient = oldself.customizeentityforclient;
177 self.uncustomizeentityforclient = oldself.uncustomizeentityforclient;
178 self.uncustomizeentityforclient_set = oldself.uncustomizeentityforclient_set;
179 if (keepvelocity == 1)
180 self.velocity = oldself.velocity;
181 self.oldvelocity = self.velocity;
182 self.alpha = oldself.alpha;
183 self.fade_time = oldself.fade_time;
184 self.fade_rate = oldself.fade_rate;
185 //self.weapon = oldself.weapon;
186 setorigin(self, oldself.origin);
187 setsize(self, oldself.mins, oldself.maxs);
188 self.prevorigin = oldself.origin;
189 self.reset = SUB_Remove;
191 Drag_MoveDrag(oldself, self);
193 if(self.colormap <= maxclients && self.colormap > 0)
194 self.colormap = 1024 + oldself.clientcolors;
196 CSQCMODEL_AUTOINIT();
197 self.CopyBody_nextthink = oldself.nextthink;
198 self.CopyBody_think = oldself.think;
199 self.nextthink = time;
200 self.think = CopyBody_Think;
201 // "bake" the current animation frame for clones (they don't get clientside animation)
202 animdecide_setframes(self, FALSE, frame, frame1time, frame2, frame2time);
207 float player_getspecies()
210 get_model_parameters(self.model, self.skin);
211 s = get_model_parameters_species;
212 get_model_parameters(string_null, 0);
214 return SPECIES_HUMAN;
218 void player_setupanimsformodel()
220 // load animation info
221 animdecide_init(self);
222 animdecide_setstate(self, 0, FALSE);
225 void player_anim (void)
227 float deadbits = (self.anim_state & (ANIMSTATE_DEAD1 | ANIMSTATE_DEAD2));
228 if(self.deadflag && !deadbits)
230 deadbits = ANIMSTATE_DEAD1;
232 deadbits = ANIMSTATE_DEAD2;
233 float animbits = deadbits;
234 if(self.freezetag_frozen)
235 animbits |= ANIMSTATE_FROZEN;
237 animbits |= ANIMSTATE_DUCK;
238 animdecide_setstate(self, animbits, FALSE);
239 animdecide_setimplicitstate(self, (self.flags & FL_ONGROUND));
241 if (self.weaponentity)
243 updateanim(self.weaponentity);
244 if (!self.weaponentity.animstate_override)
245 setanim(self.weaponentity, self.weaponentity.anim_idle, TRUE, FALSE, FALSE);
249 void SpawnThrownWeapon (vector org, float w)
251 if(self.weapons & WepSet_FromWeapon(self.weapon))
252 if(W_IsWeaponThrowable(self.weapon))
253 W_ThrowNewWeapon(self, self.weapon, FALSE, org, randomvec() * 125 + '0 0 200');
256 void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
260 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
262 // damage resistance (ignore most of the damage from a bullet or similar)
263 damage = max(damage - 5, 1);
265 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
269 if(sound_allowed(MSG_BROADCAST, attacker))
272 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
274 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
276 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM);
280 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
282 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
284 if (!(self.flags & FL_GODMODE))
286 self.armorvalue = self.armorvalue - save;
287 self.health = self.health - take;
288 // pause regeneration for 5 seconds
289 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
291 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
292 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
293 self.dmg_inflictor = inflictor;
295 if (self.health <= -autocvar_sv_gibhealth && self.alpha >= 0)
297 // don't use any animations as a gib
299 // view just above the floor
300 self.view_ofs = '0 0 4';
302 Violence_GibSplash(self, 1, 1, attacker);
304 self.solid = SOLID_NOT; // restore later
305 self.takedamage = DAMAGE_NO; // restore later
306 self.damagedbycontents = FALSE;
310 void ClientKill_Now_TeamChange();
312 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
314 float take, save, waves, sdelay, dh, da, j;
316 float valid_damage_for_weaponstats;
319 dh = max(self.health, 0);
320 da = max(self.armorvalue, 0);
322 if(!DEATH_ISSPECIAL(deathtype))
324 damage *= sqrt(bound(1.0, self.cvar_cl_handicap, 100.0));
326 damage /= sqrt(bound(1.0, attacker.cvar_cl_handicap, 100.0));
329 if(DEATH_ISWEAPON(deathtype, WEP_TUBA))
331 // tuba causes blood to come out of the ears
336 ear1_z += 0.125 * self.view_ofs_z + 0.875 * self.maxs_z; // 7/8
338 makevectors(self.angles);
339 ear1 += v_right * -10;
340 ear2 += v_right * +10;
341 d = inflictor.origin - self.origin;
343 f = (d * v_right) / vlen(d); // this is cos of angle of d and v_right!
345 f = 0; // Assum ecenter.
346 force = v_right * vlen(force);
347 Violence_GibSplash_At(ear1, force * -1, 2, bound(0, damage, 25) / 2 * (0.5 - 0.5 * f), self, attacker);
348 Violence_GibSplash_At(ear2, force, 2, bound(0, damage, 25) / 2 * (0.5 + 0.5 * f), self, attacker);
357 // force is already good
361 Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
364 v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, deathtype, damage);
370 // don't reset pushltime for self damage as it may be an attempt to
371 // escape a lava pit or similar
372 //self.pushltime = 0;
375 else if(IS_PLAYER(attacker))
377 self.pusher = attacker;
378 self.pushltime = time + autocvar_g_maxpushtime;
379 self.istypefrag = self.BUTTON_CHAT;
381 else if(time < self.pushltime)
383 attacker = self.pusher;
384 self.pushltime = max(self.pushltime, time + 0.6);
392 frag_inflictor = inflictor;
393 frag_attacker = attacker;
395 frag_damage = damage;
398 damage_force = force;
399 MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
400 take = bound(0, damage_take, self.health);
401 save = bound(0, damage_save, self.armorvalue);
402 excess = max(0, damage - take - save);
404 if(sound_allowed(MSG_BROADCAST, attacker))
407 sound (self, CH_SHOTS, "misc/armorimpact.wav", VOL_BASE, ATTEN_NORM);
409 sound (self, CH_SHOTS, "misc/bodyimpact2.wav", VOL_BASE, ATTEN_NORM);
411 sound (self, CH_SHOTS, "misc/bodyimpact1.wav", VOL_BASE, ATTEN_NORM); // FIXME possibly remove them?
415 Violence_GibSplash_At(hitloc, force * -0.1, 3, 1, self, attacker);
417 Violence_GibSplash_At(hitloc, force * -0.2, 3, 1, self, attacker);
419 if (time >= self.spawnshieldtime)
421 if (!(self.flags & FL_GODMODE))
423 self.armorvalue = self.armorvalue - save;
424 self.health = self.health - take;
425 // pause regeneration for 5 seconds
427 self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
429 if (time > self.pain_finished) //Don't switch pain sequences like crazy
431 self.pain_finished = time + 0.5; //Supajoe
433 if(autocvar_sv_gentle < 1) {
434 if(self.classname != "body") // pain anim is BORKED on our ZYMs, FIXME remove this once we have good models
436 if (!self.animstate_override)
439 animdecide_setaction(self, ANIMACTION_PAIN1, TRUE);
441 animdecide_setaction(self, ANIMACTION_PAIN2, TRUE);
445 if(sound_allowed(MSG_BROADCAST, attacker))
446 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
448 // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
450 if(deathtype == DEATH_FALL)
451 PlayerSound(playersound_fall, CH_PAIN, VOICETYPE_PLAYERSOUND);
452 else if(self.health > 75) // TODO make a "gentle" version?
453 PlayerSound(playersound_pain100, CH_PAIN, VOICETYPE_PLAYERSOUND);
454 else if(self.health > 50)
455 PlayerSound(playersound_pain75, CH_PAIN, VOICETYPE_PLAYERSOUND);
456 else if(self.health > 25)
457 PlayerSound(playersound_pain50, CH_PAIN, VOICETYPE_PLAYERSOUND);
459 PlayerSound(playersound_pain25, CH_PAIN, VOICETYPE_PLAYERSOUND);
463 // throw off bot aim temporarily
465 shake = damage * 5 / (bound(0,skill,100) + 1);
466 self.v_angle_x = self.v_angle_x + (random() * 2 - 1) * shake;
467 self.v_angle_y = self.v_angle_y + (random() * 2 - 1) * shake;
471 self.max_armorvalue += (save + take);
473 self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
474 self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
475 self.dmg_inflictor = inflictor;
477 float abot, vbot, awep;
478 abot = (IS_BOT_CLIENT(attacker));
479 vbot = (IS_BOT_CLIENT(self));
481 valid_damage_for_weaponstats = 0;
484 if(vbot || IS_REAL_CLIENT(self))
485 if(abot || IS_REAL_CLIENT(attacker))
486 if(attacker && self != attacker)
487 if(DIFF_TEAM(self, attacker))
489 if(DEATH_ISSPECIAL(deathtype))
490 awep = attacker.weapon;
492 awep = DEATH_WEAPONOF(deathtype);
493 valid_damage_for_weaponstats = 1;
496 if(valid_damage_for_weaponstats)
498 dh = dh - max(self.health, 0);
499 da = da - max(self.armorvalue, 0);
500 WeaponStats_LogDamage(awep, abot, self.weapon, vbot, dh + da);
505 float defer_ClientKill_Now_TeamChange;
506 defer_ClientKill_Now_TeamChange = FALSE;
510 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
514 if(valid_damage_for_weaponstats)
515 WeaponStats_LogKill(awep, abot, self.weapon, vbot);
517 if(autocvar_sv_gentle < 1) // TODO make a "gentle" version?
518 if(sound_allowed(MSG_BROADCAST, attacker))
520 if(deathtype == DEATH_DROWN)
521 PlayerSound(playersound_drown, CH_PAIN, VOICETYPE_PLAYERSOUND);
523 PlayerSound(playersound_death, CH_PAIN, VOICETYPE_PLAYERSOUND);
526 // get rid of kill indicator
527 if(self.killindicator)
529 remove(self.killindicator);
530 self.killindicator = world;
531 if(self.killindicator_teamchange)
532 defer_ClientKill_Now_TeamChange = TRUE;
534 if(self.classname == "body")
535 if(deathtype == DEATH_KILL)
537 // for the lemmings fans, a small harmless explosion
538 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
542 // print an obituary message
543 Obituary (attacker, inflictor, self, deathtype);
546 // increment frag counter for used weapon type
548 w = DEATH_WEAPONOF(deathtype);
550 if(accuracy_isgooddamage(attacker, self))
551 attacker.accuracy.(accuracy_frags[w-1]) += 1;
553 frag_attacker = attacker;
554 frag_inflictor = inflictor;
556 frag_deathtype = deathtype;
557 MUTATOR_CALLHOOK(PlayerDies);
559 WEP_ACTION(self.weapon, WR_PLAYERDEATH);
561 RemoveGrapplingHook(self);
563 Portal_ClearAllLater(self);
565 if(IS_REAL_CLIENT(self))
567 self.fixangle = TRUE;
569 //WriteByte (MSG_ONE, SVC_SETANGLE);
570 //WriteAngle (MSG_ONE, self.v_angle_x);
571 //WriteAngle (MSG_ONE, self.v_angle_y);
572 //WriteAngle (MSG_ONE, 80);
575 if(defer_ClientKill_Now_TeamChange)
576 ClientKill_Now_TeamChange(); // can turn player into spectator
578 // player could have been miraculously resuscitated ;)
579 // e.g. players in freezetag get frozen, they don't really die
580 if(self.health >= 1 || !IS_PLAYER(self))
583 // when we get here, player actually dies
586 WaypointSprite_PlayerDead();
588 SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
590 // become fully visible
591 self.alpha = default_player_alpha;
592 // make the corpse upright (not tilted)
596 self.avelocity = '0 0 0';
597 // view from the floor
598 self.view_ofs = '0 0 -8';
600 self.movetype = MOVETYPE_TOSS;
602 self.solid = SOLID_CORPSE;
603 self.ballistics_density = autocvar_g_ballistics_density_corpse;
604 // don't stick to the floor
605 self.flags &= ~FL_ONGROUND;
607 self.deadflag = DEAD_DYING;
608 // when to allow respawn
611 sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
615 sdelay = 0; // no respawn delay in CTS
617 sdelay = autocvar_g_respawn_delay;
619 waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
621 waves = autocvar_g_respawn_waves;
623 self.respawn_time = ceil((time + sdelay) / waves) * waves;
625 self.respawn_time = time + sdelay;
626 if(autocvar_g_respawn_delay_max > sdelay)
627 self.respawn_time_max = time + autocvar_g_respawn_delay_max;
629 self.respawn_time_max = self.respawn_time;
630 if((sdelay + waves >= 5.0) && (self.respawn_time - time > 1.75))
631 self.respawn_countdown = 10; // first number to count down from is 10
633 self.respawn_countdown = -1; // do not count down
635 if(g_cts || autocvar_g_forced_respawn)
636 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
638 self.death_time = time;
640 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD1, TRUE);
642 animdecide_setstate(self, self.anim_state | ANIMSTATE_DEAD2, TRUE);
646 setsize(self, self.mins, self.maxs);
648 // set damage function to corpse damage
649 self.event_damage = PlayerCorpseDamage;
650 // call the corpse damage function just in case it wants to gib
651 self.event_damage(inflictor, attacker, excess, deathtype, hitloc, force);
652 // set up to fade out later
653 SUB_SetFade (self, time + 6 + random (), 1);
655 if(autocvar_sv_gentle > 0 || autocvar_ekg) {
657 PlayerCorpseDamage (inflictor, attacker, autocvar_sv_gibhealth+1.0, deathtype, hitloc, force);
660 // reset fields the weapons may use just in case
661 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
663 WEP_ACTION(j, WR_RESETPLAYER);
664 ATTACK_FINISHED_FOR(self, j) = 0;
669 .float muted; // to be used by prvm_edictset server playernumber muted 1
670 float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
671 // message "": do not say, just test flood control
677 string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr;
679 var .float flood_field;
682 string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
684 if(!teamsay && !privatesay)
685 if(substring(msgin, 0, 1) == " ")
686 msgin = substring(msgin, 1, strlen(msgin) - 1); // work around DP say bug (say_team does not have this!)
688 msgin = formatmessage(msgin);
690 if (!IS_PLAYER(source))
691 colorstr = "^0"; // black for spectators
693 colorstr = Team_ColorCode(source.team);
700 if(intermission_running)
704 msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
707 * using bprint solves this... me stupid
708 // how can we prevent the message from appearing in a listen server?
709 // for now, just give "say" back and only handle say_team
712 clientcommand(self, strcat("say ", msgin));
717 if(autocvar_g_chat_teamcolors)
718 namestr = playername(source);
720 namestr = source.netname;
726 msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
727 privatemsgprefixlen = strlen(msgstr);
728 msgstr = strcat(msgstr, msgin);
729 cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
730 if(autocvar_g_chat_teamcolors)
731 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
733 privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
737 msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
738 cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
742 msgstr = strcat("\{1}", namestr, "^7: ", msgin);
745 msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
749 msgstr = cmsgstr = "";
753 fullcmsgstr = cmsgstr;
757 flood_field = floodcontrol_chat;
766 flood_spl = autocvar_g_chat_flood_spl_tell;
767 flood_burst = autocvar_g_chat_flood_burst_tell;
768 flood_lmax = autocvar_g_chat_flood_lmax_tell;
769 flood_field = floodcontrol_chattell;
773 flood_spl = autocvar_g_chat_flood_spl_team;
774 flood_burst = autocvar_g_chat_flood_burst_team;
775 flood_lmax = autocvar_g_chat_flood_lmax_team;
776 flood_field = floodcontrol_chatteam;
780 flood_spl = autocvar_g_chat_flood_spl;
781 flood_burst = autocvar_g_chat_flood_burst;
782 flood_lmax = autocvar_g_chat_flood_lmax;
783 flood_field = floodcontrol_chat;
785 flood_burst = max(0, flood_burst - 1);
786 // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
788 // do flood control for the default line size
791 getWrappedLine_remaining = msgstr;
794 while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
796 msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
799 msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
801 if(getWrappedLine_remaining != "")
803 msgstr = strcat(msgstr, "\n");
807 if(time >= source.flood_field)
809 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
819 if(time >= source.flood_field)
820 source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
825 if (timeout_status == TIMEOUT_ACTIVE) // when game is paused, no flood protection
826 source.flood_field = flood = 0;
829 if(flood == 2) // cannot happen for empty msgstr
831 if(autocvar_g_chat_flood_notify_flooder)
833 sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
838 sourcemsgstr = fullmsgstr;
839 sourcecmsgstr = fullcmsgstr;
845 sourcemsgstr = msgstr;
846 sourcecmsgstr = cmsgstr;
850 if (!IS_PLAYER(source))
852 if (!intermission_running)
853 if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || gameover)))
854 teamsay = -1; // spectators
858 print("NOTE: ", playername(source), "^7 is flooding.\n");
860 // build sourcemsgstr by cutting off a prefix and replacing it by the other one
862 sourcemsgstr = strcat(privatemsgprefix, substring(sourcemsgstr, privatemsgprefixlen, -1));
866 // always fake the message
871 if(autocvar_g_chat_flood_notify_flooder)
873 sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
884 if(sourcemsgstr != "" && ret != 0)
886 if(ret < 0) // faked message, because the player is muted
888 sprint(source, sourcemsgstr);
889 if(sourcecmsgstr != "" && !privatesay)
890 centerprint(source, sourcecmsgstr);
892 else if(privatesay) // private message, between 2 people only
894 sprint(source, sourcemsgstr);
895 sprint(privatesay, msgstr);
896 if (!autocvar_g_chat_tellprivacy) { dedicated_print(msgstr); } // send to server console too if "tellprivacy" is disabled
898 centerprint(privatesay, cmsgstr);
900 else if(teamsay > 0) // team message, only sent to team mates
902 sprint(source, sourcemsgstr);
903 dedicated_print(msgstr); // send to server console too
904 if(sourcecmsgstr != "")
905 centerprint(source, sourcecmsgstr);
906 FOR_EACH_REALPLAYER(head) if(head.team == source.team)
909 sprint(head, msgstr);
911 centerprint(head, cmsgstr);
914 else if(teamsay < 0) // spectator message, only sent to spectators
916 sprint(source, sourcemsgstr);
917 dedicated_print(msgstr); // send to server console too
918 FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
920 sprint(head, msgstr);
922 else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
924 sprint(source, sourcemsgstr);
925 dedicated_print(msgstr); // send to server console too
926 FOR_EACH_REALCLIENT(head)
928 sprint(head, msgstr);
931 bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
937 float GetVoiceMessageVoiceType(string type)
940 return VOICETYPE_TAUNT;
941 if(type == "teamshoot")
942 return VOICETYPE_LASTATTACKER;
943 return VOICETYPE_TEAMRADIO;
946 string allvoicesamples;
947 .string GetVoiceMessageSampleField(string type)
949 GetPlayerSoundSampleField_notFound = 0;
952 #define _VOICEMSG(m) case #m: return playersound_##m;
956 GetPlayerSoundSampleField_notFound = 1;
957 return playersound_taunt;
960 .string GetPlayerSoundSampleField(string type)
962 GetPlayerSoundSampleField_notFound = 0;
965 #define _VOICEMSG(m) case #m: return playersound_##m;
969 GetPlayerSoundSampleField_notFound = 1;
970 return playersound_taunt;
973 void PrecacheGlobalSound(string samplestring)
976 tokenize_console(samplestring);
980 for(i = 1; i <= n; ++i)
981 precache_sound(strcat(argv(0), ftos(i), ".wav"));
985 precache_sound(strcat(argv(0), ".wav"));
989 void PrecachePlayerSounds(string f)
993 fh = fopen(f, FILE_READ);
996 while((s = fgets(fh)))
998 if(tokenize_console(s) != 3)
1000 dprint("Invalid sound info line: ", s, "\n");
1003 PrecacheGlobalSound(strcat(argv(1), " ", argv(2)));
1007 if (!allvoicesamples)
1009 #define _VOICEMSG(m) allvoicesamples = strcat(allvoicesamples, " ", #m);
1012 allvoicesamples = strzone(substring(allvoicesamples, 1, strlen(allvoicesamples) - 1));
1016 void ClearPlayerSounds()
1018 #define _VOICEMSG(m) if(self.playersound_##m) { strunzone(self.playersound_##m); self.playersound_##m = string_null; }
1024 float LoadPlayerSounds(string f, float first)
1029 fh = fopen(f, FILE_READ);
1032 dprint("Player sound file not found: ", f, "\n");
1035 while((s = fgets(fh)))
1037 if(tokenize_console(s) != 3)
1039 field = GetPlayerSoundSampleField(argv(0));
1040 if(GetPlayerSoundSampleField_notFound)
1041 field = GetVoiceMessageSampleField(argv(0));
1042 if(GetPlayerSoundSampleField_notFound)
1045 strunzone(self.field);
1046 self.field = strzone(strcat(argv(1), " ", argv(2)));
1052 .float modelindex_for_playersound;
1053 .float skin_for_playersound;
1054 void UpdatePlayerSounds()
1056 if(self.modelindex == self.modelindex_for_playersound)
1057 if(self.skin == self.skin_for_playersound)
1059 self.modelindex_for_playersound = self.modelindex;
1060 self.skin_for_playersound = self.skin;
1061 ClearPlayerSounds();
1062 LoadPlayerSounds("sound/player/default.sounds", 1);
1063 if(!autocvar_g_debug_defaultsounds)
1064 if(!LoadPlayerSounds(get_model_datafilename(self.model, self.skin, "sounds"), 0))
1065 LoadPlayerSounds(get_model_datafilename(self.model, 0, "sounds"), 0);
1068 void FakeGlobalSound(string sample, float chan, float voicetype)
1076 tokenize_console(sample);
1079 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1081 sample = strcat(argv(0), ".wav"); // randomization
1085 case VOICETYPE_LASTATTACKER_ONLY:
1087 case VOICETYPE_LASTATTACKER:
1091 if(IS_REAL_CLIENT(msg_entity))
1092 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1095 case VOICETYPE_TEAMRADIO:
1097 if(msg_entity.cvar_cl_voice_directional == 1)
1098 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1100 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1102 case VOICETYPE_AUTOTAUNT:
1107 if(autocvar_sv_gentle)
1109 tauntrand = random();
1111 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1113 if (msg_entity.cvar_cl_voice_directional >= 1)
1114 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1116 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1119 case VOICETYPE_TAUNT:
1121 if(self.deadflag == DEAD_NO)
1122 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1125 if(autocvar_sv_gentle)
1128 if (msg_entity.cvar_cl_voice_directional >= 1)
1129 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1131 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1133 case VOICETYPE_PLAYERSOUND:
1135 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NORM);
1138 backtrace("Invalid voice type!");
1143 void GlobalSound(string sample, float chan, float voicetype)
1151 tokenize_console(sample);
1154 sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
1156 sample = strcat(argv(0), ".wav"); // randomization
1160 case VOICETYPE_LASTATTACKER_ONLY:
1163 msg_entity = self.pusher;
1164 if(IS_REAL_CLIENT(msg_entity))
1166 if(msg_entity.cvar_cl_voice_directional == 1)
1167 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1169 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1173 case VOICETYPE_LASTATTACKER:
1176 msg_entity = self.pusher;
1177 if(IS_REAL_CLIENT(msg_entity))
1179 if(msg_entity.cvar_cl_voice_directional == 1)
1180 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1182 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1185 if(IS_REAL_CLIENT(msg_entity))
1186 soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTEN_NONE);
1189 case VOICETYPE_TEAMRADIO:
1190 FOR_EACH_REALCLIENT(msg_entity)
1191 if(!teamplay || msg_entity.team == self.team)
1193 if(msg_entity.cvar_cl_voice_directional == 1)
1194 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_MIN);
1196 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1199 case VOICETYPE_AUTOTAUNT:
1204 if(autocvar_sv_gentle)
1206 tauntrand = random();
1207 FOR_EACH_REALCLIENT(msg_entity)
1208 if (tauntrand < msg_entity.cvar_cl_autotaunt)
1210 if (msg_entity.cvar_cl_voice_directional >= 1)
1211 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1213 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1216 case VOICETYPE_TAUNT:
1218 if(self.deadflag == DEAD_NO)
1219 animdecide_setaction(self, ANIMACTION_TAUNT, TRUE);
1222 if(autocvar_sv_gentle)
1224 FOR_EACH_REALCLIENT(msg_entity)
1226 if (msg_entity.cvar_cl_voice_directional >= 1)
1227 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTEN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTEN_MAX));
1229 soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTEN_NONE);
1232 case VOICETYPE_PLAYERSOUND:
1233 sound(self, chan, sample, VOL_BASE, ATTEN_NORM);
1236 backtrace("Invalid voice type!");
1241 void PlayerSound(.string samplefield, float chan, float voicetype)
1243 GlobalSound(self.samplefield, chan, voicetype);
1246 void VoiceMessage(string type, string msg)
1249 float voicetype, ownteam;
1251 sample = GetVoiceMessageSampleField(type);
1253 if(GetPlayerSoundSampleField_notFound)
1255 sprint(self, strcat("Invalid voice. Use one of: ", allvoicesamples, "\n"));
1259 voicetype = GetVoiceMessageVoiceType(type);
1260 ownteam = (voicetype == VOICETYPE_TEAMRADIO);
1262 flood = Say(self, ownteam, world, msg, 1);
1265 GlobalSound(self.sample, CH_VOICE, voicetype);
1267 FakeGlobalSound(self.sample, CH_VOICE, voicetype);
1270 void MoveToTeam(entity client, float team_colour, float type)
1272 float lockteams_backup;
1274 lockteams_backup = lockteams; // backup any team lock
1276 lockteams = 0; // disable locked teams
1278 TeamchangeFrags(client); // move the players frags
1279 SetPlayerColors(client, team_colour - 1); // set the players colour
1280 Damage(client, client, client, 100000, DEATH_AUTOTEAMCHANGE, client.origin, '0 0 0'); // kill the player
1282 lockteams = lockteams_backup; // restore the team lock
1284 LogTeamchange(client.playerid, client.team, type);