diff --git a/Config.cs b/Config.cs new file mode 100644 index 0000000..b1b69be --- /dev/null +++ b/Config.cs @@ -0,0 +1,19 @@ +using CounterStrikeSharp.API.Core; +using System.Text.Json.Serialization; + +namespace GiveWeapon +{ + public class GiveWeaponConfig : BasePluginConfig + { + + [JsonPropertyName("AccessFlag")] + public string AccessFlag { get; set; } = "@css/generic"; + + [JsonPropertyName("Command")] + public string Command { get; set; } = "css_weapon"; + + [JsonPropertyName("DropActiveWeapon")] + public bool DropActiveWeapon { get; set; } = false; + + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a62223c --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +## 🎮 CS2 GiveWeapon + +Simple plugin to give weapon easily by command. It has english language, but if you want you can translate it to any language. +Tested on Windows, but should work on Linux aswell. + + +![GitHub tag (with filter)](https://img.shields.io/github/v/tag/asapverneri/CS2-BotQuotaManager?style=for-the-badge&label=Version) + +> [!CAUTION] +> This is WIP. + +--- + +## 📦 Installion + +- Install [CounterStrike Sharp](https://github.com/roflmuffin/CounterStrikeSharp) & [Metamod:Source](https://www.sourcemm.net/downloads.php/?branch=master) +- Download the latest release from the releases tab and copy it into the counterstrikesharp plugins folder. +The config is generated after the first start of the plugin. + +--- + +## 💻 Usage + +To edit permission and database settings please edit config file. +Located in the folder `counterstrikesharp/configs/plugins/cs2giveweapon` + +You can customize couple of things in config. + +**Example config:** +```json +{ + "AccessFlag": "@css/generic", + "Command": "css_weapon", + "DropActiveWeapon": false, + "ConfigVersion": 1 +} +``` +--- + +## 📫 Contact + +
+ + Discord + + + Steam + +
+ +--- \ No newline at end of file diff --git a/cs2giveweapon.cs b/cs2giveweapon.cs new file mode 100644 index 0000000..64c1881 --- /dev/null +++ b/cs2giveweapon.cs @@ -0,0 +1,106 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using Microsoft.Extensions.Logging; + +namespace GiveWeapon; + + +public class GiveWeapon : BasePlugin, IPluginConfig +{ + public override string ModuleName => "GiveWeapon"; + public override string ModuleDescription => "Give weapon by command"; + public override string ModuleAuthor => "verneri"; + public override string ModuleVersion => "1.0"; + + public GiveWeaponConfig Config { get; set; } = new(); + + public void OnConfigParsed(GiveWeaponConfig config) + { + Config = config; + } + + public override void Load(bool hotReload) + { + Logger.LogInformation($"Loaded (version {ModuleVersion})"); + AddCommand($"{Config.Command}", "give weapon", WeaponCommand); + } + + public void WeaponCommand(CCSPlayerController? player, CommandInfo command) + { + if (!AdminManager.PlayerHasPermissions(player, Config.AccessFlag)) + { + command.ReplyToCommand($"{Localizer["no.access", Config.AccessFlag]}"); + return; + } + + if (player != null) + { + string inputWeaponName = command.ArgByIndex(1)?.ToLower(); + string? matchedWeapon = null; + + + foreach (var weapon in WeaponList) + { + if (weapon.Key.ToLower().Contains(inputWeaponName)) + { + matchedWeapon = weapon.Value; + break; + } + } + + if (matchedWeapon != null) + { + if (Config.DropActiveWeapon) { + player.DropActiveWeapon(); + } + player.GiveNamedItem(matchedWeapon); + command.ReplyToCommand($"{Localizer["weapon.given", matchedWeapon]}"); + } + else + { + command.ReplyToCommand($"{Localizer["weapon.invalid", inputWeaponName]}"); + } + } + } + + private static readonly Dictionary WeaponList = new Dictionary + { + { "m4a4", "weapon_m4a1" }, + { "m4a1", "weapon_m4a1_silencer" }, + { "famas", "weapon_famas" }, + { "aug", "weapon_aug" }, + { "ak47", "weapon_ak47" }, + { "galil", "weapon_galilar" }, + { "sg556", "weapon_sg556" }, + { "scar20", "weapon_scar20" }, + { "awp", "weapon_awp" }, + { "ssg08", "weapon_ssg08" }, + { "g3sg1", "weapon_g3sg1" }, + { "mp9", "weapon_mp9" }, + { "mp7", "weapon_mp7" }, + { "mp5sd", "weapon_mp5sd" }, + { "ump45", "weapon_ump45" }, + { "p90", "weapon_p90" }, + { "bizon", "weapon_bizon" }, + { "mac10", "weapon_mac10" }, + { "usp", "weapon_usp_silencer" }, + { "p2000", "weapon_hkp2000" }, + { "glock", "weapon_glock" }, + { "elite", "weapon_elite" }, + { "p250", "weapon_p250" }, + { "fiveseven", "weapon_fiveseven" }, + { "cz75a", "weapon_cz75a" }, + { "tec9", "weapon_tec9" }, + { "revolver", "weapon_revolver" }, + { "deagle", "weapon_deagle" }, + { "nova", "weapon_nova" }, + { "xm1014", "weapon_xm1014" }, + { "mag7", "weapon_mag7" }, + { "sawedoff", "weapon_sawedoff" }, + { "m249", "weapon_m249" }, + { "negev", "weapon_negev" }, + { "taser", "weapon_taser" }, + { "zeus", "weapon_taser" } + }; +} \ No newline at end of file diff --git a/cs2giveweapon.csproj b/cs2giveweapon.csproj new file mode 100644 index 0000000..1371a75 --- /dev/null +++ b/cs2giveweapon.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + true + + + + + + + + + + + diff --git a/cs2giveweapon.sln b/cs2giveweapon.sln new file mode 100644 index 0000000..2a958b1 --- /dev/null +++ b/cs2giveweapon.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cs2giveweapon", "cs2giveweapon.csproj", "{277F5D46-95F6-44AA-94F3-3790F76D81AB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {277F5D46-95F6-44AA-94F3-3790F76D81AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {277F5D46-95F6-44AA-94F3-3790F76D81AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {277F5D46-95F6-44AA-94F3-3790F76D81AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {277F5D46-95F6-44AA-94F3-3790F76D81AB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {86FF8256-3B63-429C-A01F-62080E9AFE37} + EndGlobalSection +EndGlobal diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..9a20f53 --- /dev/null +++ b/lang/en.json @@ -0,0 +1,6 @@ +{ + "no.access": "{green}[GiveWeapon] {red} You don't have access to this command. Please ensure you have {0} permission.", + + "weapon.given": "{green}[GiveWeapon] {lime} {0} given.", + "weapon.invalid": "{green}[GiveWeapon] {red} {0} is invalid, please try again." +} \ No newline at end of file