-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickDefuse.cs
98 lines (90 loc) · 3.56 KB
/
QuickDefuse.cs
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
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Utils;
using WASDSharedAPI;
namespace QuickDefuse;
public class QuickDefuse : BasePlugin
{
public override string ModuleName => "QuickDefuse";
public override string ModuleVersion => "1.0.3";
public override string ModuleAuthor => "Interesting";
public int Wire;
public string[] Colors = { "Red", "Blue", "Green", "Yellow"};
public char[] ChatColorsArray = { ChatColors.Red, ChatColors.Blue, ChatColors.Green, ChatColors.Yellow };
public static IWasdMenuManager? MenuManager;
public static CCSPlayerController? Defuser;
public override void Load(bool hotReload)
{
RegisterEventHandler<EventBombBegindefuse>(OnBombBeginDefuse);
RegisterEventHandler<EventBombAbortdefuse>((@event, info) =>
{
Defuser = null;
var menuManager = GetMenuManager();
menuManager?.CloseMenu(@event.Userid);
return HookResult.Continue;
});
RegisterEventHandler<EventBombDefused>((@event, info) =>
{
Defuser = null;
var menuManager = GetMenuManager();
menuManager?.CloseMenu(@event.Userid);
return HookResult.Continue;
});
RegisterEventHandler<EventBombExploded>((@event, info) =>
{
if (Defuser != null)
{
var menuManager = GetMenuManager();
menuManager?.CloseMenu(Defuser);
Defuser = null;
}
return HookResult.Continue;
});
}
public IWasdMenuManager? GetMenuManager()
{
if (MenuManager == null)
MenuManager = new PluginCapability<IWasdMenuManager>("wasdmenu:manager").Get();
return MenuManager;
}
public IWasdMenu? CreateMenu()
{
var menuManager = GetMenuManager();
IWasdMenu? menu = menuManager?.CreateMenu("Guess a wire to defuse the bomb!");
for (int i = 0; i < Colors.Length; i++)
{
int choice = i;
menu?.Add($"{Colors[i]} wire", (controller, option) =>
{
var bomb = Utilities.FindAllEntitiesByDesignerName<CPlantedC4>("planted_c4").ToList().FirstOrDefault();
if (bomb == null)
return;
if (Wire == choice)
{
Server.NextFrame(() =>
{
bomb.DefuseCountDown = 0.0f;
Server.PrintToChatAll($" {ChatColors.Blue}[QuickDefuse]{ChatColors.White} {controller.PlayerName} just defused the bomb by cutting the{ChatColorsArray[Wire]} {Colors[Wire]} wire!");
});
}
else
{
bomb.C4Blow = 1.0f;
Server.PrintToChatAll($" {ChatColors.Blue}[QuickDefuse]{ChatColors.White} {controller.PlayerName} just detonated the bomb by cutting the{ChatColorsArray[Wire]} {Colors[Wire]} wire!");
}
menuManager?.CloseMenu(controller);
});
}
return menu;
}
public HookResult OnBombBeginDefuse(EventBombBegindefuse @event, GameEventInfo info)
{
if (@event.Userid == null || @event.Userid.IsBot)
return HookResult.Continue;
Defuser = @event.Userid;
Wire = new Random().Next(0, Int32.MaxValue) % Colors.Length;
GetMenuManager()?.OpenMainMenu(@event.Userid, CreateMenu());
return HookResult.Continue;
}
}