@@ -1124,8 +1124,7 @@ public void PlayButtonSound(int client)
11241124 {
11251125 char buffer [255 ];
11261126 GetConVarString (g_hSoundPath , buffer , 255 );
1127- Format (buffer , sizeof (buffer ), " play %s " , buffer );
1128- ClientCommand (client , buffer );
1127+ EmitSoundToClientNoPreCache (client , buffer );
11291128 }
11301129
11311130 // Spectators button sound
@@ -1141,8 +1140,7 @@ public void PlayButtonSound(int client)
11411140 {
11421141 char szsound [255 ];
11431142 GetConVarString (g_hSoundPath , szsound , 256 );
1144- Format (szsound , sizeof (szsound ), " play %s " , szsound );
1145- ClientCommand (i , szsound );
1143+ EmitSoundToClientNoPreCache (client , szsound );
11461144 }
11471145 }
11481146 }
@@ -1535,8 +1533,7 @@ public void PlayRecordSound(int iRecordtype)
15351533 {
15361534 if (IsValidClient (i ) && ! IsFakeClient (i ) && g_bEnableQuakeSounds [i ] == true )
15371535 {
1538- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathWR );
1539- ClientCommand (i , buffer );
1536+ EmitSoundToClientNoPreCache (i , buffer );
15401537 }
15411538 }
15421539 }
@@ -1546,8 +1543,7 @@ public void PlayRecordSound(int iRecordtype)
15461543 {
15471544 if (IsValidClient (i ) && ! IsFakeClient (i ) && g_bEnableQuakeSounds [i ] == true )
15481545 {
1549- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathWR );
1550- ClientCommand (i , buffer );
1546+ EmitSoundToClientNoPreCache (i , buffer );
15511547 }
15521548 }
15531549 }
@@ -1557,8 +1553,7 @@ public void PlayRecordSound(int iRecordtype)
15571553 {
15581554 if (IsValidClient (i ) && ! IsFakeClient (i ) && g_bEnableQuakeSounds [i ] == true )
15591555 {
1560- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathTop );
1561- ClientCommand (i , buffer );
1556+ EmitSoundToClientNoPreCache (i , buffer );
15621557 }
15631558 }
15641559 }
@@ -1568,19 +1563,18 @@ public void PlayRecordSound(int iRecordtype)
15681563 {
15691564 if (IsValidClient (i ) && ! IsFakeClient (i ) && g_bEnableQuakeSounds [i ] == true )
15701565 {
1571- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathTop );
1572- ClientCommand (i , buffer );
1566+ EmitSoundToClientNoPreCache (i , buffer );
15731567 }
15741568 }
15751569 }
15761570}
15771571
15781572public void PlayUnstoppableSound (int client )
15791573{
1580- char buffer [255 ];
1581- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathPB );
15821574 if (! IsFakeClient (client ) && g_bEnableQuakeSounds [client ])
1583- ClientCommand (client , buffer );
1575+ {
1576+ EmitSoundToClientNoPreCache (client , g_szRelativeSoundPathPB );
1577+ }
15841578 // Spec Stop Sound
15851579 for (int i = 1 ; i <= MaxClients ; i ++ )
15861580 {
@@ -1591,7 +1585,9 @@ public void PlayUnstoppableSound(int client)
15911585 {
15921586 int Target = GetEntPropEnt (i , Prop_Send , " m_hObserverTarget" );
15931587 if (Target == client && g_bEnableQuakeSounds [i ])
1594- ClientCommand (i , buffer );
1588+ {
1589+ EmitSoundToClientNoPreCache (i , g_szRelativeSoundPathPB );
1590+ }
15951591 }
15961592 }
15971593 }
@@ -1604,8 +1600,7 @@ public void PlayWRCPRecord()
16041600 {
16051601 if (IsValidClient (i ) && ! IsFakeClient (i ) && g_bEnableQuakeSounds [i ] == true )
16061602 {
1607- Format (buffer , sizeof (buffer ), " play %s " , g_szRelativeSoundPathWRCP );
1608- ClientCommand (i , buffer );
1603+ EmitSoundToClientNoPreCache (i , buffer );
16091604 }
16101605 }
16111606}
@@ -2813,25 +2808,6 @@ stock int BooltoInt(bool status)
28132808 return (status ) ? 1 : 0 ;
28142809}
28152810
2816- public void PlayQuakeSound_Spec (int client , char [] buffer )
2817- {
2818- int SpecMode ;
2819- for (int x = 1 ; x <= MaxClients ; x ++ )
2820- {
2821- if (IsValidClient (x ) && ! IsPlayerAlive (x ))
2822- {
2823- SpecMode = GetEntProp (x , Prop_Send , " m_iObserverMode" );
2824- if (SpecMode == 4 || SpecMode == 5 )
2825- {
2826- int Target = GetEntPropEnt (x , Prop_Send , " m_hObserverTarget" );
2827- if (Target == client )
2828- if (g_bEnableQuakeSounds [x ])
2829- ClientCommand (x , buffer );
2830- }
2831- }
2832- }
2833- }
2834-
28352811public void AttackProtection (int client , int &buttons )
28362812{
28372813 if (GetConVarBool (g_hAttackSpamProtection ))
@@ -5337,3 +5313,26 @@ void RemoveColors(char[] message, int maxlength)
53375313 CRemoveTags (message , maxlength );
53385314 CRemoveColors (message , maxlength );
53395315}
5316+
5317+
5318+ /* *
5319+ * Emit a sound to a client without having to precache the sound.
5320+ * See https://wiki.alliedmods.net/Csgo_quirks#The_.22play.22_client_command for more details.
5321+ *
5322+ * @param client The client's id.
5323+ * @param szPath The path of the sound with or without "play " as a suffix.
5324+ * @param addPlay Whether or not "play " should be append to the begining of szPath (default = true).
5325+ */
5326+ stock void EmitSoundToClientNoPreCache (int client , const char [] szPath , bool addPlay = true )
5327+ {
5328+ char szBuffer [256 ];
5329+ if (addPlay )
5330+ {
5331+ Format (szBuffer , sizeof szBuffer , " play %s " , szPath );
5332+ }
5333+ else
5334+ {
5335+ strcopy (szBuffer , sizeof szBuffer , szPath );
5336+ }
5337+ ClientCommand (client , szBuffer );
5338+ }
0 commit comments