-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatColors.as
More file actions
134 lines (111 loc) · 3.45 KB
/
ChatColors.as
File metadata and controls
134 lines (111 loc) · 3.45 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
void print(string text) { g_Game.AlertMessage( at_console, text); }
void println(string text) { print(text + "\n"); }
dictionary g_player_states;
class PlayerState {
int color = -1; // classify value
}
bool g_disabled = false;
// Will create a new state if the requested one does not exit
PlayerState@ getPlayerState(CBasePlayer@ plr)
{
if (plr is null or !plr.IsConnected())
return null;
string steamId = g_EngineFuncs.GetPlayerAuthId( plr.edict() );
if (steamId == 'STEAM_ID_LAN' or steamId == 'BOT') {
steamId = plr.pev.netname;
}
if ( !g_player_states.exists(steamId) )
{
PlayerState state;
g_player_states[steamId] = state;
}
return cast<PlayerState@>( g_player_states[steamId] );
}
void PluginInit()
{
g_Module.ScriptInfo.SetAuthor( "w00tguy" );
g_Module.ScriptInfo.SetContactInfo( "https://github.com/wootguy" );
g_Hooks.RegisterHook( Hooks::Player::ClientSay, @ClientSay );
}
void MapInit()
{
g_disabled = false;
}
bool doCommand(CBasePlayer@ plr, const CCommand@ args, bool inConsole) {
bool isAdmin = g_PlayerFuncs.AdminLevel(plr) >= ADMIN_YES;
PlayerState@ state = getPlayerState(plr);
if (args.ArgC() > 0 && args[0] == ".color" || args[0] == ".c") {
if (g_disabled) {
g_PlayerFuncs.SayTextAll(plr, "Chat colors are disabled on this map.");
return true;
}
if (args.ArgC() >= 2) {
string color = args[1].ToLowercase();
string newColor;
if (color == "red" or color == "r") {
state.color = 17;
newColor = "red";
} else if (color == "green" or color == "g") {
state.color = 19;
newColor = "green";
} else if (color == "blue" or color == "b") {
state.color = 16;
newColor = "blue";
} else if (color == "yellow" or color == "y") {
state.color = 18;
newColor = "yellow";
} else if (color == "off" or color == "o") {
state.color = -1;
newColor = "disabled";
}
else {
g_PlayerFuncs.SayText(plr, "Valid colors are: red, green, blue, yellow (or just r, g, b, y)");
return true;
}
g_PlayerFuncs.SayText(plr, "Your name color is now " + newColor);
} else {
g_PlayerFuncs.SayText(plr, "Usage: .color <red/green/blue/yellow/off> OR .c <r/g/b/y/o>");
}
return true;
}
if (g_disabled) {
return false;
}
if (args.ArgC() > 0 && state.color > 0) {
int oldClassify = plr.Classify();
if (oldClassify >= 16 && oldClassify <= 19) {
g_disabled = true;
g_PlayerFuncs.SayTextAll(plr, "Chat colors disabled. This map appears to use teams.");
return false;
}
plr.SetClassification(state.color);
plr.SendScoreInfo();
plr.SetClassification(oldClassify);
g_Scheduler.SetTimeout("revert_scoreboard_color", 0.5f, EHandle(plr));
}
return false;
}
// keeping the scoreboard color would be neat too, but then you can't see hp/armor
void revert_scoreboard_color(EHandle h_plr) {
CBasePlayer@ plr = cast<CBasePlayer@>(h_plr.GetEntity());
if (plr is null or !plr.IsConnected()) {
return;
}
plr.SendScoreInfo();
}
HookReturnCode ClientSay( SayParameters@ pParams ) {
CBasePlayer@ plr = pParams.GetPlayer();
const CCommand@ args = pParams.GetArguments();
if (doCommand(plr, args, false))
{
pParams.ShouldHide = true;
return HOOK_HANDLED;
}
return HOOK_CONTINUE;
}
CClientCommand _ghost("color", "chat color commands", @consoleCmd );
CClientCommand _ghost2("c", "chat color commands", @consoleCmd );
void consoleCmd( const CCommand@ args ) {
CBasePlayer@ plr = g_ConCommandSystem.GetCurrentPlayer();
doCommand(plr, args, true);
}