PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
new bool:g_hide[MAXPLAYERS+1];
new g_iWeaponOwner[2048];
new g_bLateLoad;
public Plugin:myinfo =
{
name = "Hide Players",
author = "0wn3r",
description = "Adds commands to show/hide other players.",
version = "1.0",
url = ""
};
public OnPluginStart()
{
RegConsoleCmd("sm_hide", HideCommand);
if (g_bLateLoad)
{
for (new i = 1; i <= MaxClients; i++)
{
if (IsClientConnected(i) && IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
}
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
g_bLateLoad = late;
return APLRes_Success;
}
public OnClientPutInServer(client)
{
g_hide[client] = false;
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip);
SDKHook(client, SDKHook_WeaponDrop, Hook_WeaponDrop);
}
public OnClientDisconnect_Post(client)
{
g_hide[client] = false;
SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
SDKUnhook(client, SDKHook_WeaponEquip, Hook_WeaponEquip);
SDKUnhook(client, SDKHook_WeaponDrop, Hook_WeaponDrop);
}
public OnEntityCreated(entity, const String:classname[])
{
if (entity > MaxClients && entity < 2048)
{
g_iWeaponOwner[entity] = 0;
}
}
public OnEntityDestroyed(entity)
{
if (entity > MaxClients && entity < 2048)
{
g_iWeaponOwner[entity] = 0;
}
}
public Hook_WeaponEquip(client, weapon)
{
if (weapon > MaxClients && weapon < 2048)
{
g_iWeaponOwner[weapon] = client;
SDKHook(weapon, SDKHook_SetTransmit, Hook_SetTransmitWeapon);
}
}
public Hook_WeaponDrop(client, weapon)
{
if (weapon > MaxClients && weapon < 2048)
{
g_iWeaponOwner[weapon] = 0;
SDKUnhook(weapon, SDKHook_SetTransmit, Hook_SetTransmitWeapon);
}
}
public Action:Hook_SetTransmit(entity, client)
{
return (g_hide[client] && IsPlayerAlive(client) && client != entity && (0 < entity <= MaxClients)) ? Plugin_Handled : Plugin_Continue;
}
public Action:Hook_SetTransmitWeapon(entity, client)
{
return (g_hide[client] && IsPlayerAlive(client) && g_iWeaponOwner[entity] && g_iWeaponOwner[entity] != client) ? Plugin_Handled : Plugin_Continue;
}
public Action:HideCommand(client, args)
{
g_hide[client] = !g_hide[client];
return Plugin_Handled;
}
Alive check and weapons hide.