mirror of
https://github.com/Resxt/Plutonium-IW5-Scripts.git
synced 2025-04-19 12:42:54 +00:00
Create chat_commands
This commit is contained in:
parent
c019b4ca84
commit
6d8f87c45d
@ -6,6 +6,22 @@ Simple drag and drop scripts
|
|||||||
|
|
||||||
Change the team names to custom names depending on the game mode
|
Change the team names to custom names depending on the game mode
|
||||||
|
|
||||||
|
## chat_commands.gsc
|
||||||
|
|
||||||
|
Let players execute commands by typing in the command.
|
||||||
|
This has been created for private matches and servers that don't use IW4MAdmin.
|
||||||
|
Since there is no permission check I would recommend deleting the sensitive commands if you run a public server or don't fully trust the people in your private match.
|
||||||
|
|
||||||
|
:white_check_mark: Features available
|
||||||
|
|
||||||
|
- Easy per server (port) commands configuration
|
||||||
|
- Easy text print and functions support
|
||||||
|
- Exceptions handled with error messages (not enough arguments, command doesn't exist etc.)
|
||||||
|
|
||||||
|
:no_entry_sign: Features not available/to add
|
||||||
|
|
||||||
|
- Configure global/all servers commands
|
||||||
|
|
||||||
## disable_damages.gsc
|
## disable_damages.gsc
|
||||||
|
|
||||||
Disable melee knifing damage.
|
Disable melee knifing damage.
|
||||||
|
183
small_scripts/chat_commands.gsc
Normal file
183
small_scripts/chat_commands.gsc
Normal file
@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
==========================================================================
|
||||||
|
| Game: Plutonium IW5 |
|
||||||
|
| Description : Display text and run GSC code |
|
||||||
|
| by typing commands in the chat |
|
||||||
|
| Author: Resxt |
|
||||||
|
==========================================================================
|
||||||
|
| https://github.com/Resxt/Plutonium-IW5-Scripts/tree/main/small_scripts |
|
||||||
|
==========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Init section */
|
||||||
|
|
||||||
|
Init()
|
||||||
|
{
|
||||||
|
InitCommands();
|
||||||
|
|
||||||
|
level thread ChatListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
InitCommands()
|
||||||
|
{
|
||||||
|
level.commands_prefix = "!";
|
||||||
|
|
||||||
|
level.commands["27016"]["rules"] = ["Do not camp", "Do not spawnkill", "Do not disrespect other players"];
|
||||||
|
level.commands["27016"]["suicide"] = ::SuicideCommand;
|
||||||
|
level.commands["27016"]["map"] = ::ChangeMapCommand;
|
||||||
|
level.commands["27016"]["mode"] = ::ChangeModeCommand;
|
||||||
|
level.commands["27016"]["mapmode"] = ::ChangeMapAndModeCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Chat section */
|
||||||
|
|
||||||
|
ChatListener()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
level waittill("say", message, player);
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
continue; // Ignore/skip
|
||||||
|
}
|
||||||
|
|
||||||
|
commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"]
|
||||||
|
command = commandArray[0]; // The command as text. Example: !map
|
||||||
|
args = []; // The arguments passed to the command. Example: ["mp_dome"]
|
||||||
|
|
||||||
|
for (i = 1; i < commandArray.size; i++)
|
||||||
|
{
|
||||||
|
args[args.size] = commandArray[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == level.commands_prefix + "commands")
|
||||||
|
{
|
||||||
|
player thread TellPlayer(GetArrayKeys(level.commands[GetDvar("net_port")]), 2, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandValue = level.commands[GetDvar("net_port")][GetSubStr(command, 1)];
|
||||||
|
|
||||||
|
if (IsDefined(commandValue))
|
||||||
|
{
|
||||||
|
if (IsDefined(commandValue.size))
|
||||||
|
{
|
||||||
|
player thread TellPlayer(commandValue, 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = player [[commandValue]](args);
|
||||||
|
|
||||||
|
if (IsDefined(error))
|
||||||
|
{
|
||||||
|
player thread TellPlayer(error, 1.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player thread TellPlayer(CommandDoesNotExistError(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TellPlayer(messages, waitTime, isCommand)
|
||||||
|
{
|
||||||
|
for (i = 0; i < messages.size; i++)
|
||||||
|
{
|
||||||
|
message = messages[i];
|
||||||
|
|
||||||
|
if (IsDefined(isCommand) && isCommand)
|
||||||
|
{
|
||||||
|
message = level.commands_prefix + message;
|
||||||
|
}
|
||||||
|
|
||||||
|
self tell(message);
|
||||||
|
|
||||||
|
if (i < (messages.size - 1)) // Don't unnecessarily wait after the last message has been displayed
|
||||||
|
{
|
||||||
|
wait waitTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Command functions section */
|
||||||
|
|
||||||
|
SuicideCommand(args)
|
||||||
|
{
|
||||||
|
self Suicide();
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMapCommand(args)
|
||||||
|
{
|
||||||
|
if (args.size < 1)
|
||||||
|
{
|
||||||
|
return NotEnoughArgsError(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMap(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeModeCommand(args)
|
||||||
|
{
|
||||||
|
if (args.size < 1)
|
||||||
|
{
|
||||||
|
return NotEnoughArgsError(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMode(args[0], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMapAndModeCommand(args)
|
||||||
|
{
|
||||||
|
if (args.size < 2)
|
||||||
|
{
|
||||||
|
return NotEnoughArgsError(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMode(args[1], false);
|
||||||
|
ChangeMap(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Logic functions section */
|
||||||
|
|
||||||
|
ChangeMap(mapName)
|
||||||
|
{
|
||||||
|
cmdexec("map " + mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChangeMode(modeName, restart)
|
||||||
|
{
|
||||||
|
cmdexec("load_dsr " + modeName + ";");
|
||||||
|
|
||||||
|
if (restart)
|
||||||
|
{
|
||||||
|
cmdexec("map_restart");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Error functions section */
|
||||||
|
|
||||||
|
CommandDoesNotExistError()
|
||||||
|
{
|
||||||
|
return ["This command doesn't exist", "Type " + level.commands_prefix + "commands" + " to get a list of commands"];
|
||||||
|
}
|
||||||
|
|
||||||
|
NotEnoughArgsError(minimumArgs)
|
||||||
|
{
|
||||||
|
return ["Not enough arguments supplied", "At least " + minimumArgs + " argument expected"];
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user