Skip to content

Commit c2c898f

Browse files
authored
Add a new stock for clarity and remove an old stock (#370)
* Fix: `surftimer_OnNewWRCP` forwards formatted time * Fix: Time formatting * Add a new stock for clarity
1 parent 9486405 commit c2c898f

File tree

4 files changed

+42
-43
lines changed

4 files changed

+42
-43
lines changed

addons/sourcemod/scripting/surftimer/buttonpress.sp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public void CL_OnStartTimerPress(int client)
1212
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
1313
{
1414
CPrintToChat(client, "%t", "BPress1", g_szChatPrefix);
15-
ClientCommand(client, "play buttons\\button10.wav");
15+
EmitSoundToClientNoPreCache(client, "play buttons\\button10.wav", false);
1616
g_fErrorMessage[client] = fGetGameTime;
1717
}
1818
return;
@@ -22,7 +22,7 @@ public void CL_OnStartTimerPress(int client)
2222
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
2323
{
2424
CPrintToChat(client, "%t", "BPress2", g_szChatPrefix);
25-
ClientCommand(client, "play buttons\\button10.wav");
25+
EmitSoundToClientNoPreCache(client, "play buttons\\button10.wav", false);
2626
g_fErrorMessage[client] = fGetGameTime;
2727
}
2828
return;
@@ -32,7 +32,7 @@ public void CL_OnStartTimerPress(int client)
3232
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
3333
{
3434
CPrintToChat(client, "%t", "BPress3", g_szChatPrefix);
35-
ClientCommand(client, "play buttons\\button10.wav");
35+
EmitSoundToClientNoPreCache(client, "play buttons\\button10.wav", false);
3636
g_fErrorMessage[client] = fGetGameTime;
3737
}
3838
return;
@@ -176,7 +176,7 @@ public void CL_OnEndTimerPress(int client)
176176
// If timer is not on, play error sound and return
177177
if (!g_bTimerRunning[client])
178178
{
179-
ClientCommand(client, "play buttons\\button10.wav");
179+
EmitSoundToClientNoPreCache(client, "play buttons\\button10.wav", false);
180180
return;
181181
}
182182
else

addons/sourcemod/scripting/surftimer/commands.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ public Action Command_Restart(int client, int args)
13261326
g_fClientRestarting[client] = GetGameTime();
13271327
g_bClientRestarting[client] = true;
13281328
CPrintToChat(client, "%t", "Commands34", g_szChatPrefix);
1329-
ClientCommand(client, "play ambient/misc/clank4");
1329+
EmitSoundToClientNoPreCache(client, "play ambient/misc/clank4", false);
13301330
return Plugin_Handled;
13311331
}
13321332
}

addons/sourcemod/scripting/surftimer/misc.sp

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

15781572
public 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-
28352811
public 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+
}

addons/sourcemod/scripting/surftimer/surfzones.sp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public void EndTouch(int client, int action[3])
594594
if (g_bNoClip[client] || (!g_bNoClip[client] && (GetGameTime() - g_fLastTimeNoClipUsed[client]) < 3.0))
595595
{
596596
CPrintToChat(client, "%t", "SurfZones1", g_szChatPrefix);
597-
ClientCommand(client, "play buttons\\button10.wav");
597+
EmitSoundToClientNoPreCache(client, "play buttons\\button10.wav", false);
598598
// fluffys
599599
// ClientCommand(client, "sm_stuck");
600600
}

0 commit comments

Comments
 (0)