Skip to content

Easy chat-command API #2

@Cheatoid

Description

@Cheatoid

By using Reflection, it is possible to make certain things easier.
The goal is to make it really easy to add chat-commands for Starfall projects.
V1 code example:

[ChatCommand("test")] // Permission defaults to myself-only.
public static void TestCmd(BasePlayer invoker, string args) {
    Assert(invoker == Owner, "BUGCHECK");
    printf("Test chat command.  args=%s", args);
}

[ChatCommand("hidden", HideChat=true)] // Hides owner's chat
public static void HideTestCmd(BasePlayer invoker, string args) {
    print("Hidden command entered.");
}

[ChatCommand("join", ChatCommandPermission.Anyone)] // Let anyone run this
public static void JoinCmd(BasePlayer invoker, string args) {
    printf("%s has joined the party!", invoker.Name);
}

The above design could be upgraded by implementing a parser and have arguments fully-typed out method.
V2 code example:

[ChatCommand("install")]
public static void InstallCmd(BasePlayer invoker, string name, int num = 5, bool flag = false) {
    printf("Installing...  name=%q num=%i flag=%s", name, num, flag);
}

This version is slightly more complex to make it work, but it would be nicer and more fluent.
To run the command, you'd say:
/install --name "a string here" --flag true
Which should output the following:

Installing... name="a string here" num=5 flag=true

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions