I am adding dynamic chat commands using the cmd.AddChatCommand. This will replace any chat command that already exists, even from other plugins. What I want to do is make sure the command doesn't already exist. Is there a method for this already implemented in Oxide?
Thanks,
Fire
Method for checking if chat command exists
Discussion in 'Rust Development' started by FireStorm78, Mar 28, 2018.
-
Wulf Community Admin
Why do you need to check if it exists first?
-
Hi Wulf,
I don't want to replace a chat command if it already exists. If my plugin registers /town and I have NTeleportation installed then I override that chat command. It can cause problems even within my own plugin if the user adds a chat command with the same name as the plugin's interface. So I want to make sure it doesn't exist before adding it. -
Wulf Community Admin
Right now there are no methods to check if a command already exists, but that may be something we could look into down the road. Oxide stores the commands in internal dictionaries, so you'd have to use reflection to access those, but I generally would not recommend that. In most cases, I'd just suggest changing the command in one plugin or the other, else offering a config option or localization support to change it.
-
That would be great to add a method to check the dictionary object without reflection. I hate reflection lol. It might make more sense to you if I explained in more detail what I am doing.
The plugin is a utility for setting up custom chat commands for custom teleport points. Similar to how /town works in NTeleportation. My benefactor wants to be able to type /PVP and be sent to a custom PVP teleport point. He also wants other custom TP points by other names. And it needs to be easy to use. The functionality doesn't already exist in NTeleportation so I thought of making a companion plugin. I also considered other TP plugins but they just don't do exactly what is needed.
The admin can use a command like /CTP ADD NAME [MAXRADIUS] [MINRADIUS] to create a TP point. It can then check to see if that TP point already exists by that name in the local data file, but if it doesn't exist there it registers the chat command and saves the data. If you use /CTP ADD CTP for example you would overwrite the very chat command needed for the plugin. Which is bad. I can catch that in my code which is fine, but if someone tries to /CTP ADD TOWN then it would replace the /town command from NTeleportation for example which would also be bad. If I did a quick ChatCommandExists call to see if it is already registered before making the attempt all would be right with the world.
I noticed the AddChatCommand function does check if CanOverrideCommand is true or false to determine if it should replace the command but it never seems to be true.
So yes a quick Exists method would be great. Thanks. -
Wulf Community Admin
Might be worth mentioning that I am finishing up a universal Warps plugin that would probably do the same thing you're doing.