#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "Teammate Glow",
author = "Emptyc",
version = "1.2",
url = ""
};
int g_iEntity[MAXPLAYERS+1],
g_iClientColor[2][4];
char //g_sModelPath[256],
g_sAnimation[64];
bool g_bIsEnabled[MAXPLAYERS+1];
Handle g_hCookies;
public void OnPluginStart()
{
g_hCookies = RegClientCookie("team_glow_cookies", "", CookieAccess_Private);
ConVar
//hCvar = CreateConVar("sm_tg_model", "models/coop/challenge_coin.mdl", "Путь до модели"); hCvar.AddChangeHook(OnModelChanged);
//hCvar.GetString(g_sModelPath, sizeof g_sModelPath);
hCvar = CreateConVar("sm_tg_model_animation", "idle", "Анимация модели"); hCvar.AddChangeHook(OnAnimationChanged);
hCvar.GetString(g_sAnimation, sizeof g_sAnimation);
char sColor[16];
hCvar = CreateConVar("sm_tg_ct_color", "0 238 255 255", "Цвет подсветки кт"); hCvar.AddChangeHook(OnCtColorChanged);
hCvar.GetString(sColor, sizeof sColor);
GetRGBAFromString(1, sColor);
hCvar = CreateConVar("sm_tg_t_color", "255 213 0 255", "Цвет подсветки т"); hCvar.AddChangeHook(OnTColorChanged);
hCvar.GetString(sColor, sizeof sColor);
GetRGBAFromString(0, sColor);
AutoExecConfig(true, "team_glow");
HookEvent("player_spawn", ePS);
HookEvent("player_death", ePD);
RegConsoleCmd("sm_teamglow", OnOffGlow);
for (int i = 1; i <= MaxClients; ++i)
{
if (IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
{
OnClientCookiesCached(i);
}
}
}
public void OnPluginEnd()
{
for (int i = 1; i <= MaxClients; ++i)
{
if (IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
{
RemoveModel(i);
OnClientDisconnect(i);
}
}
}
/*
public void OnModelChanged(ConVar hCvar, char[] sOldValue, char[] sNewValue)
{
strcopy(g_sModelPath, sizeof g_sModelPath, sNewValue);
}*/
public void OnAnimationChanged(ConVar hCvar, char[] sOldValue, char[] sNewValue)
{
strcopy(g_sAnimation, sizeof g_sAnimation, sNewValue);
}
public void OnCtColorChanged(ConVar hCvar, char[] sOldValue, char[] sNewValue)
{
GetRGBAFromString(1, sNewValue);
}
public void OnTColorChanged(ConVar hCvar, char[] sOldValue, char[] sNewValue)
{
GetRGBAFromString(0, sNewValue);
}
void GetRGBAFromString(int iTeam, char[] sBuffer)
{
char sBuffers[4][4];
ExplodeString(sBuffer, " ", sBuffers, sizeof(sBuffers), sizeof(sBuffers[]));
g_iClientColor[iTeam][0] = StringToInt(sBuffers[0]);
g_iClientColor[iTeam][1] = StringToInt(sBuffers[1]);
g_iClientColor[iTeam][2] = StringToInt(sBuffers[2]);
g_iClientColor[iTeam][3] = StringToInt(sBuffers[3]);
}
public void OnClientCookiesCached(int iClient)
{
char sBuff[8];
GetClientCookie(iClient, g_hCookies, sBuff, sizeof sBuff);
g_bIsEnabled[iClient] = !sBuff[0] ? true:!!StringToInt(sBuff);
}
public void OnClientDisconnect(int iClient)
{
RemoveModel(iClient);
char sBuff[8];
IntToString(g_bIsEnabled[iClient], sBuff, sizeof sBuff);
SetClientCookie(iClient, g_hCookies, sBuff);
}
public Action OnOffGlow(int iClient, int iArgs)
{
g_bIsEnabled[iClient] = !g_bIsEnabled[iClient];
PrintToChat(iClient, "[SM] Подсветка тимейтов [%s]", g_bIsEnabled[iClient] ? "Вкл":"Выкл");
return Plugin_Handled;
}
public void ePD(Event event, const char[] name, bool dontBroadcast)
{
RemoveModel(GetClientOfUserId(GetEventInt(event, "userid")));
}
public void ePS(Event event, const char[] name, bool silent)
{
SetGlow(GetClientOfUserId(GetEventInt(event, "userid")));
}
/*
public void OnMapStart()
{
PrecacheModel(g_sModelPath);
}*/
void SetGlow(int client)
{
if (!IsClientInGame(client) || !IsPlayerAlive(client))
{
return;
}
char buffer[128];
GetClientModel(client, buffer, sizeof(buffer));
int iEntity = CreatePlayerModel(client, buffer);
int iOffset = GetEntSendPropOffs(iEntity, "m_clrGlow");
if (iOffset == -1)
{
LogError("Bad offset: \"m_clrGlow\"!");
return;
}
int iTeam = GetClientTeam(client);
SetEntProp(iEntity, Prop_Send, "m_bShouldGlow", true, true);
SetEntProp(iEntity, Prop_Send, "m_nGlowStyle", 0); // 0 - esp / 1,2 - glow
SetEntPropFloat(iEntity, Prop_Send, "m_flGlowMaxDist", 10000000.0);
for (int i = 0; i < 4; i++)
{
SetEntData(iEntity, iOffset + i, g_iClientColor[iTeam-2][i], _, true);
}
}
int CreatePlayerModel(int client, char[] buffer)
{
RemoveModel(client);
int iEntity = CreateEntityByName("prop_dynamic_override");
DispatchKeyValue(iEntity, "model", buffer);
DispatchKeyValue(iEntity, "solid", "0");
DispatchSpawn(iEntity);
SetEntityRenderMode(iEntity, RENDER_TRANSALPHA);
SetEntityRenderColor(iEntity, 255, 255, 255, 0);
SetEntProp(iEntity, Prop_Send, "m_fEffects", (1 << 0)|(1 << 4)|(1 << 6)|(1 << 9));
SetVariantString("!activator");
AcceptEntityInput(iEntity, "SetParent", client, iEntity, 0);
SetVariantString("primary");
AcceptEntityInput(iEntity, "SetParentAttachment", iEntity, iEntity, 0);
SetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity", client);
g_iEntity[client] = EntIndexToEntRef(iEntity);
SDKHook(iEntity, SDKHook_SetTransmit, SetTransmit);
return iEntity;
}
void RemoveModel(int client)
{
int iEntity = EntRefToEntIndex(g_iEntity[client]);
if(IsEntityValid(iEntity)) AcceptEntityInput(iEntity, "Kill");
g_iEntity[client] = 0;
}
bool IsEntityValid(int iEntity)
{
if(iEntity != INVALID_ENT_REFERENCE && iEntity > 0 && IsValidEntity(iEntity)) return true;
return false;
}
public Action SetTransmit(int iEntity, int iClient)
{
int iOwner;
return ((iOwner = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity")) != -1 && (iOwner == iClient || GetClientTeam(iOwner) != GetClientTeam(iClient))) || !g_bIsEnabled[iClient] ? Plugin_Handled:Plugin_Continue;
}