273 lines
8.1 KiB
SourcePawn
273 lines
8.1 KiB
SourcePawn
#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;
|
|
}
|
|
}
|