From a4a714da472512c4bf83c9b6ad6389cfb28b9803 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Thu, 15 Jun 2023 13:34:04 +0200 Subject: [PATCH] chat_commands 1.0.4 Only create variables for the port currently in-use For example: there's no need to create level.chat_commands["4977"] if the currently used port is 4976. This simply adds a bunch of variables and child variables for no reason, this was a flawed implementation that create an array per port on every server. Now it will only create an array for its own port as expected Removed 3074 from the default ports This port is not actively used by net_port, this was just a misunderstanding on my part --- chat_commands/chat_commands.gsc | 65 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index 24df2df..ccafc53 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -23,7 +23,7 @@ InitChatCommands() InitChatCommandsDvars(); level.chat_commands = []; // don't touch - level.chat_commands["ports"] = array("3074", "4976", "4977"); // an array of the ports of all your servers you want to have the script running on. This is useful to easily pass this array as first arg of CreateCommand to have the command on all your servers + level.chat_commands["ports"] = array("4976", "4977"); // an array of the ports of all your servers you want to have the script running on. This is useful to easily pass this array as first arg of CreateCommand to have the command on all your servers level.chat_commands["no_commands_message"] = array("^1No commands found", "You either ^1didn't add any chat_command file ^7to add a new command ^1or ^7there are ^1no command configured on this port", "chat_commands.gsc is ^1just the base system. ^7It doesn't provide any command on its own", "Also ^1make sure the ports are configured properly ^7in the CreateCommand function of your command file(s)"); // the lines to print in the chat when the server doesn't have any command added level.chat_commands["no_commands_wait"] = 6; // time to wait between each line in when printing that specific message in the chat @@ -61,43 +61,48 @@ InitChatCommandsDvars() */ CreateCommand(serverPorts, commandName, commandType, commandValue, commandMinimumPermission, commandHelp) { + currentPort = GetDvar("net_port"); + foreach (serverPort in serverPorts) { - level.commands[serverPort][commandName]["type"] = commandType; - - if (IsDefined(commandHelp)) + if (serverPort == currentPort) { - commandHelpMessage = commandHelp; - commandHelpString = commandHelp[0]; - - if (commandHelpString == "default_help_one_player") + level.commands[serverPort][commandName]["type"] = commandType; + + if (IsDefined(commandHelp)) { - commandHelpMessage = array("Example: " + GetDvar("cc_prefix") + commandName + " me", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt"); + commandHelpMessage = commandHelp; + commandHelpString = commandHelp[0]; + + if (commandHelpString == "default_help_one_player") + { + commandHelpMessage = array("Example: " + GetDvar("cc_prefix") + commandName + " me", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt"); + } + else if (commandHelpString == "default_help_two_players") + { + commandHelpMessage = array("Example: " + GetDvar("cc_prefix") + commandName + " me Resxt", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt me", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt Eldor"); + } + + level.commands[serverPort][commandName]["help"] = commandHelpMessage; } - else if (commandHelpString == "default_help_two_players") + + if (commandType == "text") { - commandHelpMessage = array("Example: " + GetDvar("cc_prefix") + commandName + " me Resxt", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt me", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt Eldor"); + level.commands[serverPort][commandName]["text"] = commandValue; + } + else if (commandType == "function") + { + level.commands[serverPort][commandName]["function"] = commandValue; } - level.commands[serverPort][commandName]["help"] = commandHelpMessage; - } - - if (commandType == "text") - { - level.commands[serverPort][commandName]["text"] = commandValue; - } - else if (commandType == "function") - { - level.commands[serverPort][commandName]["function"] = commandValue; - } - - if (IsDefined(commandMinimumPermission)) - { - level.commands[serverPort][commandName]["permission"] = commandMinimumPermission; - } - else - { - level.commands[serverPort][commandName]["permission"] = GetDvarInt("cc_permission_default"); + if (IsDefined(commandMinimumPermission)) + { + level.commands[serverPort][commandName]["permission"] = commandMinimumPermission; + } + else + { + level.commands[serverPort][commandName]["permission"] = GetDvarInt("cc_permission_default"); + } } } }