C.Register

From GTA Network Wiki
Jump to: navigation, search

C.Register
Server-Side Function

utilities-terminal.png Server-Side csharp.png C#

Registers a command at runtime.

Syntax

bool NAPI.Command.Register(string commandName, MethodInfo method);

NOTE: This function returns a bool, true if successful and false if failed.

Usage example(s)

namespace myresourcename
{
    public static class Commands
    {
        [Command] // Don't forget to add the Command Attribute
        public static void TestCmd(Client sender) // Method must be static!
        {
            NAPI.Util.ConsoleOutput("TestCommand Invoked!");
        }
    }

    public class Main : Script
    {
        [ServerEvent(Event.ResourceStart)]
        public void ResourceStart()
        {
            var methodInfo = Type.GetType("myresourcename.Commands").GetMethod("TestCmd"); // Reflection: Type.GetType("Namespace.Class").GetMethod("Method");
            if (methodInfo != null) NAPI.Command.Register(methodInfo);
        }
    }
}

Changelog

Version Description
1.0 Release.

References