Spectate: don't require zombiereloaded

This commit is contained in:
BotoX 2019-12-05 19:44:21 +01:00
parent ca37ab2a84
commit 85a94837a2
2 changed files with 42 additions and 13 deletions

View File

@ -3,11 +3,15 @@
#include <sourcemod> #include <sourcemod>
#include <sdktools> #include <sdktools>
#include <cstrike> #include <cstrike>
#include <zombiereloaded>
#undef REQUIRE_PLUGIN
#tryinclude <zombiereloaded>
#define REQUIRE_PLUGIN
#include "loghelper.inc" #include "loghelper.inc"
#pragma newdecls required #pragma newdecls required
bool g_bZRLoaded;
Handle g_hFwd_SpectateByCommand; Handle g_hFwd_SpectateByCommand;
bool g_bRoundEnd; bool g_bRoundEnd;
@ -53,6 +57,23 @@ public void OnPluginStart()
HookEvent("round_end", OnRoundEnd, EventHookMode_Pre); HookEvent("round_end", OnRoundEnd, EventHookMode_Pre);
} }
public void OnAllPluginsLoaded()
{
g_bZRLoaded = LibraryExists("zombiereloaded");
}
public void OnLibraryAdded(const char[] sName)
{
if (strcmp(sName, "zombiereloaded", false) == 0)
g_bZRLoaded = true;
}
public void OnLibraryRemoved(const char[] sName)
{
if (strcmp(sName, "zombiereloaded", false) == 0)
g_bZRLoaded = false;
}
public void OnMapStart() public void OnMapStart()
{ {
GetTeams(); GetTeams();
@ -92,7 +113,8 @@ public Action Command_Spectate(int client, int argc)
return Plugin_Handled; return Plugin_Handled;
} }
if (IsPlayerAlive(client) && ZR_IsClientZombie(client)) #if defined _zr_included
if (g_bZRLoaded && IsPlayerAlive(client) && ZR_IsClientZombie(client))
{ {
bool bOnlyZombie = true; bool bOnlyZombie = true;
for (int i = 1; i <= MaxClients; i++) for (int i = 1; i <= MaxClients; i++)
@ -110,13 +132,16 @@ public Action Command_Spectate(int client, int argc)
return Plugin_Handled; return Plugin_Handled;
} }
} }
#endif
if (!argc) if (!argc)
{ {
if (GetClientTeam(client) != CS_TEAM_SPECTATOR) if (GetClientTeam(client) != CS_TEAM_SPECTATOR)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd) #if defined _zr_included
if (g_bZRLoaded && IsPlayerAlive(client) && ZR_IsClientHuman(client) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
#endif
Call_StartForward(g_hFwd_SpectateByCommand); Call_StartForward(g_hFwd_SpectateByCommand);
Call_PushCell(client); Call_PushCell(client);
@ -145,8 +170,10 @@ public Action Command_Spectate(int client, int argc)
if (GetClientTeam(client) != CS_TEAM_SPECTATOR) if (GetClientTeam(client) != CS_TEAM_SPECTATOR)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd) #if defined _zr_included
if (g_bZRLoaded && IsPlayerAlive(client) && ZR_IsClientHuman(client) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
#endif
Call_StartForward(g_hFwd_SpectateByCommand); Call_StartForward(g_hFwd_SpectateByCommand);
Call_PushCell(client); Call_PushCell(client);
@ -175,8 +202,10 @@ public Action Command_Spectate(int client, int argc)
public Action Command_Suicide(int client, char[] command, int args) public Action Command_Suicide(int client, char[] command, int args)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd) #if defined _zr_included
if (g_bZRLoaded && IsPlayerAlive(client) && ZR_IsClientHuman(client) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
#endif
return Plugin_Continue; return Plugin_Continue;
} }
@ -233,4 +262,4 @@ stock void StripPlayerKnifes(int client)
AcceptEntityInput(w, "Kill"); AcceptEntityInput(w, "Kill");
} }
} }
} }

View File

@ -48,7 +48,7 @@ stock LogPlayerEvent(client, const String:verb[], const String:event[], bool:dis
if (IsValidPlayer(client)) if (IsValidPlayer(client))
{ {
decl String:player_authid[32]; decl String:player_authid[32];
if (!GetClientAuthString(client, player_authid, sizeof(player_authid))) if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{ {
strcopy(player_authid, sizeof(player_authid), "UNKNOWN"); strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
} }
@ -74,12 +74,12 @@ stock LogPlyrPlyrEvent(client, victim, const String:verb[], const String:event[]
if (IsValidPlayer(client) && IsValidPlayer(victim)) if (IsValidPlayer(client) && IsValidPlayer(victim))
{ {
decl String:player_authid[32]; decl String:player_authid[32];
if (!GetClientAuthString(client, player_authid, sizeof(player_authid))) if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{ {
strcopy(player_authid, sizeof(player_authid), "UNKNOWN"); strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
} }
decl String:victim_authid[32]; decl String:victim_authid[32];
if (!GetClientAuthString(victim, victim_authid, sizeof(victim_authid))) if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{ {
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN"); strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
} }
@ -106,12 +106,12 @@ stock LogKill(attacker, victim, const String:weapon[], bool:display_location = f
if (IsValidPlayer(attacker) && IsValidPlayer(victim)) if (IsValidPlayer(attacker) && IsValidPlayer(victim))
{ {
decl String:attacker_authid[32]; decl String:attacker_authid[32];
if (!GetClientAuthString(attacker, attacker_authid, sizeof(attacker_authid))) if (!GetClientAuthId(attacker, AuthId_Steam2, attacker_authid, sizeof(attacker_authid)))
{ {
strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN"); strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN");
} }
decl String:victim_authid[32]; decl String:victim_authid[32];
if (!GetClientAuthString(victim, victim_authid, sizeof(victim_authid))) if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{ {
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN"); strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
} }
@ -138,12 +138,12 @@ stock LogPSKillTraj(attacker, victim, const String:weapon[])
if (IsValidPlayer(attacker) && IsValidPlayer(victim)) if (IsValidPlayer(attacker) && IsValidPlayer(victim))
{ {
decl String:attacker_authid[32]; decl String:attacker_authid[32];
if (!GetClientAuthString(attacker, attacker_authid, sizeof(attacker_authid))) if (!GetClientAuthId(attacker, AuthId_Steam2, attacker_authid, sizeof(attacker_authid)))
{ {
strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN"); strcopy(attacker_authid, sizeof(attacker_authid), "UNKNOWN");
} }
decl String:victim_authid[32]; decl String:victim_authid[32];
if (!GetClientAuthString(victim, victim_authid, sizeof(victim_authid))) if (!GetClientAuthId(victim, AuthId_Steam2, victim_authid, sizeof(victim_authid)))
{ {
strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN"); strcopy(victim_authid, sizeof(victim_authid), "UNKNOWN");
} }