-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunFootBall.cs
More file actions
204 lines (192 loc) · 7.9 KB
/
FunFootBall.cs
File metadata and controls
204 lines (192 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
namespace FunMatchPlugin;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Timers;
public class FunFootBall : FunBaseClass
{
public override string Decription => "FootBall Mode T aims to take soccerball to CTspawn 足球模式 T需要将球踢进CT出生点";
private CPhysicsProp ?SoccerBall;
private Timer ?BallStatusTimer;
private Vector ScoreCenter = new(0,0,0);
private Vector SoccerLastPosition = new(0,0,0);
private Vector SoccerSpawnPosition = new(0,0,0);
private int soccer_same_pos_times = 0;
private BasePlugin.GameEventHandler<EventRoundFreezeEnd> ?EventRoundFreezeEndHandler;
public override void EndFun(FunMatchPlugin plugin)
{
Enabled = false;
ConVar.Find("mp_buytime")!.SetValue(20.0f);
ConVar.Find("mp_autokick")!.SetValue(true);
ConVar.Find("mp_buy_during_immunity")!.SetValue(0);
if (EventRoundFreezeEndHandler is not null)
plugin.DeregisterEventHandler(EventRoundFreezeEndHandler!);
if (BallStatusTimer is not null)
BallStatusTimer!.Kill();
}
public override void Fun(FunMatchPlugin plugin)
{
if (Enabled) return;
Enabled = true;
ScoreCenter = new(0,0,0);
SoccerLastPosition = new(0,0,0);
SoccerSpawnPosition = new(0,0,0);
soccer_same_pos_times = 0;
ConVar.Find("mp_buytime")!.SetValue(0.0f);
ConVar.Find("mp_autokick")!.SetValue(false);
ConVar.Find("mp_buy_during_immunity")!.SetValue(1);
var Allplayers = Utilities.GetPlayers();
foreach (var p in Allplayers)
{
if (!p.IsValid || !p.PawnIsAlive) continue;
p.RemoveWeapons();
}
/*
var gameRulesProxie = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules");
var gameRules = gameRulesProxie.First().GameRules!;
var spawnpoints_ct = gameRules.CTSpawnPoints.GetEnumerator();
foreach (var sp in spawnpoints_ct)
{
//ScoreCenter.X += sp!.AbsOrigin!.X;
//ScoreCenter.Y += sp!.AbsOrigin!.Y;
//ScoreCenter.Z += sp!.AbsOrigin!.Z;
Console.WriteLine($"scorecenter{sp!.AbsOrigin!.X} {sp!.AbsOrigin!.Y} {sp!.AbsOrigin!.Z}");
}
ScoreCenter.X = ScoreCenter.X/gameRules.SpawnPointCount_CT;
ScoreCenter.Y = ScoreCenter.Y/gameRules.SpawnPointCount_CT;
ScoreCenter.Z = ScoreCenter.Z/gameRules.SpawnPointCount_CT;
Console.WriteLine($"scorecenter{ScoreCenter.X} {ScoreCenter.Y} {ScoreCenter.Z}");
*/
plugin.RegisterEventHandler<EventRoundFreezeEnd>(EventRoundFreezeEndHandler = (@event, info)=>
{
var Allplayers = Utilities.GetPlayers();
bool HasGivenBall = false;
bool HasSetScorePoint = false;
//mp_buytime
foreach (var p in Allplayers)
{
if (!p.IsValid || !p.PawnIsAlive) continue;
p.RemoveWeapons();
if (p.PawnIsAlive && p.Team == CsTeam.Terrorist && HasGivenBall == false)
{
HasGivenBall = true;
SoccerBall = Utilities.CreateEntityByName<CPhysicsProp>("prop_physics_multiplayer")!;
var pawn = p.PlayerPawn.Get();
Vector position = new(pawn!.AbsOrigin!.X,pawn!.AbsOrigin!.Y,pawn!.AbsOrigin!.Z + 100);
SoccerBall.Teleport(position);
SoccerBall.SetModel("models/props/de_dust/hr_dust/dust_soccerball/dust_soccer_ball001.vmdl");
//models/props/de_dust/hr_dust/dust_soccerball/dust_soccer_ball001.vmdl_c
SoccerSpawnPosition.X = SoccerBall!.AbsOrigin!.X;
SoccerSpawnPosition.Y = SoccerBall!.AbsOrigin!.Y;
SoccerSpawnPosition.Z = SoccerBall!.AbsOrigin!.Z;
//SoccerBall.GlowColor = Color.GreenYellow;
SoccerBall.DispatchSpawn();
}
if (p.PawnIsAlive && p.Team == CsTeam.CounterTerrorist && HasSetScorePoint == false)
{
HasSetScorePoint = true;
//models/props_fairgrounds/fairgrounds_flagpole01.vmdl
var flag = Utilities.CreateEntityByName<CDynamicProp>("prop_dynamic")!;
var pawn = p.PlayerPawn.Get();
//Vector position = new(pawn!.AbsOrigin!.X,pawn!.AbsOrigin!.Y,pawn!.AbsOrigin!.Z);
flag.Teleport(pawn!.AbsOrigin);
flag.SetModel("models/props_fairgrounds/fairgrounds_flagpole01.vmdl");
flag.DispatchSpawn();
ScoreCenter = flag!.AbsOrigin!;
}
}
//CCSPlayerResource siteA siteB position?
//Utilities.FindAllEntitiesByDesignerName<CCSPlayerResource>("???");
BallStatusTimer = plugin.AddTimer(1,()=>CheckBallStatus(),TimerFlags.REPEAT);
return HookResult.Stop;
});
plugin.RegisterEventHandler<EventRoundEnd>((@event, info)=>
{
EndFun(plugin);
return HookResult.Stop;
});
}
private void CheckBallStatus()
{
if (Enabled == false)
{
BallStatusTimer!.Kill();
return;
}
if (SoccerBall == null)
{
BallStatusTimer!.Kill();
return;
}
if (IsBallIn())
{
TWin();
return;
}
if (IsBallFalling() || IsBallStuck())
{
if (SoccerBall!.IsValid)
SoccerBall.Teleport(SoccerSpawnPosition);
SoccerLastPosition.X = SoccerSpawnPosition.X;
SoccerLastPosition.Y = SoccerSpawnPosition.Y;
SoccerLastPosition.Z = SoccerSpawnPosition.Z;
}
}
private bool IsBallIn()
{
if (!SoccerBall!.IsValid) return false;
var ball_x = SoccerBall.AbsOrigin!.X;
var ball_y = SoccerBall.AbsOrigin!.Y;
var ball_z = SoccerBall.AbsOrigin!.Z;
if (Math.Abs(ScoreCenter.X-ball_x) <= 500 && Math.Abs(ScoreCenter.Y-ball_y) <= 500 && Math.Abs(ScoreCenter.Z-ball_z) <= 50)
return true;
else return false;
}
private void TWin()
{
var gameRulesProxie = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules");
var gameRules = gameRulesProxie.First().GameRules!;
if (gameRules!.WarmupPeriod)
return;
var Allplayers = Utilities.GetPlayers();
foreach (var p in Allplayers)
{
if (!p.IsValid) continue;
if (p.Team == CsTeam.CounterTerrorist)
{
p.CommitSuicide(false,true);
}
}
}
private bool IsBallStuck()
{
if (SoccerBall!.AbsOrigin!.X == SoccerLastPosition.X && SoccerBall!.AbsOrigin.Y == SoccerLastPosition.Y && SoccerBall!.AbsOrigin.Z == SoccerLastPosition.Z)
{
soccer_same_pos_times++;
}
else
{
soccer_same_pos_times = 0;
SoccerLastPosition.X = SoccerBall!.AbsOrigin!.X;
SoccerLastPosition.Y = SoccerBall!.AbsOrigin!.Y;
SoccerLastPosition.Z = SoccerBall!.AbsOrigin!.Z;
}
if (soccer_same_pos_times >= 5)
{
Server.PrintToChatAll(StringExtensions.ReplaceColorTags("{RED}") + "[FootBallMode] " + "Ball Stuck Resetting");
return true;
}
return false;
}
private bool IsBallFalling()
{
if (SoccerBall!.AbsOrigin!.Z - SoccerLastPosition.Z < -400)
{
Server.PrintToChatAll(StringExtensions.ReplaceColorTags("{RED}") + "[FootBallMode] " + "Ball Falling Resetting");
return true;
}
return false;
}
}