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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
#include <sourcemod>
#include <cstrike>
#include <gokz/core>
#include <gokz/profile>
#include <gokz/global>
#undef REQUIRE_EXTENSIONS
#undef REQUIRE_PLUGIN
#include <updater>
#include <gokz/chat>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "GOKZ Profile",
author = "zealain",
description = "Player profiles and ranks based on local and global data.",
version = GOKZ_VERSION,
url = GOKZ_SOURCE_URL
};
#define UPDATER_URL GOKZ_UPDATER_BASE_URL..."gokz-profile.txt"
int gI_Rank[MAXPLAYERS + 1][MODE_COUNT];
bool gB_Localranks;
bool gB_Chat;
#include "gokz-profile/options.sp"
#include "gokz-profile/profile.sp"
// =====[ PLUGIN EVENTS ]=====
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNatives();
RegPluginLibrary("gokz-profile");
return APLRes_Success;
}
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("gokz-profile.phrases");
CreateGlobalForwards();
RegisterCommands();
}
public void OnAllPluginsLoaded()
{
if (LibraryExists("updater"))
{
Updater_AddPlugin(UPDATER_URL);
}
gB_Localranks = LibraryExists("gokz-localranks");
gB_Chat = LibraryExists("gokz-chat");
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client) && !IsFakeClient(client))
{
UpdateRank(client, GOKZ_GetCoreOption(client, Option_Mode));
}
}
TopMenu topMenu;
if (LibraryExists("gokz-core") && ((topMenu = GOKZ_GetOptionsTopMenu()) != null))
{
GOKZ_OnOptionsMenuReady(topMenu);
}
}
public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, "updater"))
{
Updater_AddPlugin(UPDATER_URL);
}
gB_Localranks = gB_Localranks || StrEqual(name, "gokz-localranks");
gB_Chat = gB_Chat || StrEqual(name, "gokz-chat");
}
public void OnLibraryRemoved(const char[] name)
{
gB_Localranks = gB_Localranks && !StrEqual(name, "gokz-localranks");
gB_Chat = gB_Chat && !StrEqual(name, "gokz-chat");
}
// =====[ EVENTS ]=====
public Action OnClientCommandKeyValues(int client, KeyValues kv)
{
// Block clan tag changes - Credit: GoD-Tony (https://forums.alliedmods.net/showpost.php?p=2337679&postcount=6)
char cmd[16];
if (kv.GetSectionName(cmd, sizeof(cmd)) && StrEqual(cmd, "ClanTagChanged", false))
{
return Plugin_Handled;
}
return Plugin_Continue;
}
public void OnRebuildAdminCache(AdminCachePart part)
{
for (int client = 1; client <= MaxClients; client++)
{
if (IsValidClient(client) && !IsFakeClient(client))
{
int mode = GOKZ_GetCoreOption(client, Option_Mode);
UpdateRank(client, mode);
}
}
}
public void GOKZ_OnOptionsMenuCreated(TopMenu topMenu)
{
OnOptionsMenuCreated_OptionsMenu(topMenu);
}
public void GOKZ_OnOptionsMenuReady(TopMenu topMenu)
{
OnOptionsMenuReady_Options();
OnOptionsMenuReady_OptionsMenu(topMenu);
}
public void GOKZ_OnOptionsLoaded(int client)
{
if (IsValidClient(client) && !IsFakeClient(client))
{
int mode = GOKZ_GetCoreOption(client, Option_Mode);
UpdateTags(client, gI_Rank[client][mode], mode);
}
}
public void OnClientConnected(int client)
{
for (int mode = 0; mode < MODE_COUNT; mode++)
{
gI_Rank[client][mode] = 0;
}
Profile_OnClientConnected(client);
}
public void OnClientDisconnect(int client)
{
Profile_OnClientDisconnect(client);
}
public void GOKZ_OnOptionChanged(int client, const char[] option, any newValue)
{
Option coreOption;
if (GOKZ_IsCoreOption(option, coreOption) && coreOption == Option_Mode)
{
UpdateRank(client, newValue);
}
else if (StrEqual(option, gC_ProfileOptionNames[ProfileOption_ShowRankChat], true)
|| StrEqual(option, gC_ProfileOptionNames[ProfileOption_ShowRankClanTag], true)
|| StrEqual(option, gC_ProfileOptionNames[ProfileOption_TagType], true))
{
UpdateRank(client, GOKZ_GetCoreOption(client, Option_Mode));
}
}
public void GOKZ_GL_OnPointsUpdated(int client, int mode)
{
UpdateRank(client, mode);
Profile_OnPointsUpdated(client, mode);
}
public void UpdateRank(int client, int mode)
{
if (!IsValidClient(client) || IsFakeClient(client))
{
return;
}
int tagType = GetAvailableTagTypeOrDefault(client);
if (tagType != ProfileTagType_Rank)
{
char clanTag[64], chatTag[32], color[64];
if (tagType == ProfileTagType_Admin)
{
FormatEx(clanTag, sizeof(clanTag), "[%s %T]", gC_ModeNamesShort[mode], "Tag - Admin", client);
FormatEx(chatTag, sizeof(chatTag), "%T", "Tag - Admin", client);
color = TAG_COLOR_ADMIN;
}
if (tagType == ProfileTagType_VIP)
{
FormatEx(clanTag, sizeof(clanTag), "[%s %T]", gC_ModeNamesShort[mode], "Tag - VIP", client);
FormatEx(chatTag, sizeof(chatTag), "%T", "Tag - VIP", client);
color = TAG_COLOR_VIP;
}
if (GOKZ_GetOption(client, gC_ProfileOptionNames[ProfileOption_ShowRankClanTag]) != ProfileOptionBool_Enabled)
{
FormatEx(clanTag, sizeof(clanTag), "[%s]", gC_ModeNamesShort[mode]);
}
CS_SetClientClanTag(client, clanTag);
if (gB_Chat)
{
if (GOKZ_GetOption(client, gC_ProfileOptionNames[ProfileOption_ShowRankChat]) == ProfileOptionBool_Enabled)
{
GOKZ_CH_SetChatTag(client, chatTag, color);
}
else
{
GOKZ_CH_SetChatTag(client, "", "{default}");
}
}
return;
}
int points = GOKZ_GL_GetRankPoints(client, mode);
int rank;
for (rank = 1; rank < RANK_COUNT; rank++)
{
if (points < gI_rankThreshold[mode][rank])
{
break;
}
}
rank--;
if (GOKZ_GetCoreOption(client, Option_Mode) == mode)
{
if (points == -1)
{
UpdateTags(client, -1, mode);
}
else
{
UpdateTags(client, rank, mode);
}
}
if (gI_Rank[client][mode] != rank)
{
gI_Rank[client][mode] = rank;
Call_OnRankUpdated(client, mode, rank);
}
}
void UpdateTags(int client, int rank, int mode)
{
char str[64];
if (rank != -1 &&
GOKZ_GetOption(client, gC_ProfileOptionNames[ProfileOption_ShowRankClanTag]) == ProfileOptionBool_Enabled)
{
FormatEx(str, sizeof(str), "[%s %s]", gC_ModeNamesShort[mode], gC_rankName[rank]);
CS_SetClientClanTag(client, str);
}
else
{
FormatEx(str, sizeof(str), "[%s]", gC_ModeNamesShort[mode]);
CS_SetClientClanTag(client, str);
}
if (gB_Chat)
{
if (rank != -1 &&
GOKZ_GetOption(client, gC_ProfileOptionNames[ProfileOption_ShowRankChat]) == ProfileOptionBool_Enabled)
{
GOKZ_CH_SetChatTag(client, gC_rankName[rank], gC_rankColor[rank]);
}
else
{
GOKZ_CH_SetChatTag(client, "", "{default}");
}
}
}
bool CanUseTagType(int client, int tagType)
{
switch (tagType)
{
case ProfileTagType_Rank: return true;
case ProfileTagType_VIP: return CheckCommandAccess(client, "gokz_flag_vip", ADMFLAG_CUSTOM1);
case ProfileTagType_Admin: return CheckCommandAccess(client, "gokz_flag_admin", ADMFLAG_GENERIC);
default: return false;
}
}
int GetAvailableTagTypeOrDefault(int client)
{
int tagType = GOKZ_GetOption(client, gC_ProfileOptionNames[ProfileOption_TagType]);
if (!CanUseTagType(client, tagType))
{
return ProfileTagType_Rank;
}
return tagType;
}
// =====[ COMMANDS ]=====
void RegisterCommands()
{
RegConsoleCmd("sm_profile", CommandProfile, "[KZ] Show the profile of a player. Usage: !profile <player>");
RegConsoleCmd("sm_p", CommandProfile, "[KZ] Show the profile of a player. Usage: !p <player>");
RegConsoleCmd("sm_profileoptions", CommandProfileOptions, "[KZ] Show the profile options.");
RegConsoleCmd("sm_pfo", CommandProfileOptions, "[KZ] Show the profile options.");
RegConsoleCmd("sm_ranks", CommandRanks, "[KZ] Show all the available ranks.");
}
public Action CommandProfile(int client, int args)
{
if (args == 0)
{
ShowProfile(client, client);
}
else
{
char playerName[64];
GetCmdArgString(playerName, sizeof(playerName));
int player = FindTarget(client, playerName, true, false);
if (player != -1)
{
ShowProfile(client, player);
}
}
return Plugin_Handled;
}
public Action CommandProfileOptions(int client, int args)
{
DisplayProfileOptionsMenu(client);
return Plugin_Handled;
}
public Action CommandRanks(int client, int args)
{
char rankBuffer[256];
char buffer[256];
int mode = GOKZ_GetCoreOption(client, Option_Mode);
Format(buffer, sizeof(buffer), "%s: ", gC_ModeNamesShort[mode]);
for (int i = 0; i < RANK_COUNT; i++) {
Format(rankBuffer, sizeof(rankBuffer), "%s%s (%d) ", gC_rankColor[i], gC_rankName[i], gI_rankThreshold[mode][i]);
StrCat(buffer, sizeof(buffer), rankBuffer);
if (i > 0 && i % 3 == 0) {
GOKZ_PrintToChat(client, true, buffer);
Format(buffer, sizeof(buffer), "%s: ", gC_ModeNamesShort[mode]);
}
}
GOKZ_PrintToChat(client, true, buffer);
return Plugin_Handled;
}
// =====[ FORWARDS ]=====
static GlobalForward H_OnRankUpdated;
void CreateGlobalForwards()
{
H_OnRankUpdated = new GlobalForward("GOKZ_PF_OnRankUpdated", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
}
void Call_OnRankUpdated(int client, int mode, int rank)
{
Call_StartForward(H_OnRankUpdated);
Call_PushCell(client);
Call_PushCell(mode);
Call_PushCell(rank);
Call_Finish();
}
// =====[ NATIVES ]=====
void CreateNatives()
{
CreateNative("GOKZ_PF_GetRank", Native_GetRank);
}
public int Native_GetRank(Handle plugin, int numParams)
{
return gI_Rank[GetNativeCell(1)][GetNativeCell(2)];
}
|