A Rust-specific method (this will be obsolete soon):
[ConsoleCommand("reply")]
private void CommandReply(ConsoleSystem.Arg arg)
{
// Check if a command arguments are provided (message and name/ID)
if (arg.Args.Length >= 2)
{
// Try to find a player by name or ID
BasePlayer target = RustCore.FindPlayer(arg.Args[1]); // This is not accounting for spaces in names, use quotation marks
// Check if target player was found, or not
if (target != null)
{
// Send message to the target player
PrintToChat(target, arg.Args[0]); // This is not accounting for spaces in messages, use quotation marks
}
}
else
{
// Show a message if arguments weren't provided, if you'd like
}
}
A universal method:
[Command("reply")]
private void CommandReply(IPlayer player, string command, string[] args)
{
// Check if a command arguments are provided (message and name/ID)
if (arg.Length >= 2)
{
// Try to find a player by name or ID
IPlayer target = players.FindPlayer(args[1]); // This is not accounting for spaces in names, use quotation marks
// Check if target player was found, or not
if (target != null)
{
// Send message to the target player
target.Message(args[0]); // This is not accounting for spaces in messages, use quotation marks
}
}
else
{
// Show a message if arguments weren't provided, if you'd like
}
}