Jump to content
RAGE Multiplayer Community

[c# | Solved] Register Command


Recommended Posts

this is deprecated https://wiki.gtanet.work/index.php?title=C.Register ??

How to get args from command?

this is not working

namespace myresourcename
{
    public static class Commands // Make sure to not inherit Script class in order to avoid registering the command on stratup
    {
        [Command] // Don't forget to add the Command Attribute
      //public static void TestCmd(Player player) // working
        public static void TestCmd(Player player, string args) // not working
        {
            NAPI.Util.ConsoleOutput("TestCommand Invoked!");
        }
    }

    public class Main : Script
    {
        [ServerEvent(Event.ResourceStart)]
        public void ResourceStart()
        { 
            var methodInfo = Type.GetType("myresourcename.Commands").GetMethod("TestCmd");
            if (methodInfo != null) 
            {
                var args = new RuntimeCommandInfo {Alias = "test", Description = "Some description"};
                NAPI.Command.Register(methodInfo, args);
            }
        }
    }
}

 

Edited by Exle
Link to post
Share on other sites
Posted (edited)
Solved

 

namespace myresourcename
{
    public static class Commands // Make sure to not inherit Script class in order to avoid registering the command on stratup
    {
        [Command] // Don't forget to add the Command Attribute
        public static void TestCmd(Player player, string arg1, string arg2, ...etc) // working
        {
            Console.WriteLine(arg1);
            Console.WriteLine(arg2);
            Console.WriteLine("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) 
            {
                var args = new RuntimeCommandInfo("test", "Some description");
                NAPI.Command.Register(methodInfo, args);
            }
        }
    }
}

 

Edited by Exle
Link to post
Share on other sites
  • Exle changed the title to [c# | Solved] Register Command
  • Xabi locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...