mirror of
https://github.com/Resxt/Plutonium-IW5-Scripts.git
synced 2025-04-19 12:42:54 +00:00
chat_commands 1.1
Allow configuration of the commands prefix Added a function to easily create commands Added the ability to pass an array of server ports instead of just one port per command Added the ability to add a command to all servers using level.commands_servers_ports Fixed the warning when running a function command by explicitly defining whether a command is of type text or function Fixed commands not working when using the say command through the console instead of the chat. Now both works
This commit is contained in:
parent
1e25f5ec14
commit
e235b76ebe
@ -15,6 +15,14 @@
|
|||||||
|
|
||||||
Init()
|
Init()
|
||||||
{
|
{
|
||||||
|
InitChatCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
InitChatCommands()
|
||||||
|
{
|
||||||
|
level.commands_prefix = "!";
|
||||||
|
level.commands_servers_ports = ["27016", "27017"];
|
||||||
|
|
||||||
InitCommands();
|
InitCommands();
|
||||||
|
|
||||||
level thread ChatListener();
|
level thread ChatListener();
|
||||||
@ -22,13 +30,35 @@ Init()
|
|||||||
|
|
||||||
InitCommands()
|
InitCommands()
|
||||||
{
|
{
|
||||||
level.commands_prefix = "!";
|
CreateCommand(["27016"], "rules", "text", ["Do not camp", "Do not spawnkill", "Do not disrespect other players"]);
|
||||||
|
CreateCommand(["27017"], "rules", "text", ["Leave your spot and don't camp after using a M.O.A.B", "Don't leave while being infected", "Do not disrespect other players"]);
|
||||||
|
|
||||||
level.commands["27016"]["rules"] = ["Do not camp", "Do not spawnkill", "Do not disrespect other players"];
|
CreateCommand(level.commands_servers_ports, "suicide", "function", ::SuicideCommand);
|
||||||
level.commands["27016"]["suicide"] = ::SuicideCommand;
|
CreateCommand(level.commands_servers_ports, "map", "function", ::ChangeMapCommand);
|
||||||
level.commands["27016"]["map"] = ::ChangeMapCommand;
|
CreateCommand(level.commands_servers_ports, "mode", "function", ::ChangeModeCommand);
|
||||||
level.commands["27016"]["mode"] = ::ChangeModeCommand;
|
CreateCommand(level.commands_servers_ports, "mapmode", "function", ::ChangeMapAndModeCommand);
|
||||||
level.commands["27016"]["mapmode"] = ::ChangeMapAndModeCommand;
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
<serverPorts> the ports of the servers this command will be created for
|
||||||
|
<commandName> the name of the command, this is what players will type in the chat
|
||||||
|
<commandType> the type of the command: <text> is for arrays of text to display text in the player's chat and <function> is to execute a function
|
||||||
|
*/
|
||||||
|
CreateCommand(serverPorts, commandName, commandType, commandValue)
|
||||||
|
{
|
||||||
|
foreach (serverPort in serverPorts)
|
||||||
|
{
|
||||||
|
level.commands[serverPort][commandName]["type"] = commandType;
|
||||||
|
|
||||||
|
if (commandType == "text")
|
||||||
|
{
|
||||||
|
level.commands[serverPort][commandName]["text"] = commandValue;
|
||||||
|
}
|
||||||
|
else if (commandType == "function")
|
||||||
|
{
|
||||||
|
level.commands[serverPort][commandName]["function"] = commandValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -41,11 +71,14 @@ ChatListener()
|
|||||||
{
|
{
|
||||||
level waittill("say", message, player);
|
level waittill("say", message, player);
|
||||||
|
|
||||||
|
if (message[0] != level.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
|
||||||
|
{
|
||||||
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.commands_prefix) // If the message doesn't start with the command prefix
|
if (message[0] != level.commands_prefix) // If the message doesn't start with the command prefix
|
||||||
{
|
{
|
||||||
continue; // Ignore/skip
|
continue; // stop
|
||||||
}
|
}
|
||||||
|
|
||||||
commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"]
|
commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"]
|
||||||
@ -67,13 +100,13 @@ ChatListener()
|
|||||||
|
|
||||||
if (IsDefined(commandValue))
|
if (IsDefined(commandValue))
|
||||||
{
|
{
|
||||||
if (IsDefined(commandValue.size))
|
if (commandValue["type"] == "text")
|
||||||
{
|
{
|
||||||
player thread TellPlayer(commandValue, 2);
|
player thread TellPlayer(commandValue["text"], 2);
|
||||||
}
|
}
|
||||||
else
|
else if (commandValue["type"] == "function")
|
||||||
{
|
{
|
||||||
error = player [[commandValue]](args);
|
error = player [[commandValue["function"]]](args);
|
||||||
|
|
||||||
if (IsDefined(error))
|
if (IsDefined(error))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user