Init
This commit is contained in:
@@ -0,0 +1,392 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <sdkhooks>
|
||||
#include <regex>
|
||||
|
||||
#include <dhooks>
|
||||
#include <soundlib2>
|
||||
#include <hooksoundmsg>
|
||||
|
||||
#include <Basic>
|
||||
#include <CSound>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
bool g_bBlockAll = false;
|
||||
bool g_bDisabled[MAXPLAYERS+1] = false;
|
||||
float g_fSoundVolume[MAXPLAYERS+1] = {1.0, ...};
|
||||
float g_fMusicVolume[MAXPLAYERS+1] = {1.0, ...};
|
||||
|
||||
Handle hOnStartSoundForward = INVALID_HANDLE;
|
||||
|
||||
Basic g_aSounds;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: MyInfo
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo = {
|
||||
name = "Map Music Control Interface",
|
||||
author = "Mitch & SHUFEN from POSSESSION.tokyo & New Methods by PerfectLaugh from POSSESSION.tokyo & Testing by CrazyKid",
|
||||
description = "Allows clients to adjust ambient sounds played by the map",
|
||||
version = "4.0",
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: API
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
|
||||
RegPluginLibrary("mapmusic_interface");
|
||||
|
||||
CreateNative("MapMusicInterface_GetSoundVolume", Native_GetSoundVolume);
|
||||
CreateNative("MapMusicInterface_GetMusicVolume", Native_GetMusicVolume);
|
||||
CreateNative("MapMusicInterface_SetSoundVolume", Native_SetSoundVolume);
|
||||
CreateNative("MapMusicInterface_SetMusicVolume", Native_SetMusicVolume);
|
||||
|
||||
CreateNative("MapMusicInterface_IsDisabled", Native_IsDisabled);
|
||||
CreateNative("MapMusicInterface_SetDisabled", Native_SetDisabled);
|
||||
|
||||
CreateNative("MapMusicInterface_GetBlockAll", Native_GetBlockAll);
|
||||
CreateNative("MapMusicInterface_SetBlockAll", Native_SetBlockAll);
|
||||
|
||||
CreateNative("MapMusicInterface_HasExceedingLengthSound", Native_HasExceedingLengthSound);
|
||||
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public any Native_GetSoundVolume(Handle myself, int numParams) {
|
||||
return GetSoundVolume(GetNativeCell(1));
|
||||
}
|
||||
|
||||
public any Native_GetMusicVolume(Handle myself, int numParams) {
|
||||
return GetMusicVolume(GetNativeCell(1));
|
||||
}
|
||||
|
||||
public any Native_SetSoundVolume(Handle myself, int numParams) {
|
||||
SetSoundVolume(GetNativeCell(1), GetNativeCell(2));
|
||||
}
|
||||
|
||||
public any Native_SetMusicVolume(Handle myself, int numParams) {
|
||||
SetMusicVolume(GetNativeCell(1), GetNativeCell(2));
|
||||
}
|
||||
|
||||
public any Native_IsDisabled(Handle myself, int numParams) {
|
||||
return IsClientDisabled(GetNativeCell(1));
|
||||
}
|
||||
|
||||
public any Native_SetDisabled(Handle myself, int numParams) {
|
||||
SetClientDisabled(GetNativeCell(1), GetNativeCell(2));
|
||||
}
|
||||
|
||||
public any Native_GetBlockAll(Handle myself, int numParams)
|
||||
{
|
||||
return g_bBlockAll;
|
||||
}
|
||||
|
||||
public any Native_SetBlockAll(Handle myself, int numParams)
|
||||
{
|
||||
g_bBlockAll = GetNativeCell(1);
|
||||
}
|
||||
|
||||
public any Native_HasExceedingLengthSound(Handle myself, int numParams) {
|
||||
return HasExceedingLengthSound(GetNativeCell(1));
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: General
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnPluginStart()
|
||||
{
|
||||
hOnStartSoundForward = CreateGlobalForward("MapMusicInterface_OnStartSound", ET_Hook, Param_String, Param_Float, Param_CellByRef, Param_CellByRef);
|
||||
|
||||
g_aSounds = new Basic();
|
||||
for (int client = 1; client <= MaxClients; client++) {
|
||||
g_bDisabled[client] = false;
|
||||
g_fSoundVolume[client] = 1.0;
|
||||
g_fMusicVolume[client] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Clients
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientConnected(int client) {
|
||||
g_bDisabled[client] = false;
|
||||
g_fSoundVolume[client] = 1.0;
|
||||
g_fMusicVolume[client] = 1.0;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect_Post(int client) {
|
||||
g_bDisabled[client] = false;
|
||||
g_fSoundVolume[client] = 1.0;
|
||||
g_fMusicVolume[client] = 1.0;
|
||||
}
|
||||
|
||||
CSound GetCSound(int entity, int soundnum, bool is_ambient)
|
||||
{
|
||||
char key[64];
|
||||
FormatEx(key, sizeof(key), "%x_%x_%d", entity, soundnum, is_ambient? 1 : 0);
|
||||
CSound soundmap = view_as<CSound>(g_aSounds.GetHandle(key));
|
||||
if (soundmap == null) {
|
||||
soundmap = new CSound();
|
||||
g_aSounds.SetHandle(key, soundmap);
|
||||
}
|
||||
|
||||
return soundmap;
|
||||
}
|
||||
|
||||
CSound GetCSoundFromEntity(int entity)
|
||||
{
|
||||
char prefix[64];
|
||||
FormatEx(prefix, sizeof(prefix), "%x_", entity);
|
||||
|
||||
CSound soundmap = null;
|
||||
StringMapSnapshot snap = g_aSounds.Snapshot();
|
||||
char elem_key[64];
|
||||
for (int i = 0; i < snap.Length; i++) {
|
||||
snap.GetKey(i, elem_key, sizeof(elem_key));
|
||||
if (strncmp(prefix, elem_key, strlen(prefix)) == 0) {
|
||||
soundmap = view_as<CSound>(g_aSounds.GetHandle(elem_key));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete snap;
|
||||
return soundmap;
|
||||
}
|
||||
|
||||
#define EMIT_SND_NOFLAGS 0
|
||||
#define EMIT_SND_CHANGE_VOL (1 << 0)
|
||||
#define EMIT_SND_STOP (1 << 2)
|
||||
#define EMIT_SND_STOP_LOOPING (1 << 5)
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: HookSoundMsg
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action OnSoundEmittingToClient(int client, int origin[3], int& volume, float& delay, int& seq, int& entity, int& channel, int& pitch, int& flags, int& soundnum, int& soundnum_handle, int& speaker_entity, int& sound_level, bool is_sentence, bool is_ambient) {
|
||||
if (is_sentence || soundnum == -1) {
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
CSound soundmap = GetCSound(entity, soundnum, is_ambient);
|
||||
|
||||
if (flags & EMIT_SND_STOP || flags & EMIT_SND_STOP_LOOPING) {
|
||||
volume = 0;
|
||||
} else if (volume == -1) {
|
||||
volume = 100;
|
||||
}
|
||||
|
||||
if (soundmap.iPassTickCount != GetGameTickCount()) {
|
||||
char sample[256];
|
||||
char soundfile[256];
|
||||
ReadStringTable(FindStringTable("soundprecache"), soundnum, sample, sizeof(sample));
|
||||
if (sample[0] == '*' || sample[0] == '#')
|
||||
strcopy(soundfile, sizeof(soundfile), sample[1]);
|
||||
else
|
||||
strcopy(soundfile, sizeof(soundfile), sample);
|
||||
|
||||
if (soundmap.fLength <= 0.0) {
|
||||
soundmap.fLength = GetSoundLengthFloat(soundfile);
|
||||
}
|
||||
|
||||
if (flags == EMIT_SND_NOFLAGS ||
|
||||
((flags & EMIT_SND_CHANGE_VOL) && soundmap.fEndTime > 0.0 && soundmap.fEndTime <= GetTickedTime() && volume > 0)) {
|
||||
bool isMusic = false;
|
||||
Action res = APIOnStartSoundForward(soundfile, soundmap.fLength, isMusic, volume);
|
||||
if (res != Plugin_Continue) {
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
if (isMusic && g_bBlockAll) {
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
soundmap.fEndTime = GetTickedTime() + soundmap.fLength;
|
||||
soundmap.bIsMusic = isMusic;
|
||||
}
|
||||
else if (flags & EMIT_SND_STOP || flags & EMIT_SND_STOP_LOOPING) {
|
||||
soundmap.fEndTime = GetTickedTime();
|
||||
}
|
||||
// Volumes should be binded on entity, rather than sound file path.
|
||||
// This is the reason of why sounds were bugged on ze_deadcore.
|
||||
// Airvulpes uses multiple entities with same sound file to play with huge volume.
|
||||
soundmap.iVolume = volume;
|
||||
}
|
||||
|
||||
if ((flags & EMIT_SND_CHANGE_VOL) && soundmap.iPassTickCount == GetGameTickCount()) {
|
||||
if (soundmap.iPassClient != client) {
|
||||
// When called AcceptEntityInput(entity, "Volume"); via void UpdateAllGenericSound(int client),
|
||||
// that should be ignored because it was called even though needless except caller client.
|
||||
return Plugin_Handled;
|
||||
}
|
||||
}
|
||||
|
||||
volume = GetAdjustedVolumeOfClient(client, volume, soundmap.bIsMusic);
|
||||
return Plugin_Changed;
|
||||
}
|
||||
|
||||
int GetAdjustedVolumeOfClient(int client, int sourcevol, bool isMusic) {
|
||||
if (isMusic && IsClientDisabled(client)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float fvolume;
|
||||
if (isMusic) {
|
||||
fvolume = GetMusicVolume(client);
|
||||
}
|
||||
else {
|
||||
fvolume = GetSoundVolume(client);
|
||||
}
|
||||
|
||||
if (fvolume <= 0.0) {
|
||||
return 0;
|
||||
}
|
||||
return RoundToCeil(float(sourcevol) * fvolume);
|
||||
}
|
||||
|
||||
Action APIOnStartSoundForward(const char[] sample, float length, bool& isMusic, int& volume) {
|
||||
Call_StartForward(hOnStartSoundForward);
|
||||
Call_PushString(sample);
|
||||
Call_PushFloat(length);
|
||||
Call_PushCellRef(isMusic);
|
||||
Call_PushCellRef(volume);
|
||||
|
||||
Action res = Plugin_Continue;
|
||||
Call_Finish(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Internal
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
float GetSoundVolume(int client)
|
||||
{
|
||||
return g_fSoundVolume[client];
|
||||
}
|
||||
|
||||
float GetMusicVolume(int client)
|
||||
{
|
||||
return g_fMusicVolume[client];
|
||||
}
|
||||
|
||||
void SetSoundVolume(int client, float volume) {
|
||||
if (volume < 0.0) {
|
||||
volume = 0.0;
|
||||
}
|
||||
else if (volume > 1.0) {
|
||||
volume = 1.0;
|
||||
}
|
||||
|
||||
g_fSoundVolume[client] = volume;
|
||||
|
||||
if (IsClientInGame(client)) {
|
||||
UpdateAllGenericSound(client);
|
||||
}
|
||||
}
|
||||
|
||||
void SetMusicVolume(int client, float volume) {
|
||||
SetClientDisabled(client, false);
|
||||
|
||||
if (volume < 0.0) {
|
||||
volume = 0.0;
|
||||
}
|
||||
else if (volume > 1.0) {
|
||||
volume = 1.0;
|
||||
}
|
||||
|
||||
g_fMusicVolume[client] = volume;
|
||||
|
||||
if (IsClientInGame(client)) {
|
||||
UpdateAllGenericSound(client);
|
||||
}
|
||||
}
|
||||
|
||||
bool IsClientDisabled(int client) {
|
||||
return g_bDisabled[client];
|
||||
}
|
||||
|
||||
void SetClientDisabled(int client, bool disabled) {
|
||||
g_bDisabled[client] = disabled;
|
||||
|
||||
if (IsClientInGame(client)) {
|
||||
UpdateAllGenericSound(client);
|
||||
}
|
||||
}
|
||||
|
||||
bool HasExceedingLengthSound(float searchlength) {
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE) {
|
||||
char soundfile[256];
|
||||
GetEntPropString(entity, Prop_Data, "m_iszSound", soundfile, sizeof(soundfile));
|
||||
if (soundfile[0] == '*' || soundfile[0] == '#')
|
||||
strcopy(soundfile, sizeof(soundfile), soundfile[1]);
|
||||
|
||||
float length = GetSoundLengthFloat(soundfile);
|
||||
if (searchlength > 0.0 && length >= searchlength) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
float GetSoundLengthFloat(const char[] soundFile) {
|
||||
char path[PLATFORM_MAX_PATH];
|
||||
FormatEx(path, sizeof(path), "sound/%s", soundFile);
|
||||
|
||||
if (!FileExists(path, true)) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
SoundFile hSoundFile = new SoundFile(path, true);
|
||||
if (hSoundFile == null)
|
||||
return 0.0;
|
||||
|
||||
float result = float(hSoundFile.LengthInMilliseconds) / 1000.0;
|
||||
delete hSoundFile;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
OnEntityDestroyed(client);
|
||||
}
|
||||
|
||||
public void OnEntityDestroyed(int entity) {
|
||||
char prefix[32];
|
||||
FormatEx(prefix, sizeof(prefix), "%x_", entity);
|
||||
|
||||
StringMapSnapshot snap = g_aSounds.Snapshot();
|
||||
char elem_key[32];
|
||||
for (int i = 0; i < snap.Length; i++) {
|
||||
snap.GetKey(i, elem_key, sizeof(elem_key));
|
||||
if (strncmp(prefix, elem_key, strlen(prefix)) == 0) {
|
||||
delete g_aSounds.GetHandle(elem_key);
|
||||
g_aSounds.Remove(elem_key);
|
||||
}
|
||||
}
|
||||
delete snap;
|
||||
}
|
||||
|
||||
void UpdateAllGenericSound(int client) {
|
||||
int entity = INVALID_ENT_REFERENCE;
|
||||
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE) {
|
||||
CSound soundmap = GetCSoundFromEntity(entity);
|
||||
if (soundmap == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
soundmap.iPassTickCount = GetGameTickCount();
|
||||
soundmap.iPassClient = client;
|
||||
|
||||
SetVariantInt(soundmap.iVolume / 10);
|
||||
AcceptEntityInput(entity, "Volume");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
#include <sourcemod>
|
||||
#include <clientprefs>
|
||||
|
||||
#include <multicolors>
|
||||
#include <mapmusic_interface>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: MyInfo
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Plugin myinfo = {
|
||||
name = "Map Music Control",
|
||||
author = "Mitch & SHUFEN from POSSESSION.tokyo & Multi lang by Yuna & New Methods by PerfectLaugh from POSSESSION.tokyo & Testing by CrazyKid",
|
||||
description = "Allows clients to adjust ambient sounds played by the map",
|
||||
version = "4.0",
|
||||
url = "http://www.sourcemod.net/ + https://possession.tokyo"
|
||||
};
|
||||
|
||||
Handle cDisableSounds;
|
||||
Handle cSoundVolume;
|
||||
|
||||
ConVar sm_mapmusic_length;
|
||||
|
||||
bool bLateLoad;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: General
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
|
||||
bLateLoad = late;
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnPluginStart() {
|
||||
RegConsoleCmd("sm_music", Command_Music, "Brings up the music menu");
|
||||
RegConsoleCmd("sm_mapmusic", Command_Music, "Brings up the music menu");
|
||||
RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Toggles map music");
|
||||
RegConsoleCmd("sm_startmusic", Command_StartMusic, "Start map music");
|
||||
RegConsoleCmd("sm_playmusic", Command_StartMusic, "Start map music");
|
||||
|
||||
sm_mapmusic_length = CreateConVar("sm_mapmusic_length", "10.0", "How long required length for it will be music files.", _, true, 0.0);
|
||||
|
||||
LoadTranslations("mapmusic.phrases");
|
||||
|
||||
cDisableSounds = RegClientCookie("mapmusic_disable", "Disable Map Music", CookieAccess_Private);
|
||||
cSoundVolume = RegClientCookie("mapmusic_volume_int", "Map Music Volume", CookieAccess_Private);
|
||||
|
||||
SetCookieMenuItem(PrefMenu, 0, "Map Music");
|
||||
|
||||
if (bLateLoad) {
|
||||
for (int i = 1; i <= MaxClients; i++) {
|
||||
if (AreClientCookiesCached(i))
|
||||
OnClientCookiesCached(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Clients
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientCookiesCached(int client) {
|
||||
char sValue[8];
|
||||
|
||||
sValue[0] = '\0';
|
||||
GetClientCookie(client, cSoundVolume, sValue, sizeof(sValue));
|
||||
if (sValue[0] == '\0') {
|
||||
SetClientCookie(client, cSoundVolume, "100");
|
||||
strcopy(sValue, sizeof(sValue), "100");
|
||||
}
|
||||
MapMusicInterface_SetMusicVolume(client, StringToInt(sValue) / 100.0);
|
||||
|
||||
sValue[0] = '\0';
|
||||
GetClientCookie(client, cDisableSounds, sValue, sizeof(sValue));
|
||||
if (sValue[0] == '\0') {
|
||||
SetClientCookie(client, cDisableSounds, "0");
|
||||
strcopy(sValue, sizeof(sValue), "0");
|
||||
}
|
||||
MapMusicInterface_SetDisabled(client, view_as<bool>(StringToInt(sValue)));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Commands
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_Music(int client, int args) {
|
||||
if (client < 1 || client > MaxClients) return Plugin_Handled;
|
||||
|
||||
if (GetCmdArgs() < 1) {
|
||||
DisplaySettingsMenu(client);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
char sArguments[256];
|
||||
GetCmdArg(1, sArguments, sizeof(sArguments));
|
||||
|
||||
if (StrContains(sArguments, "off", false) > -1 || StrContains(sArguments, "disable", false) > -1 || StrContains(sArguments, "stop", false) > -1 || (strncmp(sArguments, "0", 1) == 0 && sArguments[1] == '\0')) {
|
||||
SetStatus(client, true);
|
||||
return Plugin_Handled;
|
||||
} else if (StrContains(sArguments, "on", false) > -1 || StrContains(sArguments, "enable", false) > -1 || StrContains(sArguments, "play", false) > -1) {
|
||||
SetStatus(client, false);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
SetVolume(client, StringToInt(sArguments));
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_StopMusic(int client, int args) {
|
||||
if (client < 1 || client > MaxClients) return Plugin_Handled;
|
||||
|
||||
if (GetStatus(client)) {
|
||||
SetStatus(client, false);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
SetStatus(client, true);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_StartMusic(int client, int args) {
|
||||
if (client < 1 || client > MaxClients) return Plugin_Handled;
|
||||
|
||||
SetStatus(client, false);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Menu
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void PrefMenu(int client, CookieMenuAction actions, any info, char[] buffer, int maxlen){
|
||||
if (actions == CookieMenuAction_DisplayOption) {
|
||||
Format(buffer, maxlen, "%T", "Cookie_Menu", client);
|
||||
}
|
||||
|
||||
if (actions == CookieMenuAction_SelectOption) {
|
||||
DisplaySettingsMenu(client);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplaySettingsMenu(int client) {
|
||||
Menu prefmenu = CreateMenu(PrefMenuHandler, MENU_ACTIONS_DEFAULT);
|
||||
|
||||
char szMenuTitle[64];
|
||||
Format(szMenuTitle, sizeof(szMenuTitle), "%T", "Menu_Title", client);
|
||||
prefmenu.SetTitle(szMenuTitle);
|
||||
|
||||
char szEnable[128];
|
||||
Format(szEnable, sizeof(szEnable), "%T\n \n%T", "Menu_Music", client, GetStatus(client) ? "Disabled" : "Enabled", client, "Menu_AdjustDesc", client);
|
||||
prefmenu.AddItem(GetStatus(client) ? "enable" : "disable", szEnable);
|
||||
|
||||
char szItem[32];
|
||||
int iVolume = GetVolume(client);
|
||||
Format(szItem, sizeof(szItem), "%T", "Menu_Vol", client, iVolume);
|
||||
switch (iVolume) {
|
||||
case 100: {
|
||||
prefmenu.AddItem("vol_80", szItem);
|
||||
}
|
||||
case 80: {
|
||||
prefmenu.AddItem("vol_60", szItem);
|
||||
}
|
||||
case 60: {
|
||||
prefmenu.AddItem("vol_40", szItem);
|
||||
}
|
||||
case 40: {
|
||||
prefmenu.AddItem("vol_20", szItem);
|
||||
}
|
||||
case 20: {
|
||||
prefmenu.AddItem("vol_15", szItem);
|
||||
}
|
||||
case 15: {
|
||||
prefmenu.AddItem("vol_10", szItem);
|
||||
}
|
||||
case 10: {
|
||||
prefmenu.AddItem("vol_5", szItem);
|
||||
}
|
||||
case 5: {
|
||||
prefmenu.AddItem("vol_100", szItem);
|
||||
}
|
||||
default: {
|
||||
prefmenu.AddItem("vol_100", szItem);
|
||||
}
|
||||
}
|
||||
|
||||
prefmenu.ExitBackButton = true;
|
||||
|
||||
prefmenu.Display(client, MENU_TIME_FOREVER);
|
||||
}
|
||||
|
||||
public int PrefMenuHandler(Menu prefmenu, MenuAction actions, int client, int item){
|
||||
if (actions == MenuAction_Select) {
|
||||
char preference[8];
|
||||
GetMenuItem(prefmenu, item, preference, sizeof(preference));
|
||||
|
||||
if (StrEqual(preference, "disable")) {
|
||||
SetStatus(client, true);
|
||||
} else if (StrEqual(preference, "enable")) {
|
||||
SetStatus(client, false);
|
||||
}
|
||||
|
||||
if (strncmp(preference, "vol_", 4) == 0) {
|
||||
SetVolume(client, StringToInt(preference[4]));
|
||||
}
|
||||
|
||||
DisplaySettingsMenu(client);
|
||||
}
|
||||
else if (actions == MenuAction_Cancel) {
|
||||
if (item == MenuCancel_ExitBack) {
|
||||
ShowCookieMenu(client);
|
||||
}
|
||||
}
|
||||
else if (actions == MenuAction_End) {
|
||||
delete prefmenu;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose: Internal
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
int GetVolume(int client) {
|
||||
return RoundToFloor(MapMusicInterface_GetMusicVolume(client) * 100.0);
|
||||
}
|
||||
|
||||
void SetVolume(int client, int volume) {
|
||||
if (!IsClientInGame(client)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
else if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
|
||||
MapMusicInterface_SetMusicVolume(client, volume / 100.0);
|
||||
|
||||
char sValue[8];
|
||||
IntToString(volume, sValue, sizeof(sValue));
|
||||
SetClientCookie(client, cSoundVolume, sValue);
|
||||
|
||||
CPrintToChat(client, "\x04[MapMusic] \x01%t", "Text_MapMusicVolume", volume);
|
||||
}
|
||||
|
||||
bool GetStatus(int client) {
|
||||
return MapMusicInterface_IsDisabled(client);
|
||||
}
|
||||
|
||||
void SetStatus(int client, bool bBlockMapMusic) {
|
||||
if (!IsClientInGame(client)) {
|
||||
return;
|
||||
}
|
||||
MapMusicInterface_SetDisabled(client, bBlockMapMusic);
|
||||
|
||||
char sValue[8];
|
||||
IntToString(view_as<int>(bBlockMapMusic), sValue, sizeof(sValue));
|
||||
SetClientCookie(client, cDisableSounds, sValue);
|
||||
|
||||
CPrintToChat(client, "\x04[MapMusic] \x01%t", bBlockMapMusic ? "Text_MapMusicDisable" : "Text_MapMusicEnable");
|
||||
}
|
||||
|
||||
public Action MapMusicInterface_OnStartSound(const char[] sample, float length, bool& isMusic, int& volume)
|
||||
{
|
||||
if (length >= sm_mapmusic_length.FloatValue) {
|
||||
isMusic = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user