Skip to content

Commit 55c74f0

Browse files
committed
First upload
1 parent 3d6ce16 commit 55c74f0

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

CS2DropKnife.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using CounterStrikeSharp.API.Core;
2+
using CounterStrikeSharp.API.Modules.Commands;
3+
using CounterStrikeSharp.API.Core.Attributes.Registration;
4+
using CounterStrikeSharp.API;
5+
6+
namespace CS2DropKnife;
7+
8+
public class CS2DropKnife : BasePlugin
9+
{
10+
public override string ModuleName => "CS2 Drop Knife";
11+
12+
public override string ModuleVersion => "0.0.1";
13+
14+
public override void Load(bool hotReload)
15+
{
16+
base.Load(hotReload);
17+
18+
Console.WriteLine("[CS2DropKnife] Registering listeners.");
19+
RegisterListener<Listeners.OnMapStart>(OnMapStartHandler);
20+
}
21+
22+
public void OnMapStartHandler(string map)
23+
{
24+
Server.ExecuteCommand("mp_drop_knife_enable 1");
25+
}
26+
27+
[ConsoleCommand("css_drop", "Drop 5 copies of player's knife on the ground.")]
28+
[CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)]
29+
public void OnPrefireCommand(CCSPlayerController player, CommandInfo commandInfo)
30+
{
31+
// Player might not be alive.
32+
if (player.PlayerPawn?.Value == null || player.PlayerPawn?.Value.WeaponServices == null || player.PlayerPawn?.Value.ItemServices == null)
33+
return;
34+
35+
var weapons = player.PlayerPawn.Value.WeaponServices?.MyWeapons;
36+
37+
// Player might have no weapon.
38+
if (weapons == null) return;
39+
40+
// Find the knife.
41+
foreach (var weapon in weapons)
42+
{
43+
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
44+
{
45+
if (weapon.Value.DesignerName.Contains("knife") || weapon.Value.DesignerName.Contains("bayonet"))
46+
{
47+
Console.WriteLine("[CS2DropKnife] knife index = " + weapon.Index + ", entityindex = " + weapon.Value.Index + ", designer name = " + weapon.Value.DesignerName);
48+
for (int i = 0; i < 5; i++)
49+
player.GiveNamedItem(weapon.Value.DesignerName);
50+
return;
51+
}
52+
}
53+
}
54+
55+
player.PrintToChat("[CS2DropKnife] Can't find a knife on you. Get one and try again please.");
56+
}
57+
}

CS2DropKnife.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<Reference Include="CounterStrikeSharp.API">
11+
<HintPath>../addons/counterstrikesharp/api/CounterStrikeSharp.API.dll</HintPath>
12+
</Reference>
13+
</ItemGroup>
14+
15+
</Project>

CS2DropKnife.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CS2DropKnife", "CS2DropKnife.csproj", "{267801C3-1AC7-4788-B317-3AF94D85FAAF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{267801C3-1AC7-4788-B317-3AF94D85FAAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{267801C3-1AC7-4788-B317-3AF94D85FAAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{267801C3-1AC7-4788-B317-3AF94D85FAAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{267801C3-1AC7-4788-B317-3AF94D85FAAF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {A51B1C9B-5091-4841-91E8-56E7799B4F07}
24+
EndGlobalSection
25+
EndGlobal

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# CS2DropKnife
22
A server-side CS2 plugin powered by CounterStrikeSharp that allows player to share their knife with others.
3+
4+
## How to install
5+
6+
Install CounterStrikeSharp first. Extract the folder you get from [Release](https://github.com/lengran/CS2DropKnife/releases) to the counterstrikesharp/plugins folder.
7+
8+
## How to use
9+
10+
As long as you have a knife equipped, type "!drop" in the chat box and you should see 5 of your knives dropped on the ground.
11+
12+
Note: This plugin might not respond to console "say" or "say_team" commands for now. So your drop bind might not work. Just type it yourself.

0 commit comments

Comments
 (0)