#include <sdktools_tempents>
#include <sdktools_tempents_stocks>
#include <sdktools_stringtables>
#include <clientprefs>
public Plugin myinfo =
{
name = "Grenade Trail | Линия за гранатой",
author = "Drumanid",
version = "1.0",
url = "http://vk.com/drumanid"
};
#define LC(%0) for(int %0 = 1; %0 <= MaxClients; ++%0) if(IsClientInGame(%0) && g_bUse[%0])
ConVar g_hPath;
Handle g_hCookie;
int g_iSprite, g_iThrower, g_iDrop;
bool g_bColor, g_bUse[MAXPLAYERS +1];
public void OnPluginStart()
{
g_iThrower = FindSendPropInfo("CBaseGrenade", "m_hThrower");
if(g_iThrower == -1) SetFailState("No found offset: CBaseGrenade/m_hThrower");
g_hPath = CreateConVar("grenadetrail_path", "materials/sprites/laserbeam", "Путь к спрайту без формата файлов 'vtf/vmt'");
ConVar hCvar;
(hCvar = CreateConVar("grenadetrail_colors", "1", "Цвет трейлов? 0 - команды игрока | 1 - самих гранат", _, true, 0.0, true, 1.0)).AddChangeHook(Cvar_Color); g_bColor = hCvar.BoolValue;
(hCvar = CreateConVar("grenadetrail_drop", "1", "Кому показывать трейл? 0 - только тому кто кинул | 1 - только команде | 2 - всем игрокам", _, true, 0.0, true, 1.0)).AddChangeHook(Cvar_Drop); g_iDrop = hCvar.IntValue;
g_hCookie = RegClientCookie("GrenadeTrail", "Спрайт за гранатами", CookieAccess_Public);
RegConsoleCmd("sm_gt", GrenadeTrailCommand); RegConsoleCmd("sm_grenadetrail", GrenadeTrailCommand);
AutoExecConfig(true, "GrenadeTrail");
}
public void Cvar_Color(ConVar hCvar, const char[] sOldValue, const char[] sNewValue) { g_bColor = hCvar.BoolValue; }
public void Cvar_Drop(ConVar hCvar, const char[] sOldValue, const char[] sNewValue) { g_iDrop = hCvar.IntValue; }
public void OnConfigsExecuted()
{
char sBuffer[2][128];
g_hPath.GetString(sBuffer[0], sizeof(sBuffer[]));
FormatEx(sBuffer[1], sizeof(sBuffer[]), "%s.vtf", sBuffer[0]);
AddFileToDownloadsTable(sBuffer[1]);
FormatEx(sBuffer[1], sizeof(sBuffer[]), "%s.vmt", sBuffer[0]);
g_iSprite = PrecacheModel(sBuffer[1], true);
}
public void OnClientCookiesCached(int iClient)
{
char sBuffer[4];
GetClientCookie(iClient, g_hCookie, sBuffer, sizeof(sBuffer));
if(sBuffer[0]) g_bUse[iClient] = view_as<bool>(StringToInt(sBuffer));
else g_bUse[iClient] = true;
}
public Action GrenadeTrailCommand(int iClient, int iArgs)
{
if(iClient)
{
if((g_bUse[iClient] = !g_bUse[iClient]))
{
SetClientCookie(iClient, g_hCookie, "1");
PrintToChat(iClient, "\x01Вы \x04включили \x01линию за гранатой");
}
else
{
SetClientCookie(iClient, g_hCookie, "0");
PrintToChat(iClient, "\x01Вы \x04выключили \x01линию за гранатой");
}
}
return Plugin_Handled;
}
public void OnEntityCreated(int iEntity, char[] sClassname)
{
//if(StrContains(sClassname, "hegrenade_projectile|molotov_projectile|decoy_projectile|flashbang_projectile|smokegrenade_projectile", false) != -1)
if(StrContains(sClassname, "_projectile", false) != -1)
{
//Create datapack? No, GetEdictClassname in the timer!
CreateTimer(0.0, TimerSpawnTrail, EntIndexToEntRef(iEntity));
}
}
public Action TimerSpawnTrail(Handle hTimer, any iEntity)
{
iEntity = EntRefToEntIndex(iEntity);
if(iEntity > 0 && IsValidEntity(iEntity))
{
int iClient = GetEntDataEnt2(iEntity, g_iThrower);
if(iClient > 0 && IsClientInGame(iClient))
{
int iTeam = GetClientTeam(iClient), iColors[4];
if(g_bColor)
{
char sClassname[32];
GetEdictClassname(iEntity, sClassname, sizeof(sClassname));
if(StrContains(sClassname, "hegrenade_projectile", true) == 0) iColors = {220, 20, 60, 255};
else if(StrContains(sClassname, "molotov_projectile", true) == 0) iColors = {255, 69, 0, 255};
else if(StrContains(sClassname, "decoy_projectile", true) == 0) iColors = {46, 139, 87, 255};
else if(StrContains(sClassname, "flashbang_projectile", true) == 0) iColors = {255, 255, 0, 255};
else if(StrContains(sClassname, "smokegrenade_projectile", true) == 0) iColors = {192, 192, 192, 255};
}
else
{
switch(iTeam)
{
case 2: iColors = {255, 0, 0, 255};
case 3: iColors = {0, 0, 255, 255};
}
}
TE_SetupBeamFollow(iEntity, g_iSprite, 0, 1.5, 3.5, 3.5, 5, iColors);
if(g_iDrop == 0) TE_SendToClient(iClient);
else TE_SendTo(iTeam);
}
}
return Plugin_Stop;
}
void TE_SendTo(int iTeam)
{
int[] iClients = new int[MaxClients]; int iTotal;
switch(g_iDrop)
{
case 1:
{
LC(i)
{
if(GetClientTeam(i) == iTeam) iClients[iTotal++] = i;
}
}
case 2:
{
LC(i) iClients[iTotal++] = i;
}
}
if(iTotal > 0) TE_Send(iClients, iTotal);
}