From 74db6e37c59d08522f2927715c3d0e3ed371c955 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Tue, 21 Mar 2023 03:05:02 +0100 Subject: [PATCH] chat_command_points 1.0.0 --- chat_commands/zm/README.md | 17 +++++ chat_commands/zm/chat_command_points.gsc | 97 ++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 chat_commands/zm/README.md create mode 100644 chat_commands/zm/chat_command_points.gsc diff --git a/chat_commands/zm/README.md b/chat_commands/zm/README.md new file mode 100644 index 0000000..6e5ee68 --- /dev/null +++ b/chat_commands/zm/README.md @@ -0,0 +1,17 @@ +# ZM Chat commands + +These scripts go in `scripts\zm` + +## chat_command_points.gsc + +3 related commands in one file: + +- Set points +- Add points +- Take/remove points + +| Name | Description | Arguments expected | Example | Permission level | +|---|---|---|---|---| +| setpoints | Changes of much points the targeted player has | (1) the name of the targeted player (2) the new amount of points to set | `!setpoints me 50000` | 3 | +| addpoints | Gives points to the targeted player | (1) the name of the targeted player (2) the amount of points to give | `!addpoints Resxt 2500` | 3 | +| takepoints | Takes/removes points from the targeted player | (1) the name of the targeted player (2) the amount of points to take from the player | `!takepoints Resxt 500` | 3 | diff --git a/chat_commands/zm/chat_command_points.gsc b/chat_commands/zm/chat_command_points.gsc new file mode 100644 index 0000000..ad3e98f --- /dev/null +++ b/chat_commands/zm/chat_command_points.gsc @@ -0,0 +1,97 @@ +#include scripts\chat_commands; + +Init() +{ + CreateCommand(level.chat_commands["ports"], "setpoints", "function", ::SetPointsCommand, 3); + CreateCommand(level.chat_commands["ports"], "addpoints", "function", ::AddPointsCommand, 3); + CreateCommand(level.chat_commands["ports"], "takepoints", "function", ::TakePointsCommand, 3); +} + + + +/* Command section */ + +SetPointsCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = SetPlayerPoints(args[0], args[1]); + + if (IsDefined(error)) + { + return error; + } +} + +AddPointsCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = AddPlayerPoints(args[0], args[1]); + + if (IsDefined(error)) + { + return error; + } +} + +TakePointsCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = TakePlayerPoints(args[0], args[1]); + + if (IsDefined(error)) + { + return error; + } +} + + + +/* Logic section */ + +SetPlayerPoints(playerName, points) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + player.score = int(points); +} + +AddPlayerPoints(playerName, points) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + player.score += int(points); +} + +TakePlayerPoints(playerName, points) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + player.score -= int(points); +} \ No newline at end of file