]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_player.qc
This seems to fix team modes in campaign. Yay.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_player.qc
index 33cc475cf12a2598ee8ba69165086a99c6d52442..27bd209c501ca6d799f48ec6e13f822b6e7eee86 100644 (file)
@@ -2,7 +2,7 @@ float weaponstats_buffer;
 
 void WeaponStats_Init()
 {
-       if(cvar_string("sv_weaponstats_killfile") != "" || cvar_string("sv_weaponstats_damagefile") != "")
+       if(autocvar_sv_weaponstats_killfile != "" || autocvar_sv_weaponstats_damagefile != "")
                weaponstats_buffer = buf_create();
        else
                weaponstats_buffer = -1;
@@ -17,10 +17,10 @@ void WeaponStats_Shutdown()
        string prefix;
        if(weaponstats_buffer < 0)
                return;
-       prefix = strcat(cvar_string("hostname"), "\t", GetGametype(), "_", GetMapname(), "\t");
-       if(cvar_string("sv_weaponstats_killfile") != "")
+       prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
+       if(autocvar_sv_weaponstats_killfile != "")
        {
-               fh = fopen(cvar_string("sv_weaponstats_killfile"), FILE_APPEND);
+               fh = fopen(autocvar_sv_weaponstats_killfile, FILE_APPEND);
                if(fh >= 0)
                {
                        fputs(fh, "#begin killfile\n");
@@ -39,9 +39,9 @@ void WeaponStats_Shutdown()
                        print("Weapon kill stats written\n");
                }
        }
-       if(cvar_string("sv_weaponstats_damagefile") != "")
+       if(autocvar_sv_weaponstats_damagefile != "")
        {
-               fh = fopen(cvar_string("sv_weaponstats_damagefile"), FILE_APPEND);
+               fh = fopen(autocvar_sv_weaponstats_damagefile, FILE_APPEND);
                if(fh >= 0)
                {
                        fputs(fh, "#begin damagefile\n");
@@ -111,6 +111,7 @@ void CopyBody(float keepvelocity)
        self.enemy = oldself;
        self.lip = oldself.lip;
        self.colormap = oldself.colormap;
+       self.glowmod = oldself.glowmod;
        self.iscreature = oldself.iscreature;
        self.angles = oldself.angles;
        self.avelocity = oldself.avelocity;
@@ -142,6 +143,7 @@ void CopyBody(float keepvelocity)
        self.movetype = oldself.movetype;
        self.nextthink = oldself.nextthink;
        self.solid = oldself.solid;
+       self.ballistics_density = oldself.ballistics_density;
        self.takedamage = oldself.takedamage;
        self.think = oldself.think;
        self.customizeentityforclient = oldself.customizeentityforclient;
@@ -165,55 +167,12 @@ void CopyBody(float keepvelocity)
 
 float player_getspecies()
 {
-       local float glob, i, j, fh, len, s, sk;
-       local string fn, l;
-
-       s = -1;
-
-       glob = search_begin("models/player/*.txt", TRUE, TRUE);
-       if(glob < 0)
-               return s;
-       for(j = 0; j <= 1; ++j)
-       {
-               for(i = 0; i < search_getsize(glob); ++i)
-               {
-                       fn = search_getfilename(glob, i);
-                       fh = fopen(fn, FILE_READ);
-                       if(fh < 0)
-                               continue;
-                       fgets(fh); fgets(fh);
-                       sk = stof(fgets(fh));
-                       if(sk == (j ? 0 : self.skinindex)) // 2nd pass skips the skin test
-                       if(fgets(fh) == self.model)
-                       {
-                               l = fgets(fh);
-                               len = tokenize_console(l);
-                               if (len != 2)
-                                       goto nospecies;
-                               if (argv(0) != "species")
-                                       goto nospecies;
-                               switch(argv(1))
-                               {
-                                       case "human":       s = SPECIES_HUMAN;       break;
-                                       case "alien":       s = SPECIES_ALIEN;       break;
-                                       case "robot_shiny": s = SPECIES_ROBOT_SHINY; break;
-                                       case "robot_rusty": s = SPECIES_ROBOT_RUSTY; break;
-                                       case "robot_solid": s = SPECIES_ROBOT_SOLID; break;
-                                       case "animal":      s = SPECIES_ANIMAL;      break;
-                                       case "reserved":    s = SPECIES_RESERVED;    break;
-                               }
-                       }
-:nospecies
-                       fclose(fh);
-               }
-               if (s >= 0)
-                       break;
-       }
-       search_end(glob);
-
-       if (s < 0)
-               s = SPECIES_HUMAN;
-
+       float s;
+       get_model_parameters(self.playermodel, self.skinindex);
+       s = get_model_parameters_species;
+       get_model_parameters(string_null, 0);
+       if(s < 0)
+               return SPECIES_HUMAN;
        return s;
 }
 
@@ -382,7 +341,7 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
        // damage resistance (ignore most of the damage from a bullet or similar)
        damage = max(damage - 5, 1);
 
-       v = healtharmor_applydamage(self.armorvalue, cvar("g_balance_armor_blockpercent"), damage);
+       v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
        take = v_x;
        save = v_y;
 
@@ -406,13 +365,13 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
                self.armorvalue = self.armorvalue - save;
                self.health = self.health - take;
                // pause regeneration for 5 seconds
-               self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
+               self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
        }
        self.dmg_save = self.dmg_save + save;//max(save - 10, 0);
        self.dmg_take = self.dmg_take + take;//max(take - 10, 0);
        self.dmg_inflictor = inflictor;
 
-       if (self.health <= -75 && self.modelindex != 0)
+       if (self.health <= -100 && self.modelindex != 0)
        {
                // don't use any animations as a gib
                self.frame = 0;
@@ -427,6 +386,8 @@ void PlayerCorpseDamage (entity inflictor, entity attacker, float damage, float
 }
 
 void ClientKill_Now_TeamChange();
+void freezetag_CheckWinner();
+void freezetag_Unfreeze();
 
 void PlayerDamage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
 {
@@ -475,12 +436,12 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        else
                Violence_GibSplash_At(hitloc, force, 2, bound(0, damage, 200) / 16, self, attacker);
 
-       if((g_arena && numspawned < 2) || (g_ca && player_cnt < 2) && !inWarmupStage)
+       if((g_arena && numspawned < 2) || (g_ca && ca_players < required_ca_players) && !inWarmupStage)
                return;
 
        if (!g_minstagib)
        {
-               v = healtharmor_applydamage(self.armorvalue, cvar("g_balance_armor_blockpercent"), damage);
+               v = healtharmor_applydamage(self.armorvalue, autocvar_g_balance_armor_blockpercent, damage);
                take = v_x;
                save = v_y;
        }
@@ -490,6 +451,16 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                take = damage;
        }
 
+       frag_inflictor = inflictor;
+       frag_attacker = attacker;
+       frag_target = self;
+       damage_take = take;
+       damage_save = save;
+       damage_force = force;
+       MUTATOR_CALLHOOK(PlayerDamage_SplitHealthArmor);
+       take = bound(0, damage_take, self.health);
+       save = bound(0, damage_save, self.armorvalue);
+
        if(sound_allowed(MSG_BROADCAST, attacker))
        {
                if (save > 10)
@@ -512,7 +483,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        self.armorvalue = self.armorvalue - save;
                        self.health = self.health - take;
                        // pause regeneration for 5 seconds
-                       self.pauseregen_finished = max(self.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
+                       self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_health_regen);
 
                        if (time > self.pain_finished)          //Don't switch pain sequences like crazy
                        {
@@ -528,16 +499,19 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                                        }
 
                                        if(sound_allowed(MSG_BROADCAST, attacker))
-                                       if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * cvar("g_balance_laser_primary_damage") * cvar("g_balance_selfdamagepercent") + 1)
+                                       if(!DEATH_ISWEAPON(deathtype, WEP_LASER) || attacker != self || self.health < 2 * autocvar_g_balance_laser_primary_damage * autocvar_g_balance_selfdamagepercent + 1)
+                                       if(self.health > 1)
                                        // exclude pain sounds for laserjumps as long as you aren't REALLY low on health and would die of the next two
                                        {
-                                               if(self.health > 75) // TODO make a "gentle" version?
+                                               if(deathtype == DEATH_FALL)
+                                                       PlayerSound(playersound_fall, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
+                                               else if(self.health > 75) // TODO make a "gentle" version?
                                                        PlayerSound(playersound_pain100, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 50)
                                                        PlayerSound(playersound_pain75, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
                                                else if(self.health > 25)
                                                        PlayerSound(playersound_pain50, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
-                                               else if(self.health > 1)
+                                               else
                                                        PlayerSound(playersound_pain25, CHAN_PAIN, VOICETYPE_PLAYERSOUND);
                                        }
                                }
@@ -565,7 +539,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        else if(attacker.classname == "player" || attacker.classname == "gib")
        {
                self.pusher = attacker;
-               self.pushltime = time + cvar("g_maxpushtime");
+               self.pushltime = time + autocvar_g_maxpushtime;
        }
        else if(time < self.pushltime)
        {
@@ -595,6 +569,12 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                float defer_ClientKill_Now_TeamChange;
                defer_ClientKill_Now_TeamChange = FALSE;
 
+               if(self.alivetime)
+               {
+                       PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
+                       self.alivetime = 0;
+               }
+
                if(valid_damage_for_weaponstats)
                        WeaponStats_LogKill(DEATH_WEAPONOF(deathtype), self.weapon);
 
@@ -623,21 +603,37 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        }
                }
 
-               // become fully visible
-               self.alpha = 1;
-               // clear selected player display
-               ClearSelectedPlayer();
-               // throw a weapon
-               SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
+               if(!g_freezetag)
+               {
+                       // become fully visible
+                       self.alpha = 1;
+                       // clear selected player display
+                       ClearSelectedPlayer();
+                       // throw a weapon
+                       SpawnThrownWeapon (self.origin + (self.mins + self.maxs) * 0.5, self.switchweapon);
+               }
+
                // print an obituary message
                Obituary (attacker, inflictor, self, deathtype);
                race_PreDie();
                DropAllRunes(self);
 
+               if(deathtype == DEATH_HURTTRIGGER && g_freezetag)
+               {
+                       PutClientInServer();
+                       count_alive_players(); // re-count players
+                       freezetag_CheckWinner();
+                       return;
+               }
+
                frag_attacker = attacker;
                frag_inflictor = inflictor;
+               frag_target = self;
                MUTATOR_CALLHOOK(PlayerDies);
 
+               if(g_freezetag)
+            return;
+
                if(self.flagcarried)
                {
                        if(attacker.classname != "player" && attacker.classname != "gib")
@@ -647,7 +643,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                        else
                                DropFlag(self.flagcarried, world, attacker);
                }
-               if(self.ballcarried)
+               if(self.ballcarried && g_nexball)
                        DropBall(self.ballcarried, self.origin, self.velocity);
                Portal_ClearAllLater(self);
                // clear waypoints
@@ -663,6 +659,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                self.movetype = MOVETYPE_TOSS;
                // shootable corpse
                self.solid = SOLID_CORPSE;
+               self.ballistics_density = autocvar_g_ballistics_density_corpse;
                // don't stick to the floor
                self.flags &~= FL_ONGROUND;
                // dying animation
@@ -672,10 +669,10 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                waves = 0;
                sdelay = cvar(strcat("g_", GetGametype(), "_respawn_delay"));
                if(!sdelay)
-                       sdelay = cvar("g_respawn_delay");
+                       sdelay = autocvar_g_respawn_delay;
                waves = cvar(strcat("g_", GetGametype(), "_respawn_waves"));
                if(!waves)
-                       waves = cvar("g_respawn_waves");
+                       waves = autocvar_g_respawn_waves;
                if(waves)
                        self.death_time = ceil((time + sdelay) / waves) * waves;
                else
@@ -699,12 +696,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                // call the corpse damage function just in case it wants to gib
                self.event_damage(inflictor, attacker, 0, deathtype, hitloc, force);
                // set up to fade out later
-               SUB_SetFade (self, time + 12 + random () * 4, 1);
-
-               // remove laserdot
-               if(self.weaponentity)
-                       if(self.weaponentity.lasertarget)
-                               remove(self.weaponentity.lasertarget);
+               SUB_SetFade (self, time + 6 + random (), 1);
 
                if(clienttype(self) == CLIENTTYPE_REAL)
                {
@@ -722,7 +714,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
                if(defer_ClientKill_Now_TeamChange)
                        ClientKill_Now_TeamChange();
 
-               if(sv_gentle > 0 || cvar("ekg")) {
+               if(sv_gentle > 0 || autocvar_ekg) {
                        // remove corpse
                        PlayerCorpseDamage (inflictor, attacker, 100.0, deathtype, hitloc, force);
                }
@@ -795,7 +787,7 @@ void UpdateSelectedPlayer()
        selected = world;
        selected_score = 0.95; // 18 degrees
 
-       if(!cvar("sv_allow_shownames"))
+       if(!autocvar_sv_allow_shownames)
                return;
 
        if(clienttype(self) != CLIENTTYPE_REAL)
@@ -885,14 +877,21 @@ void UpdateSelectedPlayer()
 }
 
 .float muted; // to be used by prvm_edictset server playernumber muted 1
-void Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
+float Say(entity source, float teamsay, entity privatesay, string msgin, float floodcontrol)
+// message "": do not say, just test flood control
+// return value:
+//   1 = accept
+//   0 = reject
+//  -1 = fake accept
 {
        string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, privatemsgprefix;
        float flood, privatemsgprefixlen;
+       var .float flood_field;
        entity head;
+       float ret;
 
        if(Ban_MaybeEnforceBan(source))
-               return;
+               return 0;
 
        if(!teamsay && !privatesay)
                if(substring(msgin, 0, 1) == " ")
@@ -900,9 +899,6 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
 
        msgin = formatmessage(msgin);
 
-       if(msgin == "")
-               return;
-
        if(source.classname != "player")
                colorstr = "^0"; // black for spectators
        else if(teams_matter)
@@ -913,9 +909,8 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
        if(intermission_running)
                teamsay = FALSE;
 
-       msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
-       if(msgin == "")
-               return;
+       if(msgin != "")
+               msgin = trigger_magicear_processmessage_forallears(source, teamsay, privatesay, msgin);
 
        /*
         * using bprint solves this... me stupid
@@ -928,34 +923,41 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
        }
        */
 
-       if(cvar("g_chat_teamcolors"))
+       if(autocvar_g_chat_teamcolors)
                namestr = playername(source);
        else
                namestr = source.netname;
 
-       if(privatesay)
+       if(msgin != "")
        {
-               msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
-               privatemsgprefixlen = strlen(msgstr);
-               msgstr = strcat(msgstr, msgin);
-               cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
-               if(cvar("g_chat_teamcolors"))
-                       privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
+               if(privatesay)
+               {
+                       msgstr = strcat("\{1}\{13}* ^3", namestr, "^3 tells you: ^7");
+                       privatemsgprefixlen = strlen(msgstr);
+                       msgstr = strcat(msgstr, msgin);
+                       cmsgstr = strcat(colorstr, "^3", namestr, "^3 tells you:\n^7", msgin);
+                       if(autocvar_g_chat_teamcolors)
+                               privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", playername(privatesay), ": ^7");
+                       else
+                               privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
+               }
+               else if(teamsay)
+               {
+                       msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
+                       cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
+               }
                else
-                       privatemsgprefix = strcat("\{1}\{13}* ^3You tell ", privatesay.netname, ": ^7");
-       }
-       else if(teamsay)
-       {
-               msgstr = strcat("\{1}\{13}", colorstr, "(^3", namestr, colorstr, ") ^7", msgin);
-               cmsgstr = strcat(colorstr, "(^3", namestr, colorstr, ")\n^7", msgin);
+               {
+                       msgstr = strcat("\{1}", namestr, "^7: ", msgin);
+                       cmsgstr = "";
+               }
+               msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
        }
        else
        {
-               msgstr = strcat("\{1}", namestr, "^7: ", msgin);
-               cmsgstr = "";
+               msgstr = cmsgstr = "";
        }
 
-       msgstr = strcat(strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
        fullmsgstr = msgstr;
        fullcmsgstr = cmsgstr;
 
@@ -966,66 +968,75 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
                float flood_spl;
                float flood_burst;
                float flood_lmax;
-               var .float flood_field;
                float lines;
                if(privatesay)
                {
-                       flood_spl = cvar("g_chat_flood_spl_tell");
-                       flood_burst = cvar("g_chat_flood_burst_tell");
-                       flood_lmax = cvar("g_chat_flood_lmax_tell");
+                       flood_spl = autocvar_g_chat_flood_spl_tell;
+                       flood_burst = autocvar_g_chat_flood_burst_tell;
+                       flood_lmax = autocvar_g_chat_flood_lmax_tell;
                        flood_field = floodcontrol_chattell;
                }
                else if(teamsay)
                {
-                       flood_spl = cvar("g_chat_flood_spl_team");
-                       flood_burst = cvar("g_chat_flood_burst_team");
-                       flood_lmax = cvar("g_chat_flood_lmax_team");
+                       flood_spl = autocvar_g_chat_flood_spl_team;
+                       flood_burst = autocvar_g_chat_flood_burst_team;
+                       flood_lmax = autocvar_g_chat_flood_lmax_team;
                        flood_field = floodcontrol_chatteam;
                }
                else
                {
-                       flood_spl = cvar("g_chat_flood_spl");
-                       flood_burst = cvar("g_chat_flood_burst");
-                       flood_lmax = cvar("g_chat_flood_lmax");
+                       flood_spl = autocvar_g_chat_flood_spl;
+                       flood_burst = autocvar_g_chat_flood_burst;
+                       flood_lmax = autocvar_g_chat_flood_lmax;
                        flood_field = floodcontrol_chat;
                }
                flood_burst = max(0, flood_burst - 1);
                // to match explanation in default.cfg, a value of 3 must allow three-line bursts and not four!
 
                // do flood control for the default line size
-               getWrappedLine_remaining = msgstr;
-               msgstr = "";
-               lines = 0;
-               while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
+               if(msgstr != "")
                {
-                       msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
-                       ++lines;
-               }
-               msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
+                       getWrappedLine_remaining = msgstr;
+                       msgstr = "";
+                       lines = 0;
+                       while(getWrappedLine_remaining && (!flood_lmax || lines <= flood_lmax))
+                       {
+                               msgstr = strcat(msgstr, " ", getWrappedLineLen(82.4289758859709, strlennocol)); // perl averagewidth.pl < gfx/vera-sans.width
+                               ++lines;
+                       }
+                       msgstr = substring(msgstr, 1, strlen(msgstr) - 1);
 
-               if(getWrappedLine_remaining != "")
-               {
-                       msgstr = strcat(msgstr, "\n");
-                       flood = 2;
-               }
+                       if(getWrappedLine_remaining != "")
+                       {
+                               msgstr = strcat(msgstr, "\n");
+                               flood = 2;
+                       }
 
-               if(time >= source.flood_field)
-               {
-                       source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
+                       if(time >= source.flood_field)
+                       {
+                               source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + lines * flood_spl;
+                       }
+                       else
+                       {
+                               flood = 1;
+                               msgstr = fullmsgstr;
+                       }
                }
                else
                {
-                       flood = 1;
-                       msgstr = fullmsgstr;
+                       if(time >= source.flood_field)
+                               source.flood_field = max(time - flood_burst * flood_spl, source.flood_field) + flood_spl;
+                       else
+                               flood = 1;
                }
-       }
 
-       if (timeoutStatus == 2) //when game is paused, no flood protection
-               source.flood_field = flood = 0;
+               if (timeoutStatus == 2) //when game is paused, no flood protection
+                       source.flood_field = flood = 0;
+       }
 
-       if(flood == 2)
+       if(flood == 2) // cannot happen for empty msgstr
        {
-               if(cvar("g_chat_flood_notify_flooder"))
+               if(autocvar_g_chat_flood_notify_flooder)
                {
                        sourcemsgstr = strcat(msgstr, "\n^3FLOOD CONTROL: ^7message too long, trimmed\n");
                        sourcecmsgstr = "";
@@ -1046,7 +1057,7 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
        if(!privatesay)
        if(source.classname != "player")
        {
-               if(teamsay || (cvar("g_chat_nospectators") == 1) || (cvar("g_chat_nospectators") == 2 && !inWarmupStage))
+               if(teamsay || (autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !inWarmupStage))
                        teamsay = -1; // spectators
        }
 
@@ -1060,57 +1071,70 @@ void Say(entity source, float teamsay, entity privatesay, string msgin, float fl
        if(source.muted)
        {
                // always fake the message
-               sprint(source, sourcemsgstr);
-               if(cmsgstr != "" && !privatesay)
-                       centerprint(source, sourcecmsgstr);
+               ret = -1;
        }
        else if(flood == 1)
        {
-               if(cvar("g_chat_flood_notify_flooder"))
-                       sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
-               else
+               if(autocvar_g_chat_flood_notify_flooder)
                {
-                       sprint(source, sourcemsgstr);
-                       if(cmsgstr != "" && !privatesay)
-                               centerprint(source, sourcecmsgstr);
+                       sprint(source, strcat("^3FLOOD CONTROL: ^7wait ^1", ftos(source.flood_field - time), "^3 seconds\n"));
+                       ret = 0;
                }
+               else
+                       ret = -1;
        }
-       else if(privatesay)
-       {
-               sprint(source, sourcemsgstr);
-               sprint(privatesay, msgstr);
-               if(cmsgstr != "")
-                       centerprint(privatesay, cmsgstr);
-       }
-       else if(teamsay > 0)
-       {
-               sprint(source, sourcemsgstr);
-               if(sourcecmsgstr != "")
-                       centerprint(source, sourcecmsgstr);
-               FOR_EACH_REALPLAYER(head) if(head.team == source.team)
-                       if(head != source)
-                       {
-                               sprint(head, msgstr);
-                               if(cmsgstr != "")
-                                       centerprint(head, cmsgstr);
-                       }
-       }
-       else if(teamsay < 0)
+       else
        {
-               sprint(source, sourcemsgstr);
-               FOR_EACH_REALCLIENT(head) if(head.classname != "player")
-                       if(head != source)
-                               sprint(head, msgstr);
+               ret = 1;
        }
-       else if(sourcemsgstr != msgstr)
+
+       if(sourcemsgstr != "" && ret != 0)
        {
-               sprint(source, sourcemsgstr);
-               FOR_EACH_REALCLIENT(head)
-                       if(head != source)
-                               sprint(head, msgstr);
+               if(ret < 0) // fake
+               {
+                       sprint(source, sourcemsgstr);
+                       if(sourcecmsgstr != "" && !privatesay)
+                               centerprint(source, sourcecmsgstr);
+               }
+               else if(privatesay)
+               {
+                       sprint(source, sourcemsgstr);
+                       sprint(privatesay, msgstr);
+                       if(cmsgstr != "")
+                               centerprint(privatesay, cmsgstr);
+               }
+               else if(teamsay > 0)
+               {
+                       sprint(source, sourcemsgstr);
+                       if(sourcecmsgstr != "")
+                               centerprint(source, sourcecmsgstr);
+                       FOR_EACH_REALPLAYER(head) if(head.team == source.team)
+                               if(head != source)
+                               {
+                                       sprint(head, msgstr);
+                                       if(cmsgstr != "")
+                                               centerprint(head, cmsgstr);
+                               }
+               }
+               else if(teamsay < 0)
+               {
+                       sprint(source, sourcemsgstr);
+                       FOR_EACH_REALCLIENT(head) if(head.classname != "player")
+                               if(head != source)
+                                       sprint(head, msgstr);
+               }
+               else if(sourcemsgstr != msgstr)
+               {
+                       sprint(source, sourcemsgstr);
+                       FOR_EACH_REALCLIENT(head)
+                               if(head != source)
+                                       sprint(head, msgstr);
+               }
+               else
+                       bprint(msgstr);
        }
-       else
-               bprint(msgstr);
+
+       return ret;
 }
 
 float GetVoiceMessageVoiceType(string type)
@@ -1123,12 +1147,9 @@ float GetVoiceMessageVoiceType(string type)
 }
 
 string allvoicesamples;
-float GetPlayerSoundSampleField_notFound;
-float GetPlayerSoundSampleField_fixed;
 .string GetVoiceMessageSampleField(string type)
 {
        GetPlayerSoundSampleField_notFound = 0;
-       GetPlayerSoundSampleField_fixed = 0;
        switch(type)
        {
 #define _VOICEMSG(m) case #m: return playersound_##m;
@@ -1142,7 +1163,6 @@ float GetPlayerSoundSampleField_fixed;
 .string GetPlayerSoundSampleField(string type)
 {
        GetPlayerSoundSampleField_notFound = 0;
-       GetPlayerSoundSampleField_fixed = 0;
        switch(type)
        {
 #define _VOICEMSG(m) case #m: return playersound_##m;
@@ -1211,7 +1231,10 @@ void LoadPlayerSounds(string f, float first)
        var .string field;
        fh = fopen(f, FILE_READ);
        if(fh < 0)
+       {
+               dprint("Player sound file not found: ", f, "\n");
                return;
+       }
        while((s = fgets(fh)))
        {
                if(tokenize_console(s) != 3)
@@ -1221,9 +1244,6 @@ void LoadPlayerSounds(string f, float first)
                        field = GetVoiceMessageSampleField(argv(0));
                if(GetPlayerSoundSampleField_notFound)
                        continue;
-               if(GetPlayerSoundSampleField_fixed)
-                       if not(first)
-                               continue;
                if(self.field)
                        strunzone(self.field);
                self.field = strzone(strcat(argv(1), " ", argv(2)));
@@ -1232,14 +1252,92 @@ void LoadPlayerSounds(string f, float first)
 }
 
 .float modelindex_for_playersound;
+.float skinindex_for_playersound;
 void UpdatePlayerSounds()
 {
        if(self.modelindex == self.modelindex_for_playersound)
+       if(self.skinindex == self.skinindex_for_playersound)
                return;
        self.modelindex_for_playersound = self.modelindex;
+       self.skinindex_for_playersound = self.skinindex;
        ClearPlayerSounds();
        LoadPlayerSounds("sound/player/default.sounds", 1);
-       LoadPlayerSounds(strcat(self.model, ".sounds"), 0);
+       LoadPlayerSounds(get_model_datafilename(self.playermodel, self.skinindex, "sounds"), 0);
+}
+
+void FakeGlobalSound(string sample, float chan, float voicetype)
+{
+       float n;
+       float tauntrand;
+
+       if(sample == "")
+               return;
+
+       tokenize_console(sample);
+       n = stof(argv(1));
+       if(n > 0)
+               sample = strcat(argv(0), ftos(floor(random() * n + 1)), ".wav"); // randomization
+       else
+               sample = strcat(argv(0), ".wav"); // randomization
+
+       switch(voicetype)
+       {
+               case VOICETYPE_LASTATTACKER_ONLY:
+                       break;
+               case VOICETYPE_LASTATTACKER:
+                       if(self.pusher)
+                       {
+                               msg_entity = self;
+                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
+                       }
+                       break;
+               case VOICETYPE_TEAMRADIO:
+                       msg_entity = self;
+                       if(msg_entity.cvar_cl_voice_directional == 1)
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                       else
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                       break;
+               case VOICETYPE_AUTOTAUNT:
+                       if(!sv_autotaunt)
+                               break;
+                       if(!sv_taunt)
+                               break;
+                       if(sv_gentle)
+                               break;
+                       tauntrand = random();
+                       msg_entity = self;
+                       if (tauntrand < msg_entity.cvar_cl_autotaunt)
+                       {
+                               if (msg_entity.cvar_cl_voice_directional >= 1)
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                               else
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                       }
+                       break;
+               case VOICETYPE_TAUNT:
+                       if(self.classname == "player")
+                               if(self.deadflag == DEAD_NO)
+                                       setanim(self, self.anim_taunt, FALSE, TRUE, TRUE);
+                       if(!sv_taunt)
+                               break;
+                       if(sv_gentle)
+                               break;
+                       msg_entity = self;
+                       if (msg_entity.cvar_cl_voice_directional >= 1)
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, bound(ATTN_MIN, msg_entity.cvar_cl_voice_directional_taunt_attenuation, ATTN_MAX));
+                       else
+                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
+                       break;
+               case VOICETYPE_PLAYERSOUND:
+                       msg_entity = self;
+                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NORM);
+                       break;
+               default:
+                       backtrace("Invalid voice type!");
+                       break;
+       }
 }
 
 void GlobalSound(string sample, float chan, float voicetype)
@@ -1261,34 +1359,32 @@ void GlobalSound(string sample, float chan, float voicetype)
        {
                case VOICETYPE_LASTATTACKER_ONLY:
                        if(self.pusher)
-                               if(self.pusher.team == self.team)
+                       {
+                               msg_entity = self.pusher;
+                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
                                {
-                                       msg_entity = self.pusher;
-                                       if(clienttype(msg_entity) == CLIENTTYPE_REAL)
-                                       {
-                                               if(msg_entity.cvar_cl_voice_directional == 1)
-                                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
-                                               else
-                                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
-                                       }
+                                       if(msg_entity.cvar_cl_voice_directional == 1)
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                                       else
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
                                }
+                       }
                        break;
                case VOICETYPE_LASTATTACKER:
                        if(self.pusher)
-                               if(self.pusher.team == self.team)
+                       {
+                               msg_entity = self.pusher;
+                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
                                {
-                                       msg_entity = self.pusher;
-                                       if(clienttype(msg_entity) == CLIENTTYPE_REAL)
-                                       {
-                                               if(msg_entity.cvar_cl_voice_directional == 1)
-                                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
-                                               else
-                                                       soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
-                                       }
-                                       msg_entity = self;
-                                       if(clienttype(msg_entity) == CLIENTTYPE_REAL)
-                                               soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
+                                       if(msg_entity.cvar_cl_voice_directional == 1)
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_MIN);
+                                       else
+                                               soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
                                }
+                               msg_entity = self;
+                               if(clienttype(msg_entity) == CLIENTTYPE_REAL)
+                                       soundto(MSG_ONE, self, chan, sample, VOL_BASE, ATTN_NONE);
+                       }
                        break;
                case VOICETYPE_TEAMRADIO:
                        FOR_EACH_REALCLIENT(msg_entity)
@@ -1332,6 +1428,7 @@ void GlobalSound(string sample, float chan, float voicetype)
                                else
                                        soundto(MSG_ONE, self, chan, sample, VOL_BASEVOICE, ATTN_NONE);
                        }
+                       break;
                case VOICETYPE_PLAYERSOUND:
                        sound(self, chan, sample, VOL_BASE, ATTN_NORM);
                        break;
@@ -1343,15 +1440,14 @@ void GlobalSound(string sample, float chan, float voicetype)
 
 void PlayerSound(.string samplefield, float chan, float voicetype)
 {
-       string sample;
-       sample = self.samplefield;
-       GlobalSound(sample, chan, voicetype);
+       GlobalSound(self.samplefield, chan, voicetype);
 }
 
 void VoiceMessage(string type, string msg)
 {
        var .string sample;
-       var float voicetype, ownteam;
+       float voicetype, ownteam;
+       float flood;
        sample = GetVoiceMessageSampleField(type);
 
        if(GetPlayerSoundSampleField_notFound)
@@ -1363,35 +1459,12 @@ void VoiceMessage(string type, string msg)
        voicetype = GetVoiceMessageVoiceType(type);
        ownteam = (voicetype == VOICETYPE_TEAMRADIO);
 
-       float flood;
-       float flood_spv;
-       var .float flood_field;
-
-       flood = 0;
-       if(ownteam)
-       {
-               flood_spv = cvar("g_voice_flood_spv_team");
-               flood_field = floodcontrol_voiceteam;
-       }
-       else
-       {
-               flood_spv = cvar("g_voice_flood_spv");
-               flood_field = floodcontrol_voice;
-       }
-
-       if(time >= self.flood_field)
-               self.flood_field = max(time, self.flood_field) + flood_spv;
-       else
-               flood = 1;
-
-       if (timeoutStatus == 2) //when game is paused, no flood protection
-               self.flood_field = flood = 0;
-
-       if (msg != "")
-               Say(self, ownteam, world, msg, 0);
+       flood = Say(self, ownteam, world, msg, 1);
 
-       if (!flood)
-               PlayerSound(sample, CHAN_VOICE, voicetype);
+       if (flood > 0)
+               GlobalSound(self.sample, CHAN_VOICE, voicetype);
+       else if (flood < 0)
+               FakeGlobalSound(self.sample, CHAN_VOICE, voicetype);
 }
 
 void MoveToTeam(entity client, float team_colour, float type, float show_message)