On_Console

Mar 7, 2018
On_Console
  • Method:
    On_Console

    Argument(s):
    1: Fougerite.Player Player
    2: ConsoleEvent event

    Examples:
    Python:

    Code (Python):

    def On_Console(self, Player, ConsoleEvent):
        if ConsoleEvent.Class == "Fougerite": #Class MUST be lowercase !!
            if ConsoleEvent.Function == "players":
                players = ""
                for pl in Server.Players:
                    players += " " + pl.Name
                #Reply with Player list
                ConsoleEvent.ReplyWith("Players: " + players)
            elif ConsoleEvent.Function == "broadcast":
                if not ConsoleEvent.Args:
                    ConsoleEvent.ReplyWith("Specify a name!")
                    return
                message = str.join(' ', ConsoleEvent.Args)
                Server.Broadcast(message)
     
    Javascript:
    Code (Javascript):

    function On_Console(Player, ConsoleEvent)
    {
        if (ConsoleEvent.Class == "Fougerite") //Class MUST be lowercase !!
        {
            if (ConsoleEvent.Function == "players")
            {
                var players = "";
                for (var pl in Server.Players) {
                    players += " " + pl.Name;
                }
                //Reply with Player list
                ConsoleEvent.ReplyWith("Players: " + players);
            }
        }
    }
     

    C#:
    Code (C#):

    public override void Initialize() {
        Hooks.OnConsoleReceived += OnConsole;
    }

     
    Code (C#):

    public override void DeInitialize() {
        Hooks.OnConsoleReceived -= OnConsole;
    }
     
    Code (C#):

    public void OnConsole(ref ConsoleSystem.Arg arg, bool external)
    {
        // Classname.FunctionName
        string PClass = arg.Class;
        string Pfunction = arg.Function;
        if (PClass == "myclassname" && Pfunction == "myfunction") //Class MUST be lowercase !!
        {
            if (!external) //If this is false it means It's from game console.
            {
                NetUser User = arg.argUser;
                if (User.admin)
                {
                    var players = "";
                    foreach (var pl in Server.Players) {
                        players += " " + pl.Name;
                    }
                    //Reply with Player list
                    ConsoleEvent.ReplyWith("Players: " + players);
                }
            }
        }
    }