mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 02:18:26 +00:00
Added Shavit_OnPlaySound and shavit_sounds_enabled
This commit is contained in:
parent
533f3bccc9
commit
bcc63e13b1
@ -844,7 +844,7 @@ forward void Shavit_OnTimescaleChanged(int client, float oldtimescale, float new
|
||||
forward Action Shavit_OnCheckPointMenuMade(int client, bool segmented);
|
||||
|
||||
/**
|
||||
* Called when before a selection is processed in the main checkpoint menu.
|
||||
* Called before a selection is processed in the main checkpoint menu.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param param2 Second parameter in the callback, usually the item selected.
|
||||
@ -856,6 +856,18 @@ forward Action Shavit_OnCheckPointMenuMade(int client, bool segmented);
|
||||
*/
|
||||
forward Action Shavit_OnCheckpointMenuSelect(int client, int param2, char[] info, int maxlength, int currentCheckpoint, int maxCPs);
|
||||
|
||||
/**
|
||||
* Called before a sound is played by shavit-sounds.
|
||||
*
|
||||
* @param client Index of the client that triggered the sound event.
|
||||
* @param sound Reference to the sound that will be played.
|
||||
* @param maxlength Length of the sound buffer, always PLATFORM_MAX_PATH.
|
||||
* @param clients Reference to the array of clients to receive the sound, maxsize of MaxClients.
|
||||
* @param count Reference to the number of clients to receive the sound.
|
||||
* @return Plugin_Handled or Plugin_Stop to block the sound from being played. Anything else to continue the operation.
|
||||
*/
|
||||
forward Action Shavit_OnPlaySound(int client, char[] sound, int maxlength, int[] clients, int &count);
|
||||
|
||||
/**
|
||||
* Returns the game type the server is running.
|
||||
*
|
||||
|
||||
@ -39,6 +39,9 @@ StringMap gSM_RankSounds = null;
|
||||
|
||||
// cvars
|
||||
Convar gCV_MinimumWorst = null;
|
||||
Convar gCV_Enabled = null;
|
||||
|
||||
Handle gH_OnPlaySound = null;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -80,8 +83,11 @@ public void OnPluginStart()
|
||||
|
||||
// cvars
|
||||
gCV_MinimumWorst = new Convar("shavit_sounds_minimumworst", "10", "Minimum amount of records to be saved for a \"worst\" sound to play.", 0, true, 1.0);
|
||||
gCV_Enabled = new Convar("shavit_sounds_enabled", "1", "Enables/Disables functionality of the plugin", 0, true, 0.0, true, 1.0);
|
||||
|
||||
Convar.AutoExecConfig();
|
||||
|
||||
gH_OnPlaySound = CreateGlobalForward("Shavit_OnPlaySound", ET_Event, Param_Cell, Param_String, Param_Cell, Param_Array, Param_CellByRef);
|
||||
}
|
||||
|
||||
public void OnLibraryAdded(const char[] name)
|
||||
@ -114,7 +120,7 @@ public void OnMapStart()
|
||||
|
||||
File fFile = OpenFile(sFile, "r"); // readonly, unless i implement in-game editing
|
||||
|
||||
if(fFile == null)
|
||||
if(fFile == null && gCV_Enabled.BoolValue)
|
||||
{
|
||||
SetFailState("Cannot open \"configs/shavit-sounds.cfg\". Make sure this file exists and that the server has read permissions to it.");
|
||||
}
|
||||
@ -186,6 +192,11 @@ public void OnMapStart()
|
||||
|
||||
public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track, float oldtime, float perfs)
|
||||
{
|
||||
if(!gCV_Enabled.BoolValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(oldtime != 0.0 && time > oldtime && gA_NoImprovementSounds.Length != 0)
|
||||
{
|
||||
char sSound[PLATFORM_MAX_PATH];
|
||||
@ -197,6 +208,11 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st
|
||||
|
||||
public void Shavit_OnFinish_Post(int client, int style, float time, int jumps, int strafes, float sync, int rank, int overwrite, int track)
|
||||
{
|
||||
if(!gCV_Enabled.BoolValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float fOldTime = Shavit_GetClientPB(client, style, track);
|
||||
|
||||
char sSound[PLATFORM_MAX_PATH];
|
||||
@ -235,6 +251,11 @@ public void Shavit_OnFinish_Post(int client, int style, float time, int jumps, i
|
||||
|
||||
public void Shavit_OnWorstRecord(int client, int style, float time, int jumps, int strafes, float sync, int track)
|
||||
{
|
||||
if(!gCV_Enabled.BoolValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(gA_WorstSounds.Length != 0 && Shavit_GetRecordAmount(style, track) >= gCV_MinimumWorst.IntValue)
|
||||
{
|
||||
char sSound[PLATFORM_MAX_PATH];
|
||||
@ -247,7 +268,7 @@ public void Shavit_OnWorstRecord(int client, int style, float time, int jumps, i
|
||||
}
|
||||
}
|
||||
|
||||
void PlayEventSound(int client, bool everyone, char[] sound)
|
||||
void PlayEventSound(int client, bool everyone, char sound[PLATFORM_MAX_PATH])
|
||||
{
|
||||
int[] clients = new int[MaxClients];
|
||||
int count = 0;
|
||||
@ -275,6 +296,20 @@ void PlayEventSound(int client, bool everyone, char[] sound)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Action result = Plugin_Continue;
|
||||
Call_StartForward(gH_OnPlaySound);
|
||||
Call_PushCell(client);
|
||||
Call_PushStringEx(sound, PLATFORM_MAX_PATH, SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
|
||||
Call_PushArrayEx(clients, MaxClients, SM_PARAM_COPYBACK);
|
||||
Call_PushCellRef(count);
|
||||
Call_Finish(result);
|
||||
|
||||
if(result != Plugin_Continue && result != Plugin_Changed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(count > 0)
|
||||
{
|
||||
EmitSound(clients, count, sound);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user