Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
v1.0
  • Loading branch information
asapverneri committed Sep 11, 2024
1 parent f933dd4 commit 22cd80a
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -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;

}
}
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

<div align="center">
<a href="https://discordapp.com/users/367644530121637888">
<img src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" alt="Discord" />
</a>
<a href="https://steamcommunity.com/id/vvernerii/">
<img src="https://img.shields.io/badge/Steam-000000?style=for-the-badge&logo=steam&logoColor=white" alt="Steam" />
</a>
</div>

---
106 changes: 106 additions & 0 deletions cs2giveweapon.cs
Original file line number Diff line number Diff line change
@@ -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<GiveWeaponConfig>
{
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<string, string> WeaponList = new Dictionary<string, string>
{
{ "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" }
};
}
18 changes: 18 additions & 0 deletions cs2giveweapon.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions cs2giveweapon.sln
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -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."
}

0 comments on commit 22cd80a

Please sign in to comment.