这节课续上一节课的内容
请转到
[C#cs2插件]入门编译教程(开始编写你的第一个cs2插件)[第一课,安装环境]-编程开发-CSGO插件分享-CSGO资料库 (csgocn.net)
----------------------------------------------------------
一、打开我们的(CS2插件)文件夹
![](upload/attach/202405/359_BVH8AW9GQSH4DRX.png)
在此地方输入:cmd
![](upload/attach/202405/359_6RJ4F9A4SUDBRQZ.png)
出现窗口:
![](upload/attach/202405/359_ZRZHPAFVXHFJSY3.png)
现在输入
dotnet new classlib --name "文件夹名字"
我就创建Hello World插件
dotnet new classlib --name HelloWorld
![](upload/attach/202405/359_HH4ACXTF32AH6NE.png)
就出现了
![](upload/attach/202405/359_WAPN43VK7XRQSE3.png)
我们点进去,双击此文件:
![](upload/attach/202405/359_GMZJC9ZKJA3YZTM.png)
就会进入(顺便双击)
![](upload/attach/202405/359_DFYQ679JFNYZM4G.png)
----------------------------------------------------------
二、引用配置API
[counterstrikesharp.api]
双击
![](upload/attach/202405/359_E97K6SZ4VDZZUPH.png)
在此处加上一些内容
![](upload/attach/202405/359_HW82FMG4PTKNBRR.png)
/////////////////////////////////////////////////////////////////////
<ItemGroup>
<Reference Include="CounterStrikeSharp.API">
<HintPath></HintPath>
</Reference>
</ItemGroup>
/////////////////////////////////////////////////////////////////////
![](upload/attach/202405/359_JG4UNKFC5MR9JXA.png)
然后:
![](upload/attach/202405/359_N372SQJKSV3GAFQ.png)
我们回到我们的CS2插件文件夹
![](upload/attach/202405/359_2DFDXS22CGVTRJZ.png)
接下来按照红标的点击即可
![](upload/attach/202405/359_BZQT9P54RX3G2CG.png)
![](upload/attach/202405/359_Z5Q9MW99SYJYY35.png)
![](upload/attach/202405/359_AEYA9BAKZFF6Q24.png)
![](upload/attach/202405/359_8SPBH2CUH425MPA.png)
这里就是我们需要寻找的路径了:
复制粘贴
![](upload/attach/202405/359_5QDMMTVFU3UZV5C.png)
C:\Users\34397\Desktop\cs2插件\addons\counterstrikesharp\api
在加上API的dll
C:\Users\34397\Desktop\cs2插件\addons\counterstrikesharp\api\CounterStrikeSharp.API.dll
将这串路径复制粘贴到这个位置:
![](upload/attach/202405/359_Z54A5W9V7F5HAT6.png)
![](upload/attach/202405/359_5ZBFK8V6767BT7Y.png)
但是我们还需要把"\" 改成"/"
![](upload/attach/202405/359_BAWAKRYRZ3XYGP6.png)
接下来Ctrl + S 保存
配置API完成
----------------------------------------------------------
![](upload/attach/202405/359_AE57AUQR2SZKHB5.png)
在这里我们可以发现API已经装载完成!!!!!
我们可以双击查看:
![](upload/attach/202405/359_QZTK7HTVZR83DPR.png)
![](upload/attach/202405/359_JW43H9YN6SPE6TK.png)
![](upload/attach/202405/359_BGTAFMD7QREXJWA.png)
能看到许多方法的使用(后面自己理解)我只教入门
----------------------------------------------------------
现在双击Class1.cs
![](upload/attach/202405/359_Y8FWPNHEC6PVA8F.png)
编写HelloWorld
//复制粘贴以下内容
using CounterStrikeSharp.API.Core;
namespace HelloWorld;
public class HelloWorld : BasePlugin
{
public override string ModuleName => "HelloWorld";
public override string ModuleVersion => "0.0.1";
public override void Load(bool hotReload)
{
Console.WriteLine("Hello World!");
}
}
![](upload/attach/202405/359_Z4U9YMCDJH5HRVU.png)
接下来我们把插件进行编译:
右键此处!!!
![](upload/attach/202405/359_EHXKR8KFN9VF3Z2.png)
点击生成!!!!
![](upload/attach/202405/359_WNJ79X3KDF3PXVR.png)
我们的插件已经成功编译
![](upload/attach/202405/359_XNKRZ5MKQW4RVK2.png)
接下来打开我们的(cs2插件)文件夹
![](upload/attach/202405/359_UY3E4A9BCM5AFBM.png)
![](upload/attach/202405/359_88FZM3XCSZFJZBV.png)
![](upload/attach/202405/359_5C94FGBA2TCE2YS.png)
![](upload/attach/202405/359_48K8H9EW6UZAU83.png)
![](upload/attach/202405/359_XXKVSHDCX9FCW4K.png)
这三个就是我们的插件了
![](upload/attach/202405/359_9CDZU67RYX7N4J3.png)
----------------------------------------------------------