Executing a command from the server?Solved
Hi,

is there a way to transmit code direcktly to the server so it executes for example env.time 10 when i use the [Command("timeset")]?

        [Command("timeset")]
        private void TestCommand(IPlayer player, string command, string[] args)
        {

            string envtime;
            float hour;
            
            hour = 12.2f;
            
            envtime = "env.time " + hour;

            player.Reply(envtime);

        }​
when i use this command ingame with "/timeset" it just replays ingame into chat env.time 10 but does not execute the command to the server it self.

Thx.
First of all - if You are coding for Rust, it's better to inherit RustPlugin, not CovalencePlugin, example below is for RP.
It replies to chat cuz You make it to reply to chat, all works as supposed to.
Even tho I do not suggest You to use this method to set the time, You can assign value to every convar using example below
        [ChatCommand("timeset")]
        void Settime(BasePlayer player, string command, string[] args)
        {
            if(args?.Length > 0)
            {
                float timeToSet;
                if(!Single.TryParse(args[0], out timeToSet))
                    SendReply(player, "Entered time is incorrect");
                else ConVar.Env.time = timeToSet;
            }
        }​
If You want to run actual console commands (Why do you even need this?) with code - take a look at ConsoleSystem class, but I think it's better to make all actions run through code directly as it will be faster and won't look weird.
@2CHEVSKII, better to inherit CovalencePlugin, not RustPlugin as RustPlugin is going the way of the Dodo. Also do not see a purpose to your RunConsoleCommand usage.

If "env.time" is a console command, a simple server.Command("env.time VALUE") would work.

[Command("timeset")]
private void TestCommand(IPlayer player, string command, string[] args)
{
    server.Command("env.time", args);
}​
@Wulf RunConsoleCommand left from experiments xD didn't see it. What do You mean by 'going the way of Dodo'? Is it gonna be deprecated? I gonna cry then.
My general mind was about 'Why to use console commands from the plugin?'
YEEES! That what Wulf posted was the savior^^ a big thx^^ Solved!
Locked automatically