Jump to content

Recommended Posts

Posted

English:

Is there any way to add commands for controlling BGM through mods? For example, inputting "/nobgm" to turn off BGM or set its volume to 0%, and inputting "/bgm" to turn on BGM or set its volume to 30%.

 

原文:

请问有没有办法通过模组来添加控制BGM的指令?比如输入“/nobgm"来关闭BGM或者把BGM的音量调成0%,输入”/bgm“来打开BGM或者把BGM的音量调成30%。

  • Solution
Posted

You can set any client config value via the `.clientConfig` command, including the bgm volume (`musicLevel`):

.clientConfig musicLevel 0
.clientConfig musicLevel 30

If you want short-hand commands, you can define custom commands in your mod's `StartClientSide` and use `ICoreClientAPI.TriggerChatMessage` to call `.clientConfig`.
That should look like:

public override void StartClientSide(ICoreClientAPI api) {
    api.ChatCommands
        .Create("notbgm")
        .HandleWith(args => {
            api.TriggerChatMessage(".clientConfig musicLevel 0");
            return TextCommandResult.Success($"Current music level: {ClientSettings.MusicLevel}");
        });
    //...
}
  • Like 2
Posted
On 1/12/2026 at 4:39 PM, Spoonail said:

You can set any client config value via the `.clientConfig` command, including the bgm volume (`musicLevel`):

.clientConfig musicLevel 0
.clientConfig musicLevel 30

If you want short-hand commands, you can define custom commands in your mod's `StartClientSide` and use `ICoreClientAPI.TriggerChatMessage` to call `.clientConfig`.
That should look like:

public override void StartClientSide(ICoreClientAPI api) {
    api.ChatCommands
        .Create("notbgm")
        .HandleWith(args => {
            api.TriggerChatMessage(".clientConfig musicLevel 0");
            return TextCommandResult.Success($"Current music level: {ClientSettings.MusicLevel}");
        });
    //...
}

Thank you very much!
".clientConfig musicLevel 0" and ".clientConfig musicLevel 30" are two commands that I had been searching for for a long time but couldn't find.

原文:

非常感谢!
“.clientConfig musicLevel 0”和“.clientConfig musicLevel 30”这两个指令正式我苦苦寻找了很久都没有找到的指令。

  • Like 1
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.