/
SourceChatter_generic.sp
149 lines (110 loc) · 4.1 KB
/
SourceChatter_generic.sp
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
#pragma semicolon 1
#include <sourcechatter>
#undef REQUIRE_PLUGIN
#include <ccc>
#include <updater>
#define PLUGIN_VERSION "1.0.0"
#define UPDATE_URL "https://phil25.github.io/SourceChatter/game/addons/sourcemod/updatefile_generic.txt"
#define LIB_SC "SourceChatter"
#define LIB_CCC "ccc"
#define LIB_UPDATER "updater"
bool g_bCore = false;
bool g_bCCC = false;
bool g_bTeamChat[MAXPLAYERS+1] = {false, ...};
public Plugin myinfo = {
name = "SourceChatter Generic Events",
author = "Phil25",
description = "Source Chatter module - generic Source engine events",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=310211"
};
public void OnPluginStart(){
CreateConVar("sm_sourcechatter_generic_version", PLUGIN_VERSION, "Current Source Chatter generic module version", FCVAR_NOTIFY|FCVAR_DONTRECORD|FCVAR_SPONLY);
AddCommandListener(Event_OnSayAll, "say");
AddCommandListener(Event_OnSayTeam, "say_team");
HookEvent("player_say", Event_PlayerSay, EventHookMode_Post);
HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Post);
HookEvent("player_changename", Event_PlayerChangeName, EventHookMode_Post);
}
public void OnAllPluginsLoaded(){
g_bCore = LibraryExists(LIB_SC);
g_bCCC = LibraryExists(LIB_CCC);
if(LibraryExists(LIB_UPDATER))
Updater_AddPlugin(UPDATE_URL);
}
public void OnLibraryAdded(const char[] sLibName){
if(StrEqual(sLibName, LIB_SC))
g_bCore = true;
else if(StrEqual(sLibName, LIB_CCC))
g_bCCC = true;
else if(StrEqual(sLibName, LIB_UPDATER))
Updater_AddPlugin(UPDATE_URL);
}
public void OnLibraryRemoved(const char[] sLibName){
if(StrEqual(sLibName, LIB_SC))
g_bCore = false;
else if(StrEqual(sLibName, LIB_CCC))
g_bCCC = false;
}
public Action Event_OnSayAll(int client, const char[] sCmd, int args){
g_bTeamChat[client] = false;
return Plugin_Continue;
}
public Action Event_OnSayTeam(int client, const char[] sCmd, int args){
g_bTeamChat[client] = true;
return Plugin_Continue;
}
public Action Event_PlayerSay(Handle hEvent, const char[] sName, bool bDontBroadcast){
if(!g_bCore)
return Plugin_Continue;
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
char sMsg[255];
GetEventString(hEvent, "text", sMsg, 255);
UploadSayMessage(client, sMsg, g_bTeamChat[client]);
return Plugin_Continue;
}
void UploadSayMessage(int client, const char[] sMsg, bool bTeam=false){
if(client == 0){
SC_PushMessage("[b]Console[/b]: %s", sMsg);
return;
}
if(!g_bCCC){
SC_PushMessage("%s%s[b][color=#%06x]%N[/color][/b]: %s",
IsPlayerAlive(client) ? "" : "*DEAD* ",
bTeam ? "(TEAM) " : "",
SC_GetTeamColorOfClient(client), client, sMsg
);
return;
}
char sTag[32];
CCC_GetTag(client, sTag, 32);
int iTagColor = CCC_GetColor(client, CCC_TagColor);
SC_PushMessage("%s%s[b][color=#%06x]%s[/color][color=#%06x]%N[/color][/b]: %s",
IsPlayerAlive(client) ? "" : "*DEAD* ",
bTeam ? "(TEAM) " : "",
iTagColor, sTag, SC_GetTeamColorOfClient(client), client, sMsg
);
}
public void OnClientConnected(int client){
SC_PushMessage("[color=#%06x][i][b]%N[/b] joined the game.[/i][/color]", SC_GetInfoColor(), client);
}
public Action Event_PlayerDisconnect(Handle hEvent, const char[] sName, bool bDontBroadcast){
if(!g_bCore)
return Plugin_Continue;
char sPlayerName[MAX_NAME_LENGTH], sReason[32];
GetEventString(hEvent, "name", sPlayerName, MAX_NAME_LENGTH);
GetEventString(hEvent, "reason", sReason, 32);
SC_PushMessage("[color=#%06x][i][b]%s[/b] left the game. (%s)[/i][/color]", SC_GetInfoColor(), sPlayerName, sReason);
return Plugin_Continue;
}
public Action Event_PlayerChangeName(Handle hEvent, const char[] sName, bool bDontBroadcast){
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
if(client == 0)
return Plugin_Continue;
char sOld[MAX_NAME_LENGTH], sNew[MAX_NAME_LENGTH];
GetEventString(hEvent, "oldname", sOld, MAX_NAME_LENGTH);
GetEventString(hEvent, "newname", sNew, MAX_NAME_LENGTH);
int iColor = SC_GetTeamColorOfClient(client);
SC_PushMessage("* [color=#%06x][b]%s[/b][/color] changed name to [color=#%06x][b]%s[/b][/color]", iColor, sOld, iColor, sNew);
return Plugin_Continue;
}