lstwoMODS Core • Creating Mods

Mod Actions

Creating Mod Actions

Now to add a simple action to the mod we can create a method with the [ModAction] attribute:

[ModAction]
public static void MyAction()
{
    Plugin.Logger.LogInfo("Action Pressed");
}

It’s best practice to make these static unless they need to be called from an instance (this would be the case for PlayerBasedMods for example). Any method with this attribute will automatically be built into the UI (unless the BuildPanel method was overriden).

While these actions work, sometimes you’d want to add parameters for the user to enter:

[ModAction]
public static void MyAction(string text)
{
    Plugin.Logger.LogInfo(text);
}

These will automatically be turned into UI inputs as well. If you want to use this to set a single value, like player speed and want this to update in the UI as well, consider using a mod setting on a property. This is described in the Mod Settings guide

Customizing Mod Actions

We can further customize the action using the parameters on the attribute:

[ModAction(
    Label = "My Custom Action",
    Description = "This is my custom mod action",
    ShowInUI = true,
    Order = 10,
    Id = "MyAction",
    SeparatorText = "My Actions",
    ContentWidth = false,
    Macroable = false,
    ExcludeParameters = ["suffix"]
)]
public static void MyAction(string text, string suffix = "Pressed")
{
    Plugin.Logger.LogInfo($"{text} {suffix}");
}

These can be used to change how the action looks in the UI, wether it even shows up in the UI and whether it should be compatible with macros. Here is a list of all parameters and what they do:

  • Label: Changes the label on the button
  • Description: The tooltip that appears when hovering over the button
  • ShowInUI: Whether the AutoUIBuilder should build UI for this mod (turn this off to make custom UI, or to only include this in macros)
  • Order: What position this action should appear at in the UI. Very important for mods with multiple actions and settings as otherwise they will be placed (sort of) randomly.
  • Id: An ImGui ID that should be pushed to the UI. Set this to something unique if ImGui complains about any Id conflicts due to multiple UI elements having the same name.
  • Separator: Whether there should be a separator at the top of this action.
  • SeparatorText: Same as the one above but this one is a string that will be displayed as a SeparatorText. This works independently from the one above so setting this one to any non null value will enable it.
  • ContentWidth: Whether the button should stretch to the content width (same width as input field).
  • Macroable: Whether this action should appear as a macro step.
  • ExcludeParameters: An array of parameter names that should not be rendered to UI. They will instead pass their default value.

Customizing Mod Action Parameters

You can also customize each individual parameter, to make them work in the way you want them to in the UI:

[ModAction]
public static void MyAction(
    [ModActionParam(
        Label = "Number",
        Widget = WidgetType.Drag,
        Speed = 0.01f,
        Format = "%.2f",
        Id = "num"
    )] float num
)
{
    Plugin.Logger.LogInfo(num);
}

Here is a list of all parameters and what they do:

  • Label: The label of the input in the UI
  • Widget: The widget type used for the input (Default, Drag, Slider, Input, Color3, Color4)
  • Speed (Drag type only): How much to increase the value per step.
  • Min / Max: Min and max values for a number input.
  • Format: Printf format to display the numbers in (e.g. %.2f for a float with 2 decimal places)
  • Id: Same as the one on ModAction, gives an ImGui Id to avoid conflicts.