Skip to content

Commit 2f0586a

Browse files
committed
Add Listener when player write one of the triggerwords
1 parent ad53a34 commit 2f0586a

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Modules/Config.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ public class Config
1212
public PrefixConfig Prefix { get; init; } = null!;
1313

1414
public bool GiveArmor {get; init;} = true;
15+
public string[] triggerWords {get; init;} = { "guns", "gun", "weapon", "weapons"};
1516

1617
public Config()
1718
{
1819
DbConnection = new ConnectionConfig();
1920
Prefix = new PrefixConfig();
2021
GiveArmor = true;
22+
triggerWords = new string[] { "guns", "gun", "weapon", "weapons"};
2123
}
2224

2325
public bool IsValid()

Modules/Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Core : BasePlugin
1717
public static Core Plugin = null!;
1818

1919
public override string ModuleName => "[Retakes] Weapons Allocator";
20-
public override string ModuleVersion => "1.1.0";
20+
public override string ModuleVersion => "1.1.1";
2121
public override string ModuleAuthor => "Ravid & B3none";
2222
public override string ModuleDescription => "Weapons Allocator plugin for retakes";
2323

Modules/Handlers/Listeners.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using CounterStrikeSharp.API;
2+
using CounterStrikeSharp.API.Core;
3+
using CounterStrikeSharp.API.Modules.Commands;
24
using CounterStrikeSharp.API.Core.Attributes;
35
using CounterStrikeSharp.API.Modules.Entities;
46

57
using static RetakesAllocator.Modules.Core;
68
using static RetakesAllocator.Modules.Utils;
9+
using static RetakesAllocator.Modules.Weapons.Menu;
710

811
namespace RetakesAllocator.Modules.Handlers;
912

@@ -15,6 +18,9 @@ public static void RegisterListeners()
1518
Plugin.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnClientAuthorized>(OnClientAuthorized);
1619
Plugin.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnClientConnected>(OnClientConnected);
1720
Plugin.RegisterListener<CounterStrikeSharp.API.Core.Listeners.OnClientDisconnect>(OnClientDisconnect);
21+
22+
Plugin.AddCommandListener("say", OnSay);
23+
Plugin.AddCommandListener("say_team", OnSay);
1824
}
1925

2026
private static void OnMapStart(string map_name)
@@ -49,4 +55,30 @@ private static void OnClientDisconnect(int playerSlot)
4955
var player = Utilities.GetPlayerFromSlot(playerSlot);
5056
RemovePlayerFromList(player);
5157
}
58+
59+
private static HookResult OnSay(CCSPlayerController? player, CommandInfo command)
60+
{
61+
if (player == null || !player.IsValid)
62+
return HookResult.Continue;
63+
64+
if(command.ArgCount < 2)
65+
return HookResult.Continue;
66+
67+
var message = command.GetArg(1);
68+
69+
if(!Core.Config.triggerWords.Any(word => word.Equals(message)))
70+
return HookResult.Continue;
71+
72+
var playerObj = FindPlayer(player);
73+
74+
if (playerObj == null!)
75+
{
76+
ReplyToCommand(command, $"{PREFIX} This command can only be executed by a valid player.");
77+
return HookResult.Continue;
78+
}
79+
80+
OpenTPrimaryMenu(player);
81+
82+
return HookResult.Continue;
83+
}
5284
}

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ The DBConnection will be generated empty and the plugin will raise an exception,
2727
"PREFIX": " \u0004[Retakes]\u0001",
2828
"PREFIX_CON": "[Retakes]",
2929
},
30-
"GiveArmor": true
30+
"GiveArmor": true,
31+
"triggerWords": [
32+
"guns",
33+
"gun",
34+
"weapon",
35+
"weapons"
36+
]
3137
}
3238
3339
```

0 commit comments

Comments
 (0)