Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 68 additions & 25 deletions addons/sourcemod/scripting/ZLeader.sp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ int g_Serial_Beacon = 0,
g_iCooldownBeamPing[MAXPLAYERS + 1] = {0, ... },
g_iCurrentLeader[MAXLEADER] = {-1, -1, -1};

bool g_bPlugin_ccc,
bool g_bLate,
g_bPlugin_ccc,
g_bPlugin_vipcore,
g_Plugin_BaseComm,
g_bPlugin_SourceCommsPP,
Expand Down Expand Up @@ -86,9 +87,7 @@ char g_sEntityTypes[ENTITIES_PER_MK][32] = { "prop_dynamic", "light_dynamic", "e
float g_fPos[3],
g_fMarkerTime;

Handle g_hShortcut = INVALID_HANDLE,
g_hPingSound = INVALID_HANDLE,
g_hMarkerPos = INVALID_HANDLE,
Handle g_hZLeaderSettings = INVALID_HANDLE,
g_hSetClientLeaderForward = INVALID_HANDLE,
g_hRemoveClientLeaderForward = INVALID_HANDLE;

Expand Down Expand Up @@ -140,6 +139,7 @@ public Plugin myinfo = {
};

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
g_bLate = late;
CreateNative("ZL_SetLeader", Native_SetLeader);
CreateNative("ZL_IsClientLeader", Native_IsClientLeader);
CreateNative("ZL_RemoveLeader", Native_RemoveLeader);
Expand Down Expand Up @@ -230,22 +230,25 @@ public void OnPluginStart() {

/* COOKIES */
SetCookieMenuItem(ZLeaderCookieHandler, 0, "ZLeader Settings");
g_hMarkerPos = RegClientCookie("zleader_makerpos", "ZLeader Marker Position", CookieAccess_Protected);
g_hShortcut = RegClientCookie("zleader_shortcut", "ZLeader ShortCut", CookieAccess_Protected);
g_hPingSound = RegClientCookie("zleader_pingsound", "ZLeader Ping Sound", CookieAccess_Protected);
g_hZLeaderSettings = RegClientCookie("zleader_settings", "ZLeader Settings", CookieAccess_Protected);

/* ADD FILTERS */
AddMultiTargetFilter("@leaders", Filter_Leaders, "Possible Leaders", false);
AddMultiTargetFilter("@!leaders", Filter_NotLeaders, "Everyone but Possible Leaders", false);
AddMultiTargetFilter("@leader", Filter_Leader, "Current Leader", false);
AddMultiTargetFilter("@!leader", Filter_NotLeader, "Every one but the Current Leader", false);

if (!g_bLate)
return;

/* Late load */
char sSteam32ID[32];
for (int i = 1; i < MaxClients; i++) {
if (IsClientInGame(i) && !IsFakeClient(i) && IsClientAuthorized(i) && GetClientAuthId(i, AuthId_Steam2, sSteam32ID, sizeof(sSteam32ID)))
OnClientAuthorized(i, sSteam32ID);
}

g_bLate = false;
}

public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) {
Expand Down Expand Up @@ -418,9 +421,7 @@ public void OnPluginEnd() {
RemoveCommandListener(QuickLeaderMenuCommand, "+lookatweapon");
RemoveCommandListener(QuickMarkerMenuCommand, "-lookatweapon");

CloseHandle(g_hShortcut);
CloseHandle(g_hPingSound);
CloseHandle(g_hMarkerPos);
CloseHandle(g_hZLeaderSettings);
CloseHandle(g_hSetClientLeaderForward);
CloseHandle(g_hRemoveClientLeaderForward);
}
Expand Down Expand Up @@ -520,29 +521,71 @@ public void OnClientCookiesCached(int client) {
ReadClientCookies(client);
}

void ParseClientCookie(int client, bool &shortcut, bool &pingSound, int &markerPos) {
char buffer[64];
GetClientCookie(client, g_hZLeaderSettings, buffer, sizeof(buffer));

// Parse chain format: shortcut|pingsound|markerpos
if (buffer[0] != '\0') {
char parts[3][16];
int count = ExplodeString(buffer, "|", parts, 3, sizeof(parts[]));

if (count >= 1) {
shortcut = view_as<bool>(StringToInt(parts[0]));
}
if (count >= 2) {
pingSound = view_as<bool>(StringToInt(parts[1]));
}
if (count >= 3) {
markerPos = StringToInt(parts[2]);
}
}
else {
// Default values
shortcut = true;
pingSound = true;
markerPos = MK_TYPE_CROSSHAIR;
}
}

public void ReadClientCookies(int client) {
char buffer[32];
GetClientCookie(client, g_hShortcut, buffer, 32);
g_bShorcut[client] = view_as<bool>(StringToInt(buffer)) || buffer[0] == '\0';
bool shortcut, pingSound;
int markerPos;

GetClientCookie(client, g_hPingSound, buffer, 32);
g_bPingSound[client] = view_as<bool>(StringToInt(buffer)) || buffer[0] == '\0';
ParseClientCookie(client, shortcut, pingSound, markerPos);

GetClientCookie(client, g_hMarkerPos, buffer, 32);
g_iMarkerPos[client] = (buffer[0] != '\0') ? StringToInt(buffer) : MK_TYPE_CROSSHAIR;
g_bShorcut[client] = shortcut;
g_bPingSound[client] = pingSound;
g_iMarkerPos[client] = markerPos;
}

public void SetClientCookies(int client) {
if (!client || !IsClientInGame(client) || IsFakeClient(client))
return;

char sValue[8];
// Read current cookie values
bool currentShortcut, currentPingSound;
int currentMarkerPos;
ParseClientCookie(client, currentShortcut, currentPingSound, currentMarkerPos);

FormatEx(sValue, sizeof(sValue), "%i", g_bShorcut[client]);
SetClientCookie(client, g_hShortcut, sValue);
// Check if values have changed
bool shortcutChanged = g_bShorcut[client] != currentShortcut;
bool pingSoundChanged = g_bPingSound[client] != currentPingSound;
bool markerPosChanged = g_iMarkerPos[client] != currentMarkerPos;

FormatEx(sValue, sizeof(sValue), "%i", g_iMarkerPos[client]);
SetClientCookie(client, g_hMarkerPos, sValue);
// If no values have changed, no need to save
if (!shortcutChanged && !pingSoundChanged && !markerPosChanged) {
return;
}

// Otherwise, save the chain format
char sValue[64];
FormatEx(sValue, sizeof(sValue), "%d|%d|%d",
g_bShorcut[client] ? 1 : 0,
g_bPingSound[client] ? 1 : 0,
g_iMarkerPos[client]);

SetClientCookie(client, g_hZLeaderSettings, sValue);
}

public void ZLeaderCookieHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) {
Expand Down Expand Up @@ -594,9 +637,11 @@ public int ZLeaderSettingHandler(Menu menu, MenuAction action, int param1, int p
g_bShorcut[param1] = !g_bShorcut[param1];
FormatEx(status, 64, "%T", g_bShorcut[param1] ? "Enabled Chat" : "Disabled Chat", param1);
CPrintToChat(param1, "%T %T", "Prefix", param1, "You set shortcut", param1, status);
SetClientCookies(param1);
} else if (strcmp(info, "markerpos", false) == 0) {
g_iMarkerPos[param1] = (g_iMarkerPos[param1] == MK_TYPE_CLIENT) ? MK_TYPE_CROSSHAIR : MK_TYPE_CLIENT;
CPrintToChat(param1, "%T %T", "Prefix", param1, (g_iMarkerPos[param1] == MK_TYPE_CLIENT) ? "Marker Pos Player Position" : "Marker Pos Crosshair", param1);
SetClientCookies(param1);
}

ZLeaderSetting(param1);
Expand All @@ -622,8 +667,6 @@ public void OnClientDisconnect(int client) {

FormatEx(g_sSteamIDs2[client], sizeof(g_sSteamIDs2[]), "");
FormatEx(g_sSteamIDs64[client], sizeof(g_sSteamIDs64[]), "");

SetClientCookies(client);
}

public void OnPlayerTeam(Event event, const char[] name, bool dontBroadcast) {
Expand Down Expand Up @@ -3000,4 +3043,4 @@ void Reset_ClientFromLeaderSlots(int client) {
g_iCurrentLeader[i] = -1;
}
}
}
}
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/include/zleader.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define _zleader_included

#define ZLeader_V_MAJOR "3"
#define ZLeader_V_MINOR "6"
#define ZLeader_V_PATCH "6"
#define ZLeader_V_MINOR "7"
#define ZLeader_V_PATCH "0"

#define ZLeader_VERSION ZLeader_V_MAJOR..."."...ZLeader_V_MINOR..."."...ZLeader_V_PATCH

Expand Down