So i'm new to Rust Development, I've recently got all the .dll for references and decompiled the Assembly for rust and i'm starting to understand the concept more and more, but there's 1 specific thing i'm stuck on and that's the Chat commands and replies. So my question is how would one make a command for example: /register (password) (steamid) and if the password is empty then it return; but before that it displays a message to the player that it is incorrect.
Solved Creating a chat command?
Discussion in 'Rust Development' started by Captain Zip, Aug 6, 2017.
-
Wulf Community Admin
There's a plugin that does that already called "Authenticator | Oxide" if you're looking for that. It'd also provide one method of a universal chat command. For other examples, there are quite a few other plugins specific to games like Rust.
-
No no, it was an example just like how it would work etc I have that plugin downloaded and looked inside it but i dont understand what is written for the chat commands
-
Wulf Community Admin
The Docs also has an example: Oxide API for Rust. -
Yeah i edit the post cause i downloaded it but it's just weird cause i'm still getting use to all the functions
-
You need to use CovalencePlugin on ur class
And then add
Code:[Command("job")] void JobCommand(IPlayer player, string command, string[] args) { }
-
Base syntax:
[ChatCommand("NAME")]
void RANDOMNAME(BasePlayer player, string command, string[] args)
Check for empty password.
If (args[0].Length == 0) { SendReply(player, "Empty Pass); return; } -
Wulf Community Admin
-
Code:
[ChatCommand("Authkey")] void cmdChatAuthKey(BasePlayer player, string command, string[] args) { if (args[0] == AuthKey + SteamID) //Authkey (Authkey) (SteamID) { cmdConsoleAuthKey(); } else if (SteamID < 70000000000000000L) { PrintToChat("Please Enter a Valid Steam64ID!"); return; } else { return; } } #endregion #region Console Command void cmdConsoleAuthKey(ConsoleSystem.Arg arg) { SendReply(arg, "ownerid " + SteamID + " Owner"); }
Last edited by a moderator: Aug 6, 2017 -
There is another way, if you want to store the command as the variable:
Code:string ChatCommand = "/mycoolcommand"; var cmd= Interface.Oxide.GetLibrary<Command>(); //You there is 2 ways of adding commands: Function or string. If string - it would look like this: //cmd.AddChatCommand(ChatCommand.Replace("/", string.Empty), this, "CommandItself"); //Simular to the Plugin.CallHook. //If function - it should contain all arguments, as shown below cmd.AddChatCommand(ChatCommand.Replace("/", string.Empty), this, CommandItself); private void CommandItself(BasePlayer player, string command, string[] args) { //here goes your code. }
-
Wulf Community Admin
- The var cmd is not needed, that's already exposed as "cmd" by Oxide via RustPlugin
- There's no reason to add a / to the command at all, that's handled by Oxide
Code:private void Init() => cmd.AddChatCommand("mycoolcommand", this, CommandItself);private void CommandItself(BasePlayer player, string command, string[] args) { // Your code goes here }
-
2. I know - this is just for thouse admin who would try to add "/" to the config) -
Wulf Community Admin
-
Would look better next time, thanks!
You are the best =^-^=