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
268 changes: 136 additions & 132 deletions addons/sourcemod/scripting/ZLeader.sp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public void OnRoundStart(Event event, const char[] name, bool dontBroadcast) {

public Action Timer_RoundEndClean(Handle timer) {
for (int i = 1; i <= MaxClients; i++) {
if (IsValidClient(i))
if (IsClientInGame(i))
Reset_ClientNextVote(i);
if (IsClientLeader(i))
RemoveLeader(i, R_SELFRESIGN, false);
Expand Down Expand Up @@ -934,61 +934,62 @@ public void LeaderMenu(int client) {
}

public int LeaderMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (IsValidClient(param1) && IsClientLeader(param1)) {
switch (action) {
case MenuAction_DisplayItem: {
char info[64], display[128];
menu.GetItem(param2, info, sizeof(info));
if (strcmp(info, "follow", false) == 0 && g_iClientSprite[param1] == SP_FOLLOW) {
FormatEx(display, sizeof(display), "%T (✘)", "Follow Me", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "trail", false) == 0 && g_bTrailActive[param1]) {
FormatEx(display, sizeof(display), "%T (✘)", "Toggle Trail", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "beacon", false) == 0 && g_bBeaconActive[param1]) {
FormatEx(display, sizeof(display), "%T (✘)", "Toggle Beacon", param1);
return RedrawMenuItem(display);
}
switch (action) {
case MenuAction_DisplayItem: {
char info[64], display[128];
menu.GetItem(param2, info, sizeof(info));
if (strcmp(info, "follow", false) == 0 && g_iClientSprite[param1] == SP_FOLLOW) {
FormatEx(display, sizeof(display), "%T (✘)", "Follow Me", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "trail", false) == 0 && g_bTrailActive[param1]) {
FormatEx(display, sizeof(display), "%T (✘)", "Toggle Trail", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "beacon", false) == 0 && g_bBeaconActive[param1]) {
FormatEx(display, sizeof(display), "%T (✘)", "Toggle Beacon", param1);
return RedrawMenuItem(display);
}
}

case MenuAction_Select: {
char info[64];
menu.GetItem(param2, info, sizeof(info));
case MenuAction_Select: {
if (!IsClientLeader(param1))
return 0;

if (!ZR_IsClientZombie(param1)) {
if (strcmp(info, "follow", false) == 0) {
if (g_iClientSprite[param1] != SP_FOLLOW) {
RemoveSpriteFollow(param1);
g_iClientSprite[param1] = SP_FOLLOW;
int slot = GetLeaderIndexWithLeaderSlot(g_iClientLeaderSlot[param1]);
if (g_LeaderData[slot].L_FollowVMT[0] != '\0')
g_iSpriteFollow[param1] = AttachSprite(param1, g_LeaderData[slot].L_FollowVMT, 1);
} else {
RemoveSpriteFollow(param1);
Reset_ClientSprite(param1);
}

LeaderMenu(param1);
} else if (strcmp(info, "trail", false) == 0) {
ToggleTrail(param1);
LeaderMenu(param1);
} else if (strcmp(info, "beacon", false) == 0) {
ToggleBeacon(param1);
LeaderMenu(param1);
} else if (strcmp(info, "marker", false) == 0) {
MarkerMenu(param1);
} else if (strcmp(info, "removemarker", false) == 0) {
RemoveAllMarkers(param1);
LeaderMenu(param1);
} else if (strcmp(info, "resign", false) == 0) {
ResignConfirmMenu(param1);
char info[64];
menu.GetItem(param2, info, sizeof(info));

if (!ZR_IsClientZombie(param1)) {
if (strcmp(info, "follow", false) == 0) {
if (g_iClientSprite[param1] != SP_FOLLOW) {
RemoveSpriteFollow(param1);
g_iClientSprite[param1] = SP_FOLLOW;
int slot = GetLeaderIndexWithLeaderSlot(g_iClientLeaderSlot[param1]);
if (g_LeaderData[slot].L_FollowVMT[0] != '\0')
g_iSpriteFollow[param1] = AttachSprite(param1, g_LeaderData[slot].L_FollowVMT, 1);
} else {
RemoveSpriteFollow(param1);
Reset_ClientSprite(param1);
}

LeaderMenu(param1);
} else if (strcmp(info, "trail", false) == 0) {
ToggleTrail(param1);
LeaderMenu(param1);
} else if (strcmp(info, "beacon", false) == 0) {
ToggleBeacon(param1);
LeaderMenu(param1);
} else if (strcmp(info, "marker", false) == 0) {
MarkerMenu(param1);
} else if (strcmp(info, "removemarker", false) == 0) {
RemoveAllMarkers(param1);
LeaderMenu(param1);
} else if (strcmp(info, "resign", false) == 0) {
ResignConfirmMenu(param1);
}
}
}

case MenuAction_End: {
delete menu;
}
case MenuAction_End: {
delete menu;
}
}
return 0;
Expand Down Expand Up @@ -1055,13 +1056,10 @@ public Action Command_CurrentLeader(int client, int args) {
}

public int CurrentLeaderMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (IsValidClient(param1) && g_bClientLeader[param1]) {
switch (action) {
case MenuAction_End: {
delete menu;
}
}
if (action == MenuAction_End) {
delete menu;
}

return 0;
}

Expand Down Expand Up @@ -1150,8 +1148,9 @@ public Action Command_VoteLeader(int client, int args) {
}

if (GetClientFromSerial(g_iClientVoteWhom[client]) != 0) {
if (IsValidClient(GetClientFromSerial(g_iClientVoteWhom[client])))
g_iClientGetVoted[GetClientFromSerial(g_iClientVoteWhom[client])]--;
int clientVoteWhom = GetClientFromSerial(g_iClientVoteWhom[client]);
if (clientVoteWhom)
g_iClientGetVoted[clientVoteWhom]--;
}

g_iClientGetVoted[target]++;
Expand Down Expand Up @@ -1230,7 +1229,7 @@ public Action Command_RemoveLeader(int client, int args) {
}

public void RemoveLeaderList(int client) {
if (!IsValidClient(client)) return;
if (!client) return;

SetGlobalTransTarget(client);
Menu menu = new Menu(RemoveLeaderListMenuHandler);
Expand Down Expand Up @@ -1687,56 +1686,58 @@ public void MarkerMenu(int client) {
}

public int MarkerMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (IsValidClient(param1) && IsClientLeader(param1)) {
switch (action) {
case MenuAction_DisplayItem: {
if (g_iMaximumMarker < 1) {
char info[64], display[64];
menu.GetItem(param2, info, sizeof(info));

if (strcmp(info, "normal", false) == 0 && g_iClientMarker[MK_NORMAL][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "Arrow Marker", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "defend", false) == 0 && g_iClientMarker[MK_DEFEND][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "Defend Here", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "zmtp", false) == 0 && g_iClientMarker[MK_ZMTP][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "ZM Teleport", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "nohug", false) == 0 && g_iClientMarker[MK_NOHUG][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "No Doorhug", param1);
return RedrawMenuItem(display);
}
switch (action) {
case MenuAction_DisplayItem: {
if (g_iMaximumMarker < 1) {
char info[64], display[64];
menu.GetItem(param2, info, sizeof(info));

if (strcmp(info, "normal", false) == 0 && g_iClientMarker[MK_NORMAL][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "Arrow Marker", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "defend", false) == 0 && g_iClientMarker[MK_DEFEND][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "Defend Here", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "zmtp", false) == 0 && g_iClientMarker[MK_ZMTP][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "ZM Teleport", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "nohug", false) == 0 && g_iClientMarker[MK_NOHUG][param1] != -1) {
FormatEx(display, sizeof(display), "%T (✘)", "No Doorhug", param1);
return RedrawMenuItem(display);
}
}
}

case MenuAction_Select: {
char info[64];
menu.GetItem(param2, info, sizeof(info));
case MenuAction_Select: {
if (!IsClientLeader(param1))
return 0;

if (strcmp(info, "normal", false) == 0)
ToggleMarkerState(param1, MK_NORMAL);
else if (strcmp(info, "defend", false) == 0)
ToggleMarkerState(param1, MK_DEFEND);
else if (strcmp(info, "zmtp", false) == 0)
ToggleMarkerState(param1, MK_ZMTP);
else if (strcmp(info, "nohug", false) == 0)
ToggleMarkerState(param1, MK_NOHUG);
else if (strcmp(info, "ping", false) == 0)
CreatePing(param1);
else if (strcmp(info, "removemarker", false) == 0)
RemoveAllMarkers(param1);
char info[64];
menu.GetItem(param2, info, sizeof(info));

MarkerMenu(param1);
}
if (strcmp(info, "normal", false) == 0)
ToggleMarkerState(param1, MK_NORMAL);
else if (strcmp(info, "defend", false) == 0)
ToggleMarkerState(param1, MK_DEFEND);
else if (strcmp(info, "zmtp", false) == 0)
ToggleMarkerState(param1, MK_ZMTP);
else if (strcmp(info, "nohug", false) == 0)
ToggleMarkerState(param1, MK_NOHUG);
else if (strcmp(info, "ping", false) == 0)
CreatePing(param1);
else if (strcmp(info, "removemarker", false) == 0)
RemoveAllMarkers(param1);

MarkerMenu(param1);
}

case MenuAction_Cancel: {
case MenuAction_Cancel: {
if (IsClientLeader(param1))
LeaderMenu(param1);
}
}

case MenuAction_End: {
delete menu;
}
case MenuAction_End: {
delete menu;
}
}
return 0;
Expand Down Expand Up @@ -2037,7 +2038,7 @@ stock bool TraceFilterAllEntities(int entity, int contentsMask, int client) {
|| Leader Chat
============================================================================ */
public Action HookPlayerChat(int client, char[] command, int args) {
if (IsValidClient(client) && IsClientLeader(client)) {
if (IsClientLeader(client)) {
char LeaderText[256];
GetCmdArgString(LeaderText, sizeof(LeaderText));
StripQuotes(LeaderText);
Expand All @@ -2063,7 +2064,7 @@ public Action HookPlayerChat(int client, char[] command, int args) {
}

public Action HookPlayerChatTeam(int client, char[] command, int args) {
if (IsValidClient(client) && IsClientLeader(client)) {
if (IsClientLeader(client)) {
char LeaderText[256];
GetCmdArgString(LeaderText, sizeof(LeaderText));
StripQuotes(LeaderText);
Expand Down Expand Up @@ -2358,7 +2359,7 @@ public Action QuickMarkerMenuCommand(int client, const char[] command, int argc)
// Spray x2 : Ping Shortcut
// +Attack3 x4 : Leader Menu (x4: +attack(<ANY>) = attack in loop)
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse) {
if (IsValidClient(client) && IsPlayerAlive(client) && IsClientLeader(client)) {
if (IsClientLeader(client)) {
if (impulse == 0x64) {
QuickMarkerCommand(client);
return Plugin_Continue;
Expand Down Expand Up @@ -2607,15 +2608,15 @@ public bool Filter_NotLeaders(const char[] sPattern, Handle hClients) {

public bool Filter_Leader(const char[] sPattern, Handle hClients) {
for (int i = 1; i <= MaxClients; i++) {
if (IsValidClient(i) && i < MAXLEADER && g_iCurrentLeader[i])
if (IsClientInGame(i) && !IsFakeClient(i) && i < MAXLEADER && g_iCurrentLeader[i])
PushArrayCell(hClients, i);
}
return true;
}

public bool Filter_NotLeader(const char[] sPattern, Handle hClients) {
for (int i = 1; i <= MaxClients; i++) {
if (IsValidClient(i) && (i >= MAXLEADER || !g_iCurrentLeader[i]))
if (IsClientInGame(i) && !IsFakeClient(i) && (i >= MAXLEADER || !g_iCurrentLeader[i]))
PushArrayCell(hClients, i);
}
return true;
Expand Down Expand Up @@ -2743,38 +2744,41 @@ public void ResignConfirmMenu(int client) {
}

public int ResignConfirmMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (IsValidClient(param1) && IsClientLeader(param1)) {
switch (action) {
case MenuAction_DisplayItem: {
char info[64], display[64];
menu.GetItem(param2, info, sizeof(info));
switch (action) {
case MenuAction_DisplayItem: {
char info[64], display[64];
menu.GetItem(param2, info, sizeof(info));

if (strcmp(info, "canceled", false) == 0) {
FormatEx(display, sizeof(display), "%T", "No", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "confirmed", false) == 0) {
FormatEx(display, sizeof(display), "%T", "Yes", param1);
return RedrawMenuItem(display);
}
if (strcmp(info, "canceled", false) == 0) {
FormatEx(display, sizeof(display), "%T", "No", param1);
return RedrawMenuItem(display);
} else if (strcmp(info, "confirmed", false) == 0) {
FormatEx(display, sizeof(display), "%T", "Yes", param1);
return RedrawMenuItem(display);
}
case MenuAction_Select: {
char info[64];
menu.GetItem(param2, info, sizeof(info));
}
case MenuAction_Select: {
if (!IsClientLeader(param1))
return 0;

if (strcmp(info, "confirmed", false) == 0) {
RemoveLeader(param1, R_SELFRESIGN, true);
} else if (strcmp(info, "canceled", false) == 0) {
LeaderMenu(param1);
}
}
case MenuAction_Cancel: {
char info[64];
menu.GetItem(param2, info, sizeof(info));

if (strcmp(info, "confirmed", false) == 0) {
RemoveLeader(param1, R_SELFRESIGN, true);
} else if (strcmp(info, "canceled", false) == 0) {
LeaderMenu(param1);
}
case MenuAction_End: {
delete menu;
}
}
case MenuAction_Cancel: {
if (IsClientLeader(param1))
LeaderMenu(param1);
}
case MenuAction_End: {
delete menu;
}
}

return 0;
}

Expand Down Expand Up @@ -3030,7 +3034,7 @@ void Reset_AllLeaders() {
for (int i = 0; i < g_iTotalLeader; i++) {
int client = g_iCurrentLeader[i];
if (client != -1) {
if (IsValidClient(client)) {
if (IsClientInGame(client) && !IsFakeClient(client)) {
RemoveLeader(client, R_ADMINFORCED, false);
} else {
Reset_LeaderSlotByIndex(i);
Expand Down Expand Up @@ -3063,4 +3067,4 @@ void Reset_ClientFromLeaderSlots(int client) {
g_iCurrentLeader[i] = -1;
}
}
}
}
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/include/zleader.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#define ZLeader_V_MAJOR "3"
#define ZLeader_V_MINOR "7"
#define ZLeader_V_PATCH "1"
#define ZLeader_V_PATCH "2"

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

Expand Down