Exle Posted March 6, 2021 Posted March 6, 2021 (edited) 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 March 7, 2021 by Exle
Exle Posted March 7, 2021 Author Posted March 7, 2021 (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 March 7, 2021 by Exle
Recommended Posts