Hey, I'm trying to get into C# so please excuse me for being a noob! I'm trying to create a chat command that would work like this:
/consoleCMD <SteamID>
-This would then make the specified player run some code like this, player.Command("echo \"Hello\"")
Making a chat command that sends a specified player a command?
You need to find a player. `covalence.Players.Find` or something, dont remember exactly. Pass a string as an argument. Will give u a IPlayer. use `player.Command` - done.
In response to misticos ():Hey!
You need to find a player. `covalence.Players.Find` or something, dont remember exactly. P...
I've got this so far but I'm stuck again, hope I'm on the right track:
[ChatCommand("runcmd")]
private void runcmdCommand(BasePlayer player, string command, string[] args)
{
var steamID = Interface.Oxide.GetLibrary<Covalence>().Players.FindPlayerById("userIdAsString");
if (args == null || args.Length == 0)
{
SendReply(player, "Syntax: /runcmd <STEAMID>");
return;
}
switch (args[0].ToLower())
{
case steamID:
SendReply(player, "TEST");
return;
default:
break;
}
} [Command("runcmd")]
private void RunCommand(IPlayer player, string command, string[] args)
{
if (args.Length == 0)
{
player.Reply("Syntax: /runcmd <STEAMID>");
return
}
IPlayer targetPlayer = players.FindPlayerById(args[0]);
if (targetPlayer != null)
{
targetPlayer.Command("echo \"hello world\"");
}
}
This assumes your plugin is set as a RustPlugin (not recommend, being replaced by CovalencePlugin):
[Command("runcmd")]
private void RunCommand(BasePlayer player, string command, string[] args)
{
if (args.Length == 0)
{
SendReply(player, "Syntax: /runcmd <STEAMID>");
return
}
IPlayer targetPlayer = covalence.Players.FindPlayerById(args[0]);
if (targetPlayer != null)
{
targetPlayer.Command("echo \"hello world\"");
}
} In response to Wulf ():This assumes you have your plugin set as CovalencePlugin, not RustPlugin:
[Command("runcmd")]...
Hey thanks for the help, not sure why but when I try to load the plugin it returns this error:
Error while compiling: Plugin.cs(30,4): error CS1056: Unexpected character `'
the line 30,4 doesn't exist though so im not sure how to fix this one
Edit: This error is from the covalence sample you provided
In response to Wulf ():I don't see any issues in the code I provided above, but your IDE should be able to show you were th...
Yeah for some reason my plugin had an invisible character in it somewhere, the code works great but when I try to use this:
var pos = (targetPlayer.transform.position);
I get this error:
Error CS1061 'IPlayer' does not contain a definition for 'transform' and no accessible extension method 'transform' accepting a first argument of type 'IPlayer' could be found (are you missing a using directive or an assembly reference?)
For reference I'm trying to do this:
[Command("runcmd")]
private void RunCommand(IPlayer player, string command, string[] args)
{
if (args.Length == 0)
{
player.Reply("Syntax: /runcmd <STEAMID>");
return;
}
IPlayer targetPlayer = players.FindPlayerById(args[0]);
if (targetPlayer != null)
{
var pos = (targetPlayer.transform.position);
pos.y += 1.5f;
targetPlayer.Command("ddraw.text 15 255,0,0 ", pos, " Hey q t :p");
}
}