From 135a45f20bde27d61a9b20434b0d4ee55e0e5b0e Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Tue, 13 Jun 2023 12:53:44 +0200 Subject: [PATCH] chat_command_give 1.0.0 --- chat_commands/README.md | 26 ++++++++ chat_commands/chat_command_give.gsc | 95 +++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 chat_commands/chat_command_give.gsc diff --git a/chat_commands/README.md b/chat_commands/README.md index 527330c..9313fb4 100644 --- a/chat_commands/README.md +++ b/chat_commands/README.md @@ -106,6 +106,32 @@ Note that this does not work during the prematch period. |---| | 3 | +## chat_command_give.gsc + + + +- Give weapon (with or without attachment(s) and camo in MP) + +| Name | Description | Arguments expected | Example | Permission level | +|---|---|---|---|---| +| giveweapon | Gives the targeted player the specific weapon. Attachments and camo can be passed | (1) the name of the player (2) the weapon codename (3) optional, camo index from 0 to 45 | `!giveweapon me tar21_mp` | 2 | + +You can use [chat_command_info.gsc](#chat_command_infogsc) to list available weapons and their attachments. +Alternatively you can use [this](https://forum.plutonium.pw/topic/1909/resource-stat-modification-checks-other-structures) to get weapon/attachment names from your browser. + +| More examples (MP) | +|---| +| `!giveweapon me kard_mp` (give weapon by codename) | +| `!giveweapon me an94` (give weapon by codename without _mp at the end) | +| `!giveweapon me as50_mp+ir` (give weapon by codename with an attachment) | +| `!giveweapon me ballista_mp 15` (give weapon by codename with camo index 15, in this case gold camo) | +| `!giveweapon me dsr50_mp+silencer 16` (give weapon by codename with an attachment and camo index 16, in this case diamond camo) | + +| More examples (ZM) | +|---| +| `!giveweapon me m14_zm` (give weapon by codename) | +| `!giveweapon me m1911_upgraded_zm` (give upgraded/PAPed weapon by codename) | + ## chat_command_god_mode.gsc Toggles whether the targeted player is in god mode (invincible) or not. diff --git a/chat_commands/chat_command_give.gsc b/chat_commands/chat_command_give.gsc new file mode 100644 index 0000000..c97600a --- /dev/null +++ b/chat_commands/chat_command_give.gsc @@ -0,0 +1,95 @@ +#include scripts\chat_commands; + +Init() +{ + CreateCommand(level.chat_commands["ports"], "giveweapon", "function", ::GiveWeaponCommand, 2); +} + + + +/* Command section */ + +GiveWeaponCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = GivePlayerWeapon(args[0], args[1], args[2], true, true); + + if (IsDefined(error)) + { + return error; + } +} + + + +/* Logic section */ + +GivePlayerWeapon(targetedPlayerName, weaponName, camoIndex, takeCurrentWeapon, playSwitchAnimation) +{ + player = FindPlayerByName(targetedPlayerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(targetedPlayerName); + } + + weaponName = ToLower(weaponName); + weaponSplitted = StrTok(weaponName, "+"); + weaponName = weaponSplitted[0]; + attachments = weaponSplitted[1]; + + if (IsMultiplayerMode()) + { + if (GetSubStr(weaponName, weaponName.size - 3, weaponName.size) != "_mp") + { + weaponName += "_mp"; + } + } + + if (!IsValidWeapon(weaponName)) + { + return WeaponDoesNotExistError(weaponName); + } + + finalCamoIndex = 0; + + if (IsDefined(camoIndex)) + { + finalCamoIndex = int(camoIndex); + } + + if (IsDefined(takeCurrentWeapon) && takeCurrentWeapon) + { + player TakeWeapon(player GetCurrentWeapon()); + } + + DoGiveWeapon(weaponName, attachments, finalCamoIndex); + + if (IsDefined(playSwitchAnimation) && playSwitchAnimation) + { + player SwitchToWeapon(weaponName); + } + else + { + player SetSpawnWeapon(weaponName); + } +} + +DoGiveWeapon(weaponCodeName, attachments, camoIndex) +{ + if (IsDefined(attachments) && attachments != "") + { + weaponCodeName = weaponCodeName+ "+" + attachments; + } + + if (!IsDefined(camoIndex)) + { + camoIndex = 0; + } + + self GiveWeapon(weaponCodeName, 0, camoIndex); +} \ No newline at end of file