I'm working with CuiButtons and I'm attempting to set the command argument to a console command with multiple arguments. I want the command that the CuiButton executes to be equivalent to typing chat.say "/leader ban <NAME>" in console which is the same as typing /leader ban <NAME> in chat. During my first attempt I tried this
This results in /leader being sent into chat and the second two arguments being lost, next I tried using double quotations so it would be interpreted as one argument.Code:Command = "chat.say /leader ban " + currentPlayer.displayName
This results in the server sending this to chat "/leader meaning that the double quotes did not force the following arguments to be interpreted as oneCode:Command = "chat.say \"/leader ban " + currentPlayer.displayName + "\""
I then tried using single quotes
This results in '/leader ban CombatTag' to be sent into chat which is closer to being correct because it kept the second and third arguments, but I need the single quotes to be removed somehow.Code:Command = "chat.say '/leader ban " + currentPlayer.displayName + "'"
Here is the part where I add the element if that is useful
Code:int i = 0; foreach (BasePlayer currentPlayer in zone.players) { Puts("0.375 " + ((.9) - ((double).05 * i))); Puts("0.625 " + ((.9 - 0.04) - ((double).05 * i))); elements.Add(new CuiButton { Button = { Command = "chat.say '/leader ban " + currentPlayer.displayName + "'", Close = mainName, Color = "0 255 0 1" }, RectTransform = { AnchorMin = "0.15 " + ((.95 - 0.02) - (i * 0.3)), AnchorMax = "0.35 " + ((.95) - (i * 0.3)) }, Text = { Text = currentPlayer.displayName, FontSize = 12, Align = TextAnchor.MiddleCenter } }, mainName); i++; }
CuiButton Multi argument command
Discussion in 'Rust Development' started by CombatTag, Aug 8, 2016.
-
Try
[DOUBLEPOST=1470614333][/DOUBLEPOST]Oh never mind try this instead:Code:Command = $"chat.say /leader ban {currentPlayer.displayName}";Code:Command = $"chat.say '/leader ban {currentPlayer.displayName}' ".Replace("'", ""); -
Just tested it and it is ignoring the last two arguments and only sending /leader
-
Already replied a second option. If all else fails I guess you could try:
Code:var newCommand = $"/leader ban {currentPlayer.displayName}"; //Put this where var i = 0; is Command = $"chat.say {newCommand}"; -
The two new options seem to have the same effect. I think I might just detect in chat when someone surrounds their message with single quotes cancel the message (if possible) and then use the player.Command function because I believe it will accept the arguments correctly.
