Chat Commands Manager
CLI library for Outward chat. No more need to build UI to execute mod functions.
| Last updated | 5 days ago |
| Total downloads | 20 |
| Total rating | 0 |
| Categories | Libraries Utility |
| Dependency string | GymMed-Chat_Commands_Manager-0.0.1 |
| Dependants | 1 other package depends on this package |
This mod requires the following mods to function
GymMed-Mods_Communicator
Outward Mods Communicator enables seamless communication between mods through shared events and configuration syncing. It also lets users override any changes made by other mods, giving them full control over their settings.
Preferred version: 1.2.0README
Outward Chat Commands Manager
Deeper Explanation
CLI stands for Command Line Interface. This mod brings a CLI-like experience to the in-game chat, allowing you to easily create and use commands directly in chat.Commands can be created through the Mods Communicator without the need to build a custom UI. This provides fast and convenient access to dynamic mod methods through chat commands.
The Chat Commands Manager includes command history and allows navigation using
the ArrowUp and ArrowDown keys. It also provides several
helper commands and the ability to bind recently used commands to hotkeys.
As a command manager, it allows inspection of all registered commands, including the original Outward commands. The tool also supports creating cheat commands and debug-mode–required commands. When cheat commands are used, the current game session will be marked as unsavable, preventing progress from being saved.
How to use it
Firstly, install Mods
Communicator After that,
you can publish and subscribe to ChatCommandsManager events.
All events are registered and visible in Mods Communicator’s logging system. However, it is still recommended to read the event descriptions below and review the examples.
Built-in Commands
The most important commands are:
/commands, /help, and /history.
These commands provide essential information about available commands and their usage.
For hotkey control, the following commands are available:
/lockKey and /releaseKey.
Use /help lockKey for detailed information about how to use these
commands.
Events
Publish
Mod Namespace:gymmed.chat_commands_manager_*Add Command
Event Name:ChatCommandsManager@AddChatCommandAccepts all command parameters data described in the Command Parameters section.
Example
This example shows a command registered duringResourcesPrefabManager.Load. This is done for safety in case a soft
dependency is missing. Commands can be added or removed dynamically at any time.
using OutwardModsCommunicator;
...
[HarmonyPatch(typeof(ResourcesPrefabManager), nameof(ResourcesPrefabManager.Load))]
public class ResourcesPrefabManager_Load
{
static void Postfix(ResourcesPrefabManager __instance)
{
Dictionary<string, (string, string)> myParameters = new()
{
{
"myParameter",
("parameterDescription", defaultValue)
}
};
Action<Character, Dictionary<string, string>> myFunction = MyCommandFunction;
var payload = new EventPayload
{
// command is a chat message trigger /myCommandName
["command"] = "myCommandName",
["parameters"] = myParameters,
["function"] = myFunction,
["description"] = "Your command description that will be seen through /help myCommandName ."
};
EventBus.Publish("gymmed.chat_commands_manager_*", "ChatCommandsManager@AddChatCommand", payload);
}
}
public static void MyCommandFunction(Character characterSender, Dictionary<string, string> arguments)
{
ChatPanel panel = characterSender?.CharacterUI?.ChatPanel;
if(panel == null)
{
Plugin.LogMessage("MySuperFunction Tried to use missing chatPanel.");
return;
}
// send message to chat
panel.ChatMessageReceived("System", "<color=#9900cc>Your command was triggered!</color>");
// parameter value = argument
arguments.TryGetValue("myParameter", out string parameterValue);
if(string.IsNullOrWhiteSpace(parameterValue))
{
...Your code when argument is missing.
return;
}
...Your code when argument is provided.
}
Remove Command
Event Name:ChatCommandsManager@RemoveChatCommandAccepts only the following parameter:
"command" — the name of the command to remove.
Example
using OutwardModsCommunicator;
...
[HarmonyPatch(typeof(ResourcesPrefabManager), nameof(ResourcesPrefabManager.Load))]
public class ResourcesPrefabManager_Load
{
static void Postfix(ResourcesPrefabManager __instance)
{
var payload = new EventPayload
{
// command is a chat message trigger /myCommandName
["command"] = "myCommandName",
};
EventBus.Publish("gymmed.chat_commands_manager_*", "ChatCommandsManager@RemoveChatCommand", payload);
}
}
Subscribe
Mod Namespace:gymmed.chat_commands_managerAllows you to listen for events triggered by the Chat Commands Manager.
Command Added
Event Name:ChatCommandsManager@AddChatCommand_AfterThis event is triggered after a command has been added and passes all command parameters back to the subscriber.
Example
using OutwardModsCommunicator;
...
[HarmonyPatch(typeof(ResourcesPrefabManager), nameof(ResourcesPrefabManager.Load))]
public class ResourcesPrefabManager_Load
{
static void Postfix(ResourcesPrefabManager __instance)
{
EventBus.Subscribe("gymmed.chat_commands_manager", "ChatCommandsManager@AddChatCommand_After", AddedCommand);
}
}
public static void AddedCommand(EventPayload payload)
{
if (payload == null) return;
string commandName = payload.Get<string>("command", null);
if(string.IsNullOrEmpty(commandName))
{
Log.LogMessage($"MyMod@AddedCommand didn't receive command variable!");
return;
}
...continue with execution...
}
Command Removed
Event Name:ChatCommandsManager@RemoveChatCommand_AfterThis event is triggered after a command has been removed and passes all command parameters back to the subscriber.
Example
using OutwardModsCommunicator;
...
[HarmonyPatch(typeof(ResourcesPrefabManager), nameof(ResourcesPrefabManager.Load))]
public class ResourcesPrefabManager_Load
{
static void Postfix(ResourcesPrefabManager __instance)
{
EventBus.Subscribe("gymmed.chat_commands_manager", "ChatCommandsManager@RemoveChatCommand_After", RemovedCommand);
}
}
public static void RemovedCommand(EventPayload payload)
{
if (payload == null) return;
string commandName = payload.Get<string>("command", null);
if(string.IsNullOrEmpty(commandName))
{
Log.LogMessage($"MyMod@RemovedCommand didn't receive command variable!");
return;
}
...continue with execution...
}
Command Parameters
Chat command data
| Variable Key | Type | Description |
|---|---|---|
| command | string | Required. The text players type in chat (e.g. "/command") to trigger your handler. |
| parameters | Dictionary<string, (string, string)> | Optional. Parameters with name and (description, default value) provided as dictionary. |
| function | Action <Character, Dictionary<string, string>> | Required. The method to execute when the command is triggered. Character is the command caller and Dictionary stores parameter and argument(value). |
| isCheatCommand | bool | Optional. Default false. Determines if player game will be saved after triggering your command. |
| description | string | Optional. Default null. Provides description of command for users. |
| debugMode | bool | Optional. Default false. Determines if command requires debug mode to work. |
Can I find full project example how to use this?
You can view outward basic chat commands mod here.
How to set up
To manually set up, do the following
- Create the directory:
Outward\BepInEx\plugins\OutwardChatCommandsManager\. - Extract the archive into any directory(recommend empty).
- Move the contents of the plugins\ directory from the archive into the
BepInEx\plugins\OutwardChatCommandsManager\directory you created. - It should look like
Outward\BepInEx\plugins\OutwardChatCommandsManager\OutwardChatCommandsManager.dllLaunch the game.