Skip to content
Open
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
80 changes: 24 additions & 56 deletions addons/sourcemod/scripting/ThirdPerson.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ bool g_bThirdPerson[MAXPLAYERS + 1] = { false, ... };
bool g_bMirror[MAXPLAYERS + 1] = { false, ... };

bool g_bZombieReloaded = false;
bool g_bZombieSpawned = false;
bool g_bTeamManager = false;
bool g_bFullUpdate = false;

ConVar g_cvAllowThirdPerson;
Expand All @@ -27,7 +25,7 @@ public Plugin myinfo =
name = "ThirdPerson",
author = "BotoX, maxime1907, .Rushaway",
description = "Allow players/admins to toggle thirdperson on themselves/players.",
version = "1.3.6"
version = "1.3.7"
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
Expand All @@ -46,7 +44,6 @@ public void OnPluginStart()
RegConsoleCmd("sm_tp", Command_ThirdPerson, "Toggle thirdperson");
RegConsoleCmd("sm_mirror", Command_Mirror, "Toggle Rotational Thirdperson view");

HookEvent("round_start", Event_RoundStart, EventHookMode_Pre);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_spawn", Event_PlayerSpawn);

Expand All @@ -64,7 +61,6 @@ public void OnConVarChanged(ConVar cvar, const char[] oldVal, const char[] newVa
public void OnAllPluginsLoaded()
{
g_bZombieReloaded = LibraryExists("zombiereloaded");
g_bTeamManager = LibraryExists("TeamManager");
g_bFullUpdate = LibraryExists("FullUpdate");
}

Expand All @@ -74,10 +70,6 @@ public void OnLibraryAdded(const char[] name)
{
g_bZombieReloaded = true;
}
else if (strcmp(name, "TeamManager", false) == 0)
{
g_bTeamManager = true;
}
else if (strcmp(name, "FullUpdate", false) == 0)
{
g_bFullUpdate = true;
Expand All @@ -90,10 +82,6 @@ public void OnLibraryRemoved(const char[] name)
{
g_bZombieReloaded = false;
}
else if (strcmp(name, "TeamManager", false) == 0)
{
g_bTeamManager = false;
}
else if (strcmp(name, "FullUpdate", false) == 0)
{
g_bFullUpdate = false;
Expand All @@ -112,11 +100,6 @@ public void OnClientDisconnect(int client)
g_bMirror[client] = false;
}

public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
g_bZombieSpawned = false;
}

public Action Command_Mirror(int client, int args)
{
if(!IsValidClient(client, true, true))
Expand All @@ -125,14 +108,6 @@ public Action Command_Mirror(int client, int args)
return Plugin_Handled;
}

#if defined _zr_included
if(!g_bZombieSpawned)
{
CReplyToCommand(client, "{green}[SM] {default}You may not use this command as there is no zombie spawned.");
return Plugin_Handled;
}
#endif

if(g_bThirdPerson[client])
ThirdPersonOff(client, false);

Expand All @@ -152,14 +127,6 @@ public Action Command_ThirdPerson(int client, int args)
return Plugin_Handled;
}

#if defined _zr_included
if(!g_bZombieSpawned)
{
CReplyToCommand(client, "{green}[SM] {default}You may not use this command as there is no zombie spawned.");
return Plugin_Handled;
}
#endif

if (g_bMirror[client])
MirrorOff(client);

Expand Down Expand Up @@ -211,14 +178,6 @@ public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadca
return Plugin_Continue;
}

#if defined _zr_included
public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)
{
if (motherInfect && g_bTeamManager)
g_bZombieSpawned = true;
}
#endif

void ThirdPersonOn(int client)
{
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", 0);
Expand Down Expand Up @@ -262,27 +221,36 @@ stock void ResetClient(int client, bool bFixUI = false)
stock void FixClientUI(int client)
{
int currentTeam = GetClientTeam(client);
if (currentTeam < CS_TEAM_T)
return;

ChangeClientTeam(client, CS_TEAM_SPECTATOR);
if (!g_bZombieReloaded)
CS_SwitchTeam(client, currentTeam);
else

// Always put the client back in their own team: forcing CS_TEAM_T before the mother zombie
// spawned gives the engine a spawnable T and it restarts the round (Game_Commencing).
CS_SwitchTeam(client, currentTeam);

if (g_bZombieReloaded && !IsPlayerAlive(client))
{
CS_SwitchTeam(client, CS_TEAM_T);
if (!IsPlayerAlive(client))
{
ConVar cvRespawn = FindConVar("zr_respawn");
if (cvRespawn.IntValue == 1)
RequestFrame(RespawnClient, client);
ConVar cvRespawn = FindConVar("zr_respawn");
if (cvRespawn != null && cvRespawn.IntValue == 1)
RequestFrame(RespawnClient, GetClientUserId(client));

delete cvRespawn;
}
delete cvRespawn;
}
}

stock void RespawnClient(int client)
stock void RespawnClient(int userid)
{
if (IsClientInGame(client))
CS_RespawnPlayer(client);
int client = GetClientOfUserId(userid);
if (!client || IsPlayerAlive(client))
return;

// The client may have been moved to spectator in the meantime (e.g. sm_spec)
if (GetClientTeam(client) < CS_TEAM_T)
return;

CS_RespawnPlayer(client);
}

stock void MirrorOn(int client, bool notify = true)
Expand Down
Loading