name = "CS:GO Team Grenade Trail (mmcs.pro)",
author = "9iky6, SAZONISCHE",
description = "Adds grenade trails",
int g_mGrenadeColor[DataNade][] =
bool g_bNadeTrailEnabled[MAXPLAYERS+1] = {false, ...};
g_beamsprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
public void OnPluginStart()
g_tNadesName = CreateTrie();
LoadTranslations("team_grenade_trails.phrases");
SetTrieValue( g_tNadesName, "hegrenade_projectile", nade_he );
SetTrieValue( g_tNadesName, "flashbang_projectile", nade_flash );
SetTrieValue( g_tNadesName, "smokegrenade_projectile", nade_smoke );
SetTrieValue( g_tNadesName, "decoy_projectile", nade_decoy );
SetTrieValue( g_tNadesName, "molotov_projectile", nade_molotov );
SetTrieValue( g_tNadesName, "incgrenade_projectile", nade_inc );
SetTrieValue( g_tNadesName, "tagrenade_projectile", nade_tag );
g_hCookie = RegClientCookie("sm_nadetrail", "Nade Trails", CookieAccess_Private);
SetCookieMenuItem(DsCookieMenuHandler, 0, "Nade Trails");
RegConsoleCmd("sm_gtrail", Cmd_NadeTrail);
for (int client = 1; client <= MaxClients; client++)
if(!IsClientInGame(client) || !AreClientCookiesCached(client))
OnClientCookiesCached(client);
public void OnClientCookiesCached(int client)
char[] szBuffer = new char[2];
GetClientCookie(client, g_hCookie, szBuffer, 2);
g_bNadeTrailEnabled[client] = szBuffer[0] ? view_as<bool>(StringToInt(szBuffer)) : true;
public Action Cmd_NadeTrail(int client, int args)
ReplyToCommand(client, "[SM] Only ingame command");
if(g_bNadeTrailEnabled[client])
g_bNadeTrailEnabled[client] = false;
SetClientCookie(client, g_hCookie, "0");
CPrintToChat(client, "%t", "NadeTrail_off");
g_bNadeTrailEnabled[client] = true;
SetClientCookie(client, g_hCookie, "1");
CPrintToChat(client, "%t", "NadeTrail_on");
public void DsCookieMenuHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
case CookieMenuAction_DisplayOption:
Format(buffer, maxlen, "%T", g_bNadeTrailEnabled[client] ? "Off Nade Trail" : "On Nade Trail", client);
case CookieMenuAction_SelectOption:
if(g_bNadeTrailEnabled[client])
g_bNadeTrailEnabled[client] = false;
SetClientCookie(client, g_hCookie, "0");
CPrintToChat(client, "%t", "NadeTrail_off");
FakeClientCommand(client, "sm_settings");
g_bNadeTrailEnabled[client] = true;
SetClientCookie(client, g_hCookie, "1");
CPrintToChat(client, "%t", "NadeTrail_on");
FakeClientCommand(client, "sm_settings");
public void OnEntityCreated(int entity, const char[] classname)
if(IsValidEntity(entity) && GetTrieValue(g_tNadesName, classname, iType))
SDKHook(entity, SDKHook_SpawnPost, OnEntitySpawned);
public void OnEntityDeleted(int entity, const char[] classname)
if(IsValidEntity(entity) && GetTrieValue(g_tNadesName, classname, iType))
SDKUnhook(entity, SDKHook_SpawnPost, OnEntitySpawned);
public void OnEntitySpawned(int entity)
if(!IsValidEdict(entity))
GetEdictClassname(entity, classname, sizeof(classname)-1);
int owner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
if(GetTrieValue(g_tNadesName, classname, iType))
TE_SetupBeamFollow(entity, g_beamsprite, 0, 2.5, 0.9, 1.0, 1, g_mGrenadeColor[iType]);
TE_SendToTeam(GetClientTeam(owner));
stock void TE_SendToTeam(int iTeam, float delay=0.0)
int[] clients = new int[MaxClients];
for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i) && IsPlayerAlive(i) && g_bNadeTrailEnabled[i] && GetClientTeam(i) == iTeam)
TE_Send(clients, total, delay);