chat_commands 1.3.2

Changed the prefix from a level scoped variable to a dvar.
Updated IW4MAdmin instructions, including the prefix conflict

Added cc_prefix dvar
This commit is contained in:
Resxt 2023-03-21 01:36:36 +01:00
parent 32686b90d3
commit ba1322b933
2 changed files with 13 additions and 11 deletions

View File

@ -2,8 +2,8 @@
Let players execute commands by typing in the chat. Let players execute commands by typing in the chat.
This can be used to display text to the player, for example the server rules or execute GSC code, just like console commands. This can be used to display text to the player, for example the server rules or execute GSC code, just like console commands.
This has been created for private games or servers that aren't running IW4MAdmin and want to have some commands. This works in private games, on dedicated servers that use [IW4MAdmin](https://github.com/RaidMax/IW4M-Admin) and those that don't.
This hasn't been tested on a server running IW4MAdmin so I highly recommend doing some testing on a private server if you want to use both. If you do monitor your server with [IW4MAdmin](https://github.com/RaidMax/IW4M-Admin) then make sure to read the [notes section](#notes).
## chat_commands.gsc ## chat_commands.gsc
@ -30,6 +30,7 @@ Here are the dvars you can configure:
| Name | Description | Default value | Accepted values | | Name | Description | Default value | Accepted values |
|---|---|---|---| |---|---|---|---|
| cc_debug | Toggle whether the script is in debug mode or not. This is used to print players GUID in the console when they connect | 0 | 0 or 1 | | cc_debug | Toggle whether the script is in debug mode or not. This is used to print players GUID in the console when they connect | 0 | 0 or 1 |
| cc_prefix | The symbol to type before the command name in the chat. Only one character is supported. The `/` symbol won't work normally as it's reserved by the game. If you use the `/` symbol as prefix you will need to type double slash in the game | ! | Any working symbol |
| cc_permission_enabled | Toggle whether the permission system is enabled or not. If it's disabled any player can run any available | 0 | 0 or 1 | | cc_permission_enabled | Toggle whether the permission system is enabled or not. If it's disabled any player can run any available | 0 | 0 or 1 |
| cc_permission_mode | Changes whether the permission dvars values are names or guids | name | name or guid | | cc_permission_mode | Changes whether the permission dvars values are names or guids | name | name or guid |
| cc_permission_default | The default permission level players who aren't found in the permission dvars will be granted | 1 | Any plain number from 0 to `cc_permission_max` | | cc_permission_default | The default permission level players who aren't found in the permission dvars will be granted | 1 | Any plain number from 0 to `cc_permission_max` |
@ -61,6 +62,7 @@ set cc_permission_4 ""
### Notes ### Notes
- To pass an argument with a space you need to put `'` around it. For example if a player name is `The Moonlight` then you would write `!teleport 'The Moonlight' Resxt` - To pass an argument with a space you need to put `'` around it. For example if a player name is `The Moonlight` then you would write `!teleport 'The Moonlight' Resxt`
- If you use [IW4MAdmin](https://github.com/RaidMax/IW4M-Admin) make sure you have a different commands prefix to avoid conflicts. For example `!` for IW4MAdmin commands and `.` for this script. The commands prefix can be modified by changing the value of the `cc_prefix` dvar. As for [IW4MAdmin](https://github.com/RaidMax/IW4M-Admin), at the time of writing, if you want to change it you'll need to change the value of [CommandPrefix](https://github.com/RaidMax/IW4M-Admin/wiki/Configuration#advanced-configuration)
## chat_command_change_team.gsc ## chat_command_change_team.gsc

View File

@ -23,7 +23,6 @@ InitChatCommands()
InitChatCommandsDvars(); InitChatCommandsDvars();
level.chat_commands = []; // don't touch level.chat_commands = []; // don't touch
level.chat_commands["prefix"] = "!"; // the symbol to type before the command name in the chat. Only one character is supported. The slash (/) symbol won't work normally as it's reserved by the game. If you use the slash (/) you will need to type double slash in the game
level.chat_commands["ports"] = ["27016", "27017", "27018"]; // 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"] = ["27016", "27017", "27018"]; // 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"] = ["^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_message"] = ["^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 <level.chat_commands["no_commands_message"]> when printing that specific message in the chat level.chat_commands["no_commands_wait"] = 6; // time to wait between each line in <level.chat_commands["no_commands_message"]> when printing that specific message in the chat
@ -35,6 +34,7 @@ InitChatCommands()
InitChatCommandsDvars() InitChatCommandsDvars()
{ {
SetDvarIfNotInitialized("cc_debug", 0); SetDvarIfNotInitialized("cc_debug", 0);
SetDvarIfNotInitialized("cc_prefix", "!");
SetDvarIfNotInitialized("cc_permission_enabled", 0); SetDvarIfNotInitialized("cc_permission_enabled", 0);
SetDvarIfNotInitialized("cc_permission_mode", "name"); SetDvarIfNotInitialized("cc_permission_mode", "name");
@ -72,11 +72,11 @@ CreateCommand(serverPorts, commandName, commandType, commandValue, commandMinimu
if (commandHelpString == "default_help_one_player") if (commandHelpString == "default_help_one_player")
{ {
commandHelpMessage = ["Example: " + level.chat_commands["prefix"] + commandName + " me", "Example: " + level.chat_commands["prefix"] + commandName + " Resxt"]; commandHelpMessage = ["Example: " + GetDvar("cc_prefix") + commandName + " me", "Example: " + GetDvar("cc_prefix") + commandName + " Resxt"];
} }
else if (commandHelpString == "default_help_two_players") else if (commandHelpString == "default_help_two_players")
{ {
commandHelpMessage = ["Example: " + level.chat_commands["prefix"] + commandName + " me Resxt", "Example: " + level.chat_commands["prefix"] + commandName + " Resxt me", "Example: " + level.chat_commands["prefix"] + commandName + " Resxt Eldor"]; commandHelpMessage = ["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; level.commands[serverPort][commandName]["help"] = commandHelpMessage;
@ -112,12 +112,12 @@ ChatListener()
{ {
level waittill("say", message, player); level waittill("say", message, player);
if (message[0] != level.chat_commands["prefix"]) // For some reason checking for the buggy character doesn't work so we start at the second character if the first isn't the command prefix if (message[0] != GetDvar("cc_prefix")) // For some reason checking for the buggy character doesn't work so we start at the second character if the first isn't the command prefix
{ {
message = GetSubStr(message, 1); // Remove the random/buggy character at index 0, get the real message message = GetSubStr(message, 1); // Remove the random/buggy character at index 0, get the real message
} }
if (message[0] != level.chat_commands["prefix"]) // If the message doesn't start with the command prefix if (message[0] != GetDvar("cc_prefix")) // If the message doesn't start with the command prefix
{ {
continue; // stop continue; // stop
} }
@ -158,7 +158,7 @@ ChatListener()
if (IsDefined(level.commands[GetDvar("net_port")])) if (IsDefined(level.commands[GetDvar("net_port")]))
{ {
if (command == level.chat_commands["prefix"] + "commands") // commands command if (command == GetDvar("cc_prefix") + "commands") // commands command
{ {
if (GetDvarInt("cc_permission_enabled")) if (GetDvarInt("cc_permission_enabled"))
{ {
@ -182,7 +182,7 @@ ChatListener()
else else
{ {
// help command // help command
if (command == level.chat_commands["prefix"] + "help" && !IsDefined(level.commands[GetDvar("net_port")]["help"]) || command == level.chat_commands["prefix"] + "help" && IsDefined(level.commands[GetDvar("net_port")]["help"]) && args.size >= 1) if (command == GetDvar("cc_prefix") + "help" && !IsDefined(level.commands[GetDvar("net_port")]["help"]) || command == GetDvar("cc_prefix") + "help" && IsDefined(level.commands[GetDvar("net_port")]["help"]) && args.size >= 1)
{ {
if (args.size < 1) if (args.size < 1)
{ {
@ -276,7 +276,7 @@ TellPlayer(messages, waitTime, isCommand)
if (IsDefined(isCommand) && isCommand) if (IsDefined(isCommand) && isCommand)
{ {
message = level.chat_commands["prefix"] + message; message = GetDvar("cc_prefix") + message;
} }
self tell(message); self tell(message);
@ -323,7 +323,7 @@ OnPlayerConnect()
CommandDoesNotExistError(commandName) CommandDoesNotExistError(commandName)
{ {
return ["The command " + commandName + " doesn't exist", "Type " + level.chat_commands["prefix"] + "commands to get a list of commands"]; return ["The command " + commandName + " doesn't exist", "Type " + GetDvar("cc_prefix") + "commands to get a list of commands"];
} }
CommandHelpDoesNotExistError(commandName) CommandHelpDoesNotExistError(commandName)