Skip to content

Commit

Permalink
2022_2_10 updated
Browse files Browse the repository at this point in the history
l4d2_spectating_cheat
  • Loading branch information
fbef0102 committed Feb 10, 2022
1 parent 94c9b8c commit 2078b1c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 55 deletions.
Binary file modified l4d2_spectating_cheat/plugins/l4d2_spectating_cheat.smx
Binary file not shown.
21 changes: 17 additions & 4 deletions l4d2_spectating_cheat/readme
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
A spectator who watching the survivor at first person view can now see the infected model glows though the wall
(抓透視外掛神器)

-ChangeLog-
v2.0
- Alive SI glow color
- Ghost SI glow color
- Admin Flag to toggle Speatator watching cheat

v1.0
- Original Request paid work by Target (https://steamcommunity.com/id/Target7/)

-Convar-
no auto generate cfg
//Ghost SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.
cfg\sourcemod\l4d2_specting_cheat.cfg
// Alive SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.
l4d2_specting_cheat_alive_color "255 0 0"

// Ghost SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.
l4d2_specting_cheat_ghost_color "255 255 255"

//Alive SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.
l4d2_specting_cheat_alive_color "255 0 0"
// Players with these flags have access to use command to toggle Speatator watching cheat. (Empty = Everyone, -1: Nobody)
l4d2_specting_cheat_use_command_flag "z"

-Command-
//Toggle Speatator watching cheat (spectator only)
Expand Down
130 changes: 79 additions & 51 deletions l4d2_spectating_cheat/scripting/l4d2_spectating_cheat.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#define ENTITY_SAFE_LIMIT 2000 //don't spawn boxes when it's index is above this

ConVar g_hCvarColor;
ConVar g_hCvarColor2;
int g_iCvarColor;
int g_iCvarColor2;
ConVar g_hCvarColor, g_hCvarColor2, g_hCommandAccess;

int g_iCvarColor, g_iCvarColor2;
char g_sCommandAccesslvl[16];

bool bSpecCheatActive[MAXPLAYERS + 1]; //spectatpr open watch
int g_iModelIndex[MAXPLAYERS+1]; // Player Model entity reference
Expand All @@ -33,28 +33,31 @@ public Plugin myinfo =
name = "l4d2 specating cheat",
author = "Harry Potter",
description = "A spectator who watching the survivor at first person view would see the infected model glows though the wall",
version = "1.9",
version = "2.0",
url = "https://steamcommunity.com/id/fbef0102/"
}

public void OnPluginStart()
{
g_hCvarColor = CreateConVar( "l4d2_specting_cheat_ghost_color", "255 255 255", "Ghost SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.", FCVAR_NOTIFY);
g_hCvarColor2 = CreateConVar( "l4d2_specting_cheat_alive_color", "255 0 0", "Alive SI glow color, Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.", FCVAR_NOTIFY);

char sColor[16],sColor2[16];
g_hCvarColor.GetString(sColor, sizeof(sColor));
g_iCvarColor = GetColor(sColor);
g_hCvarColor2.GetString(sColor2, sizeof(sColor2));
g_iCvarColor2 = GetColor(sColor2);

g_hCommandAccess = CreateConVar( "l4d2_specting_cheat_use_command_flag", "z", "Players with these flags have access to use command to toggle Speatator watching cheat. (Empty = Everyone, -1: Nobody)", FCVAR_NOTIFY);

GetCvars();
g_hCvarColor.AddChangeHook(ConVarChanged_Glow);
g_hCvarColor2.AddChangeHook(ConVarChanged_Glow_2);
g_hCommandAccess.AddChangeHook(ConVarChanged_Cvars);

//Autoconfig for plugin
AutoExecConfig(true, "l4d2_specting_cheat");

HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_team", Event_PlayerTeam);
HookEvent("round_end", Event_RoundEnd);
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("map_transition", Event_RoundEnd, EventHookMode_PostNoCopy); //戰役模式下過關到下一關的時候 (沒有觸發round_end)
HookEvent("mission_lost", Event_RoundEnd, EventHookMode_PostNoCopy); //戰役模式下滅團重來該關卡的時候 (之後有觸發round_end)
HookEvent("finale_vehicle_leaving", Event_RoundEnd, EventHookMode_PostNoCopy); //救援載具離開之時 (沒有觸發round_end)

HookEvent("player_disconnect", Event_PlayerDisconnect);

Expand All @@ -67,29 +70,27 @@ public void OnPluginStart()
RegConsoleCmd("sm_hellocheat", ToggleSpecCheatCmd, "Toggle Speatator watching cheat");
RegConsoleCmd("sm_areyoucheat", ToggleSpecCheatCmd, "Toggle Speatator watching cheat");
RegConsoleCmd("sm_fuckyoucheat", ToggleSpecCheatCmd, "Toggle Speatator watching cheat");

Clear();
}

public void OnPluginEnd() //unload插件的時候
{
UnhookEvent("player_spawn", Event_PlayerSpawn);
UnhookEvent("player_death", Event_PlayerDeath);
UnhookEvent("player_team", Event_PlayerTeam);
UnhookEvent("round_end", Event_RoundEnd);

UnhookEvent("player_disconnect", Event_PlayerDisconnect);

Clear();
RemoveAllModelGlow();
}

public Action ToggleSpecCheatCmd(int client, int args)
{
if(GetClientTeam(client)!= L4D_TEAM_SPECTATOR)
if(client == 0 || GetClientTeam(client)!= L4D_TEAM_SPECTATOR)
return Plugin_Handled;

bSpecCheatActive[client] = !bSpecCheatActive[client];
PrintToChat(client, "\x01[\x04WatchMode\x01]\x03 Watch Cheater Mode \x01 is now \x05%s\x01.", (bSpecCheatActive[client] ? "On" : "Off"));

if(HasAccess(client, g_sCommandAccesslvl))
{
bSpecCheatActive[client] = !bSpecCheatActive[client];
PrintToChat(client, "\x01[\x04WatchMode\x01]\x03 Watch Cheater Mode \x01 is now \x05%s\x01.", (bSpecCheatActive[client] ? "On" : "Off"));
}
else
{
PrintToChat(client, "\x01[\x04WatchMode\x01]\x03 You don't have access.");
}

return Plugin_Handled;
}
Expand All @@ -112,20 +113,15 @@ public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast
{
int client = GetClientOfUserId(event.GetInt("userid"));

if(client && IsClientInGame(client) && GetClientTeam(client) == L4D_TEAM_INFECTED)
{
CreateInfectedModelGlow(client);
}
RemoveInfectedModelGlow(client); //有可能特感變成坦克復活
CreateInfectedModelGlow(client);
}

public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));

if(client && IsClientInGame(client) && GetClientTeam(client) == L4D_TEAM_INFECTED)
{
RemoveInfectedModelGlow(client);
}
RemoveInfectedModelGlow(client);
}

public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)
Expand All @@ -137,14 +133,11 @@ public void Event_PlayerTeam(Event event, const char[] name, bool dontBroadcast)

public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
for( int i = 1; i <= MaxClients; i++ )
RemoveInfectedModelGlow(i);
RemoveAllModelGlow();
}

public void CreateInfectedModelGlow(int client)
{
RemoveInfectedModelGlow(client); //有可能特感變成坦克復活

if (!client ||
!IsClientInGame(client) ||
GetClientTeam(client) != L4D_TEAM_INFECTED ||
Expand All @@ -157,12 +150,12 @@ public void CreateInfectedModelGlow(int client)
//PrintToChatAll("%N: %s",client,sModelName);

// Spawn dynamic prop entity
int entity = CreateEntityByName("prop_dynamic_override");
int entity = CreateEntityByName("prop_dynamic_ornament");
if (CheckIfEntityMax( entity ) == false)
return;

// Set new fake model
PrecacheModel(sModelName);
//PrecacheModel(sModelName);
SetEntityModel(entity, sModelName);
DispatchSpawn(entity);

Expand Down Expand Up @@ -229,10 +222,8 @@ int GetColor(char[] sTemp)
}

public void ConVarChanged_Glow(Handle convar, const char[] oldValue, const char[] newValue) {
char sColor[16];
g_hCvarColor.GetString(sColor, sizeof(sColor));
g_iCvarColor = GetColor(sColor);

GetCvars();

int entity;
for(int i=1; i<=MaxClients ; ++i)
{
Expand All @@ -249,9 +240,7 @@ public void ConVarChanged_Glow(Handle convar, const char[] oldValue, const char[
}

public void ConVarChanged_Glow_2(Handle convar, const char[] oldValue, const char[] newValue) {
char sColor2[16];
g_hCvarColor2.GetString(sColor2, sizeof(sColor2));
g_iCvarColor2 = GetColor(sColor2);
GetCvars();

int entity;
for(int i=1; i<=MaxClients ; ++i)
Expand All @@ -268,23 +257,44 @@ public void ConVarChanged_Glow_2(Handle convar, const char[] oldValue, const cha
}
}

public void ConVarChanged_Cvars(Handle convar, const char[] oldValue, const char[] newValue) {
GetCvars();

for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(HasAccess(i, g_sCommandAccesslvl) == false) bSpecCheatActive[i] = false;
}
}
}

void GetCvars()
{
char sColor[16],sColor2[16];
g_hCvarColor.GetString(sColor, sizeof(sColor));
g_iCvarColor = GetColor(sColor);
g_hCvarColor2.GetString(sColor2, sizeof(sColor2));
g_iCvarColor2 = GetColor(sColor2);
g_hCommandAccess.GetString(g_sCommandAccesslvl,sizeof(g_sCommandAccesslvl));
}

bool IsPlayerGhost(int client)
{
return view_as<bool>(GetEntProp(client, Prop_Send, "m_isGhost"));
}

bool IsValidEntRef(int entity)
{
if( entity >0 && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE)
if( entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE)
return true;
return false;
}

void Clear()
void RemoveAllModelGlow()
{
for (int i = 1; i <= MaxClients; i++)
{
bSpecCheatActive[i] = false;
RemoveInfectedModelGlow(i);
}
}
Expand All @@ -299,4 +309,22 @@ bool CheckIfEntityMax(int entity)
return false;
}
return true;
}

public bool HasAccess(int client, char[] g_sAcclvl)
{
// no permissions set
if (strlen(g_sAcclvl) == 0)
return true;

else if (StrEqual(g_sAcclvl, "-1"))
return false;

// check permissions
if ( GetUserFlagBits(client) & ReadFlagString(g_sAcclvl) )
{
return true;
}

return false;
}

0 comments on commit 2078b1c

Please sign in to comment.