Skip to content

Commit 04d86e8

Browse files
feature(load config)
new feature: 1.can load config where you can enable or disable modes and define vars in these modes. 2.can load custom console-only modes
1 parent 1a7c544 commit 04d86e8

10 files changed

+289
-75
lines changed

CustomModesConfig.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace FunMatchPlugin;
2+
3+
public class CustomModeInfo
4+
{
5+
public string Decr {get;set;}
6+
public string Fun_cfgfilename {get;set;}
7+
public string Endfun_cfgfilename {get;set;}
8+
}
9+
10+
public class CustomModesConfig
11+
{
12+
public List<CustomModeInfo> Modes{get;set;}
13+
}

FunCustomConsoleMode.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using CounterStrikeSharp.API;
2+
using CounterStrikeSharp.API.Core.Translations;
3+
4+
namespace FunMatchPlugin;
5+
6+
public class FunCustomConsoleMode : FunBaseClass
7+
{
8+
public string DecriptionCustom;
9+
private string CFGLoadFile;
10+
private string CFGUnLoadFile;
11+
public override string Decription => "Custom Modes";
12+
13+
public FunCustomConsoleMode(string decr,string loadFile, string unLoadFile)
14+
{
15+
DecriptionCustom = decr;
16+
CFGLoadFile = loadFile;
17+
CFGUnLoadFile = unLoadFile;
18+
}
19+
20+
public override void EndFun(FunMatchPlugin plugin)
21+
{
22+
Enabled = false;
23+
Server.ExecuteCommand("exec " + CFGUnLoadFile);
24+
}
25+
26+
public override void Fun(FunMatchPlugin plugin)
27+
{
28+
if (Enabled == true) return;
29+
Enabled = true;
30+
Server.ExecuteCommand("exec " + CFGLoadFile);
31+
}
32+
public override void DisPlayHelp()
33+
{
34+
Server.PrintToChatAll(StringExtensions.ReplaceColorTags("{RED}") + "[FunMatchPlugin] " + DecriptionCustom);
35+
}
36+
}

FunMatchPlugin.cs

Lines changed: 131 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,148 @@
33
using CounterStrikeSharp.API;
44
using CounterStrikeSharp.API.Modules.Commands;
55
using CounterStrikeSharp.API.Modules.Admin;
6+
using System.Text.Json;
67

78
namespace FunMatchPlugin;
89

9-
public class FunMatchPlugin: BasePlugin
10+
public class FunMatchPlugin: BasePlugin , IPluginConfig<FunMatchPluginConfig>
1011
{
1112
public override string ModuleName => "Fun Match Plugin";
12-
public override string ModuleVersion => "1.0.7";
13+
public override string ModuleVersion => "1.0.8";
14+
public FunMatchPluginConfig Config {get;set;} = new();
1315
public override void Load(bool hotReload)
1416
{
1517
Console.WriteLine("Fun Match Plugin Load!");
16-
FunBulletTeleport funBulletTeleport = new (this);
17-
FunLists.Add(funBulletTeleport);
18-
FunHealTeammates funHealTeammates = new (this);
19-
FunLists.Add(funHealTeammates);
20-
FunHealthRaid funHealthRaid = new (this);
21-
FunLists.Add(funHealthRaid);
22-
FunHighHP funHighHP = new (this);
23-
FunLists.Add(funHighHP);
24-
FunInfiniteGrenade funFunInfiniteGrenade = new (this);
25-
FunLists.Add(funFunInfiniteGrenade);
26-
FunJumpOrDie funJumpOrDie = new(this);
27-
FunLists.Add(funJumpOrDie);
28-
FunNoClip funNoClip = new (this);
29-
FunLists.Add(funNoClip);
30-
FunPlayerShootExChange funPlayerShootExChange = new (this);
31-
FunLists.Add(funPlayerShootExChange);
32-
FunToTheMoon funToTheMoon = new(this);
33-
FunLists.Add(funToTheMoon);
34-
FunWNoStop funWNoStop = new (this);
35-
FunLists.Add(funWNoStop);
36-
FunDropWeaponOnShoot funDropWeaponOnShoot = new();
37-
FunLists.Add(funDropWeaponOnShoot);
38-
FunChangeWeaponOnShoot funChangeWeaponOnShoot = new();
39-
FunLists.Add(funChangeWeaponOnShoot);
18+
InstallFun(Config);
19+
InstallCustomModes();
4020
//FunC4EveryWhere funC4EveryWhere = new(this);
4121
//FunLists.Add(funC4EveryWhere);
4222
}
23+
public void OnConfigParsed(FunMatchPluginConfig config)
24+
{
25+
Console.WriteLine("Parsing config");
26+
Config = config;
27+
}
28+
29+
private void InstallCustomModes()
30+
{
31+
var configdirectory = Path.Combine(Application.RootDirectory, "configs/plugins/FunMatchPlugin");
32+
if (!Path.Exists(configdirectory)) Directory.CreateDirectory(configdirectory);
33+
var configpath = Path.Combine(configdirectory,"CustomModes.json");
34+
if (!File.Exists(configpath)) return;
35+
36+
var dir_addons = Directory.GetParent(Application.RootDirectory);
37+
var dir_csgo = Directory.GetParent(dir_addons!.FullName);
38+
var path_cfg = Path.Combine(dir_csgo!.FullName,"cfg");
39+
40+
using (StreamReader r = new StreamReader(configpath))
41+
{
42+
string json = r.ReadToEnd();
43+
CustomModesConfig customModesConfig = JsonSerializer.Deserialize<CustomModesConfig>(json)!;
44+
foreach (var mode in customModesConfig.Modes)
45+
{
46+
var fun_cfg_game = Path.Combine(path_cfg,mode.Fun_cfgfilename);
47+
var fun_cfg_config = Path.Combine(configdirectory,mode.Fun_cfgfilename);
48+
var endfun_cfg_game = Path.Combine(path_cfg,mode.Endfun_cfgfilename);
49+
var endfun_cfg_config = Path.Combine(configdirectory,mode.Endfun_cfgfilename);
50+
File.Copy(fun_cfg_config,fun_cfg_game,true);
51+
File.Copy(endfun_cfg_config,endfun_cfg_game,true);
52+
FunLists.Add(new FunCustomConsoleMode(mode.Decr,mode.Fun_cfgfilename,mode.Endfun_cfgfilename));
53+
}
54+
}
55+
}
56+
57+
private void InstallFun(FunMatchPluginConfig config)
58+
{
59+
if (config.IsFunBulletTeleportOn)
60+
{
61+
FunBulletTeleport funBulletTeleport = new (this);
62+
FunLists.Add(funBulletTeleport);
63+
}
64+
if (config.IsFunHealTeammatesOn)
65+
{
66+
FunHealTeammates funHealTeammates = new(this)
67+
{
68+
BurnAfterSecond = config.FunHealTeammatesBurnAfterSecond,
69+
BurnDamage = config.FunHealTeammatesBurnDamage,
70+
HealValue = config.FunHealTeammatesHealValue,
71+
};
72+
FunLists.Add(funHealTeammates);
73+
}
74+
if (config.IsFunHealthRaidOn)
75+
{
76+
FunHealthRaid funHealthRaid = new (this)
77+
{
78+
initHP = config.FunHealthRaidinitHP,
79+
maxRaid = config.FunHealthRaidmaxRaid,
80+
RaidScale = config.FunHealthRaidScale,
81+
};
82+
FunLists.Add(funHealthRaid);
83+
}
84+
if (config.IsFunHighHPOn)
85+
{
86+
FunHighHP funHighHP = new (this)
87+
{
88+
maxHP = config.FunHighHPmaxHP,
89+
armor = config.FunHighHParmor,
90+
};
91+
FunLists.Add(funHighHP);
92+
}
93+
if (config.IsFunInfiniteGrenadeOn)
94+
{
95+
FunInfiniteGrenade funFunInfiniteGrenade = new (this);
96+
FunLists.Add(funFunInfiniteGrenade);
97+
}
98+
if (config.IsFunJumpOrDieOn)
99+
{
100+
FunJumpOrDie funJumpOrDie = new(this)
101+
{
102+
BurnAfterSecond = config.FunJumpOrDieBurnAfterSecond,
103+
BurnDamage = config.FunJumpOrDieBurnDamage,
104+
};
105+
FunLists.Add(funJumpOrDie);
106+
}
107+
if (config.IsFunNoClipOn)
108+
{
109+
FunNoClip funNoClip = new (this){
110+
interval = config.FunNoClipinterval,
111+
};
112+
FunLists.Add(funNoClip);
113+
}
114+
if (config.IsFunPlayerShootExChangeOn)
115+
{
116+
FunPlayerShootExChange funPlayerShootExChange = new (this);
117+
FunLists.Add(funPlayerShootExChange);
118+
}
119+
if (config.IsFunToTheMoonOn)
120+
{
121+
FunToTheMoon funToTheMoon = new(this)
122+
{
123+
gravity = config.FunToTheMoongravity,
124+
BulletGiveAbsV = config.FunToTheMoonBulletGiveAbsV,
125+
};
126+
FunLists.Add(funToTheMoon);
127+
}
128+
if (config.IsFunWNoStopOn)
129+
{
130+
FunWNoStop funWNoStop = new (this)
131+
{
132+
BurnAfterSecond = config.FunWNoStopBurnAfterSecond,
133+
BurnDamage = config.FunWNoStopBurnDamage,
134+
};
135+
FunLists.Add(funWNoStop);
136+
}
137+
if (config.IsFunDropWeaponOnShootOn)
138+
{
139+
FunDropWeaponOnShoot funDropWeaponOnShoot = new();
140+
FunLists.Add(funDropWeaponOnShoot);
141+
}
142+
if (config.IsFunChangeWeaponOnShootOn)
143+
{
144+
FunChangeWeaponOnShoot funChangeWeaponOnShoot = new();
145+
FunLists.Add(funChangeWeaponOnShoot);
146+
}
147+
}
43148

44149
public void LoadRandomFun()
45150
{

FunMatchPluginConfig.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Text.Json.Serialization;
2+
using CounterStrikeSharp.API.Core;
3+
using CounterStrikeSharp.API.Core.Attributes;
4+
5+
namespace FunMatchPlugin;
6+
public class FunMatchPluginConfig : BasePluginConfig
7+
{
8+
[JsonPropertyName("BulletTeleport")] public bool IsFunBulletTeleportOn { get; set; } = true;
9+
[JsonPropertyName("ChangeWeaponOnShoot")] public bool IsFunChangeWeaponOnShootOn { get; set; } = true;
10+
[JsonPropertyName("FunDropWeaponOnShoot")] public bool IsFunDropWeaponOnShootOn { get; set; } = true;
11+
[JsonPropertyName("FunHealTeammates")] public bool IsFunHealTeammatesOn { get; set; } = true;
12+
[JsonPropertyName("FunHealTeammatesBurnAfterSecond")] public float FunHealTeammatesBurnAfterSecond { get; set; } = 1.0f;
13+
[JsonPropertyName("FunHealTeammatesBurnDamage")] public int FunHealTeammatesBurnDamage { get; set; } = 5;
14+
[JsonPropertyName("FunHealTeammatesHealValue")] public int FunHealTeammatesHealValue { get; set; } = 10;
15+
[JsonPropertyName("FunHealthRaid")] public bool IsFunHealthRaidOn { get; set; } = true;
16+
[JsonPropertyName("FunHealthRaidinitHP")] public int FunHealthRaidinitHP { get; set; } = 100;
17+
[JsonPropertyName("FunHealthRaidmaxRaid")] public int FunHealthRaidmaxRaid { get; set; } = 100;
18+
[JsonPropertyName("FunHealthRaidScale")] public float FunHealthRaidScale { get; set; } = 0.5f;
19+
[JsonPropertyName("FunHighHP")] public bool IsFunHighHPOn { get; set; } = true;
20+
[JsonPropertyName("FunHighHPmaxHP")] public int FunHighHPmaxHP { get; set; } = 1000;
21+
[JsonPropertyName("FunHighHParmor")] public int FunHighHParmor { get; set; } = 200;
22+
[JsonPropertyName("FunInfiniteGrenade")] public bool IsFunInfiniteGrenadeOn { get; set; } = true;
23+
[JsonPropertyName("FunJumpOrDie")] public bool IsFunJumpOrDieOn { get; set; } = true;
24+
[JsonPropertyName("FunJumpOrDieBurnAfterSecond")] public float FunJumpOrDieBurnAfterSecond { get; set; } = 1.0f;
25+
[JsonPropertyName("FunJumpOrDieBurnDamage")] public int FunJumpOrDieBurnDamage { get; set; } = 5;
26+
[JsonPropertyName("FunNoClip")] public bool IsFunNoClipOn { get; set; } = true;
27+
[JsonPropertyName("FunNoClipinterval")] public float FunNoClipinterval { get; set; } = 2.0f;
28+
[JsonPropertyName("FunPlayerShootExChange")] public bool IsFunPlayerShootExChangeOn { get; set; } = true;
29+
[JsonPropertyName("FunToTheMoon")] public bool IsFunToTheMoonOn { get; set; } = true;
30+
[JsonPropertyName("FunToTheMoongravity")] public float FunToTheMoongravity { get; set; } = (float)(800 * 0.166);
31+
[JsonPropertyName("FunToTheMoonBulletGiveAbsV")] public float FunToTheMoonBulletGiveAbsV { get; set; } = 100;
32+
[JsonPropertyName("FunWNoStop")] public bool IsFunWNoStopOn { get; set; } = true;
33+
[JsonPropertyName("FunWNoStopBurnAfterSecond")] public float FunWNoStopBurnAfterSecond { get; set; } = 0.5f;
34+
[JsonPropertyName("FunWNoStopBurnDamage")] public int FunWNoStopBurnDamage { get; set; } = 2;
35+
}

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@ a showmatch like plugin for fun
55

66
### random fun mode every round 每回合随机一种娱乐模式
77

8+
### enable or disable modes in config 可配置各个模式是否启用 配置模式参数
9+
10+
### custom console-only(.cfg) modes loading 可自定义仅控制台命令的模式
11+
812
## Avaliable Fun/Mode 当前可使用的娱乐模式
913

1014
### Bullet Teleport 瞬移子弹
1115
### HealTeammates 攻击治疗队友
16+
get hurt continually, your teammates can heal you.
1217
持续受到伤害 只有队友能帮你活下去
1318
### Health Raid 攻击吸血
1419
### 1000 Hp 1000血量
1520
### Infinite Grenades 无限手雷
1621
### Jump Or Die 地板烫脚
22+
if you don't jump, you will get hurt.
1723
不跳就会收到伤害
1824
### NoClip On 启用飞行穿墙
25+
will noclip on for a while.
26+
每隔一段时间切换一次状态 包点无法起飞
1927
### Shoot Exchange 换位子弹
2028
### To The Moon 月球模式
21-
低重力 且有一定后坐力
29+
low gravity, counterforce enabled (like that in space).
30+
低重力 射击会有一定反作用力
2231
### WNoStop 按住W不松手
2332
if you don't forward, you will get hurt.
24-
不向前则会收到伤害
33+
不按住w则会收到伤害
2534
### Change Weapon ONShoot 射击换枪
2635
### Drop Weapon ONShoot 射击丢枪
2736

@@ -43,6 +52,17 @@ see [https://docs.cssharp.dev/docs/guides/getting-started.html](https://docs.css
4352

4453
`!fun_random` will not load any random mode per round automaticly 停用每回合随机模式 @css/root required
4554

46-
`fun_load [num]` load certain mode by num (num can be found in command "funlists") won't affect random load 手动加载模式 对应的数字可以在"funlists"指令查到 与随机模式独立 @css/root required
55+
`fun_load [num]` load certain mode by num (num can be found in command "fun_lists") won't affect random load 手动加载模式 对应的数字可以在"funlists"指令查到 与随机模式独立 @css/root required
56+
57+
`!fun_load` Unload mode you manually load (num can be found in command "fun_lists") 卸载手动加载的模式 @css/root required
58+
59+
## Config 插件配置
60+
61+
if you would like to configurate something, pls put config here 修改模式默认配置 请将配置文件放在此文件夹
62+
...\Counter-Strike Global Offensive\game\csgo\addons\counterstrikesharp\configs\plugins\FunMatchPlugin
63+
64+
`FunMatchPlugin.json` will configure enable or disable modes and how modes work. 该文件会配置是否启用特定模式,特定模式的参数
4765

48-
`!fun_load` Unload mode you manually load (num can be found in command "funlists") 卸载手动加载的模式 @css/root required
66+
`CustomModes.json` will add new custom console-only mode to this plugin. 该文件会配置仅控制台自定义新模式并加入游戏中
67+
you will need .cfg files to add custom console-only mode. 该模式基于.cfg文件运行,请将你需要的指令放在指定的.cfg文件中
68+
see `config-example`

RoundFunManager.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

config-example/CustomModes.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Modes" :
3+
[
4+
{
5+
"Decr" : "headshot only 爆头模式",
6+
"Fun_cfgfilename" : "start.cfg",
7+
"Endfun_cfgfilename" : "end.cfg"
8+
},
9+
{
10+
"Decr" : "your custom mode decription",
11+
"Fun_cfgfilename" : "cfg file to excute on round start",
12+
"Endfun_cfgfilename" : "cfg file to excute on next round start to end mode"
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)