130 lines
3.7 KiB
SourcePawn
130 lines
3.7 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
#include <sdktools>
|
|
#include <sdkhooks>
|
|
#include <clientprefs>
|
|
#include <multicolors>
|
|
|
|
#pragma newdecls required
|
|
|
|
static const char entityList[][] = { "env_entity_igniter", "env_explosion", "env_fade", "env_fire", "env_hudhint", \
|
|
"env_physexplosion", "env_sprite", "env_sun", \
|
|
"func_breakable", "func_brush", "func_bomb_target", "func_button", "func_door", \
|
|
"func_dustmotes", "func_physbox_multiplayer", "info_overlay", "info_particle_system", \
|
|
"info_player_counterterrorist", "info_player_terrorist", "infodecal", \
|
|
"item_assaultsuit", "item_defuser", "item_kevlar", \
|
|
"light", "light_environment", "light_spot", "move_rope", "path_track", "planted_c4", \
|
|
"point_viewcontrol", "shadow_control", "vgui_screen", "func_tracktrain", "worldspawn", \
|
|
"func_tanktrain"};
|
|
|
|
bool bEnabled[MAXPLAYERS + 1];
|
|
|
|
int iDistance[MAXPLAYERS + 1];
|
|
|
|
float g_fClientOrigin[MAXPLAYERS + 1][3];
|
|
|
|
public void OnPluginStart()
|
|
{
|
|
// Run the cache timer every 0.5 seconds globally
|
|
CreateTimer(0.5, Timer_CacheOrigins, _, TIMER_REPEAT);
|
|
}
|
|
|
|
public Action Timer_CacheOrigins(Handle timer)
|
|
{
|
|
for (int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
GetClientAbsOrigin(i, g_fClientOrigin[i]);
|
|
}
|
|
}
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public Plugin myinfo =
|
|
{
|
|
name = "Render Distance Control",
|
|
author = "null138 & (ty ZombieFeyk), modified for webclient on unloze",
|
|
description = "Sets entities render distance and etc for players",
|
|
version = "3.0.5",
|
|
url = "https://steamcommunity.com/id/null138/"
|
|
}
|
|
|
|
public void OnClientAuthorized(int client, const char[] auth)
|
|
{
|
|
bEnabled[client] = false;
|
|
iDistance[client] = 800;
|
|
|
|
char sIP[32];
|
|
GetClientIP(client, sIP, sizeof(sIP));
|
|
|
|
char allowed_ips[128];
|
|
ConVar sv_set_steam_id_ips = FindConVar("sv_set_steam_id_ips");
|
|
sv_set_steam_id_ips.GetString(allowed_ips, sizeof(allowed_ips));
|
|
if (StrEqual(sIP, allowed_ips))
|
|
{
|
|
bEnabled[client] = true;
|
|
iDistance[client] = 1200;
|
|
}
|
|
}
|
|
|
|
public void OnEntityCreated(int entity, const char[] classname)
|
|
{
|
|
bool hook = false;
|
|
|
|
if (!strncmp(classname, "prop_", 5))
|
|
{
|
|
hook = true;
|
|
}
|
|
else
|
|
{
|
|
for(int i; i < sizeof(entityList); i++)
|
|
{
|
|
if(!strcmp(classname, entityList[i]))
|
|
{
|
|
hook = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hook)
|
|
{
|
|
SDKHook(entity, SDKHook_SetTransmit, DoTransmit);
|
|
}
|
|
}
|
|
|
|
public Action DoTransmit(int entity, int client)
|
|
{
|
|
if (IsFakeClient(client) || !bEnabled[client])
|
|
return Plugin_Continue;
|
|
|
|
if (GetEdictFlags(entity) & FL_EDICT_ALWAYS)
|
|
SetEdictFlags(entity, GetEdictFlags(entity) ^ FL_EDICT_ALWAYS);
|
|
|
|
// Get Entity Origin
|
|
static float entVec[3];
|
|
if (HasEntProp(entity, Prop_Send, "m_vecOrigin"))
|
|
{
|
|
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", entVec);
|
|
}
|
|
else
|
|
{
|
|
return Plugin_Continue; // If it doesnt have an origin, let it render safely
|
|
}
|
|
|
|
// Use GetVectorDistance with UseSquared=true (avoids an expensive Square Root calculation)
|
|
float maxDist = float(iDistance[client]);
|
|
float distanceSq = ((g_fClientOrigin[client][0] - entVec[0]) * (g_fClientOrigin[client][0] - entVec[0])) +
|
|
((g_fClientOrigin[client][1] - entVec[1]) * (g_fClientOrigin[client][1] - entVec[1])) +
|
|
((g_fClientOrigin[client][2] - entVec[2]) * (g_fClientOrigin[client][2] - entVec[2]));
|
|
|
|
if (distanceSq > (maxDist * maxDist))
|
|
{
|
|
return Plugin_Handled; // Out of range, hide it from the software renderer!
|
|
}
|
|
|
|
return Plugin_Continue;
|
|
}
|