1. Consider these two small plugins, that demonstrate the use of console and chat commands with or without any arguments.

    CommandExampleCs.cs=
    Code:
    using System;namespace Oxide.Plugins
    {
        [Info(" Command Example CS", "Bas", "0.1.0", ResourceId = 99681)]
        public class CommandExampleCs : RustPlugin
        {
            [ChatCommand("checkcs")]
            void cmdChatCheckCs(BasePlayer player, string cmd, string[] args)
            {
                Console.WriteLine(string.Format("player.displayName={0}", player.displayName));
                Console.WriteLine(string.Format("player.userID{0}", player.userID));
                Console.WriteLine(string.Format("cmd={0}", cmd));
                Console.WriteLine(string.Format("Number of arguments={0}", args.Length));
                foreach(string s in args){
                    Console.WriteLine( s );
                }
                Console.WriteLine("");
            }
            [ConsoleCommand("checkcs")]
            void cmdConsoleCheckCs(ConsoleSystem.Arg args)
            {
                if (args.HasArgs())
                {
                    Console.WriteLine(string.Format("Number of arguments={0}", args.Args.Length));
                    foreach(string s in args.Args){
                        Console.WriteLine( s );
                    }
                    Console.WriteLine("");
                }
                else
                {
                    Console.WriteLine(string.Format("Number of arguments=0"));
                }
            }
        }
    }
    CommandExamplePy.py=
    Code:
    import Systemclass CommandExamplePy:
        def __init__(self):
            self.Title = 'Command Example Py'
            self.Author = 'Bas'
            self.Version = V(0, 1, 0)
            self.ResourceId = 44823    def Init(self):
            #works fine:
            command.AddChatCommand('checkpy', self.Plugin, 'cmdChatCheckPy')
            #but this will not compile due to an 'array index is out of range'
            #command.AddConsoleCommand('checkpy', self.Plugin,  'cmdConsoleCheckPy')    def cmdChatCheckPy(self, player, cmd, args):
            print "player.displayName=" + player.displayName
            print "player.userID=" +str(player.userID)
            print "cmd=" +cmd
            print "number of arguments="+str(len(args))
            print str(args)    def cmdConsoleCheckPy(self, args):
            print dir(args)
    The problem is: in python AddConsoleCommand seems to malfunction due to an 'array index is out of range'?

    Or am I doing something wrong here?
     
  2. Correct your doing something wrong, all console commands must have a parent.

    Change:
    command.AddConsoleCommand('checkpy', self.Plugin, 'cmdConsoleCheckPy')

    To:
    command.AddConsoleCommand('example.checkpy', self.Plugin, 'cmdConsoleCheckPy')
     
  3. Yes, that works as in: the error is gone, but it does not work as in the dir of the args is never printed. Still something is going wrong...

    I have this now:
    Code:
    import Systemclass ConsoleCommandExamplePy:
        def __init__(self):
            self.Title = 'Console Command Example Py'
            self.Author = 'Bas'
            self.Version = V(0, 1, 0)
            self.ResourceId = 44823
          
        def Init(self):
            command.AddConsoleCommand('ConsoleCommandExamplePy.checkpy', self.Plugin,  'cmdConsoleCheckPy')    def cmdConsoleCheckPy(self, args):
            print 'Inside cmdConsoleCheckPy'
     
    Last edited by a moderator: Apr 23, 2015
  4. You'll need to wait for someone who has experience with python to help you more.
     
  5. the parameter is from rust type ConsoleSystem+Args, so you can display with:
    Code:
    def cmdConsoleCheckPy(self, arg):
        print arg.Args
    and use functions like HasArgs([count]) and Get[Type](argNum) eg: arg.HasArgs(1) or arg.GetString(0)
     
  6. Tx: SkinN õ.Õ'.|. for the help on this

    In python, the wierd thing is: you have to type the complete command, including class name, in the console. Then it will work.
    So to have cmdConsoleCheckPy triggered, you would have to type PyConsole.checkpy into the console.

    PyConsole.py
    Code:
    class PyConsole:
        def __init__(self):
            self.Title = 'PyConsole'
            self.Author = 'Bas'
            self.Version = V(0, 1, 0)   
        def Init(self):
            command.AddConsoleCommand('PyConsole.checkpy', self.Plugin, 'cmdConsoleCheckPy')
        def cmdConsoleCheckPy(self,args):
            msg='PyConsole'
            for arg in args.Args:
                msg=msg+" "+arg
            print msg
    But the wierd thing is: in the c# plugin I made that does the same: I only have to type the command name itself, not the classname.
    So I would only have to type checkcs into the console to trigger cmdConsoleCheckCs.

    CsConsole.cs
    Code:
    using System;namespace Oxide.Plugins{
        [Info("CsConsole", "Bas", "0.1.0")]
        public class CsConsole : RustPlugin {
            [ConsoleCommand("checkcs")]
            void cmdConsoleCheckCs(ConsoleSystem.Arg args) {
                if (args.HasArgs()) {
                    Console.WriteLine(string.Format("Number of arguments={0}", args.Args.Length));
                    foreach(string s in args.Args) {
                        Console.WriteLine( s );
                    }
                }
                else {
                    Console.WriteLine(string.Format("Number of arguments=0"));
                }
                Console.WriteLine("");
            }
        }
    }