From 5aa2ea361add08eccaaaa00586e699b7a513db22 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Sat, 18 Mar 2023 02:01:18 +0100 Subject: [PATCH] chat_command_permissions 1.0.0 --- chat_commands/README.md | 12 ++++ chat_commands/chat_command_permissions.gsc | 76 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 chat_commands/chat_command_permissions.gsc diff --git a/chat_commands/README.md b/chat_commands/README.md index d582d8b..c596f1d 100644 --- a/chat_commands/README.md +++ b/chat_commands/README.md @@ -228,6 +228,18 @@ Toggles norecoil on the targeted player |---| | 3 | +## chat_command_permissions.gsc + +2 related commands in one file: + +- Get permission level +- Set permission level + +| Name | Description | Arguments expected | Example | Permission level | +|---|---|---|---|---| +| getpermission | Prints the target player's current permission level in the player's chat | (1) the name of the targeted player | `!getpermission me` | 2 | +| setpermission | Changes the targeted player's permission level | (1) the name of the targeted player (2) the permission level to grant | `!setpermission Resxt 4` | 4 | + ## chat_command_suicide.gsc The player who runs the command dies. diff --git a/chat_commands/chat_command_permissions.gsc b/chat_commands/chat_command_permissions.gsc new file mode 100644 index 0000000..6a0bdde --- /dev/null +++ b/chat_commands/chat_command_permissions.gsc @@ -0,0 +1,76 @@ +#include scripts\chat_commands; + +Init() +{ + CreateCommand(level.chat_commands["ports"], "getpermission", "function", ::GetPlayerPermissionCommand, 2); + CreateCommand(level.chat_commands["ports"], "setpermission", "function", ::SetPlayerPermissionCommand, 4); +} + + + +/* Command section */ + +GetPlayerPermissionCommand(args) +{ + if (args.size < 1) + { + return NotEnoughArgsError(1); + } + + error = GetPlayerPermission(args[0]); + + if (IsDefined(error)) + { + return error; + } +} + +SetPlayerPermissionCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = SetPlayerPermission(args[0], args[1]); + + if (IsDefined(error)) + { + return error; + } +} + + + +/* Logic section */ + +GetPlayerPermission(playerName) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + self thread TellPlayer(["^5" + player.name + " ^7permission level is ^5" + player GetPlayerPermissionLevel()], 1); +} + +SetPlayerPermission(playerName, newPermissionLevel) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + newPermissionLevel = int(newPermissionLevel); + + if (newPermissionLevel < 0 || newPermissionLevel > GetDvarInt("cc_permission_max")) + { + return InvalidPermissionLevelError(newPermissionLevel); + } + + player SetPlayerPermissionLevel(newPermissionLevel); +} \ No newline at end of file