Move the IsValidEntity(entity) check above that line, like this:
PHP Code:
public OnEntitySpawned(entity)
{
if(IsValidEntity(entity))
{
decl String:class_name[32];
GetEdictClassname(entity, class_name, 32);
new owner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
if(0 < owner <= MaxClients && IsClientInGame(owner)) // add any other necessary checks here if you want
{
if(StrContains(class_name, "projectile") != -1 && (((GetConVarBool(g_AllowPlayers) || isAdmin(owner)) && Tails[owner]) || GetConVarBool(g_DefaultOn)))
{
if(StrContains(class_name, "hegrenade") != -1 && GetConVarBool(g_EnableHETails))
GetSetColor(g_HEColor);
else if(StrContains(class_name, "flashbang") != -1 && GetConVarBool(g_EnableFlashTails))
GetSetColor(g_FlashColor);
else if(StrContains(class_name, "smoke") != -1 && GetConVarBool(g_EnableSmokeTails))
GetSetColor(g_SmokeColor);
else if(StrContains(class_name, "decoy") != -1 && GetConVarBool(g_EnableDecoyTails))
GetSetColor(g_DecoyColor);
else if(StrContains(class_name, "molotov") != -1 && GetConVarBool(g_EnableMolotovTails))
GetSetColor(g_MolotovColor);
else if(StrContains(class_name, "incgrenade") != -1 && GetConVarBool(g_EnableIncTails))
GetSetColor(g_IncColor);
TE_SetupBeamFollow(entity, g_iBeamSprite, 0, GetConVarFloat(g_TailTime), GetConVarFloat(g_TailWidth), GetConVarFloat(g_TailWidth), GetConVarInt(g_TailFadeTime), TempColorArray);
TE_SendToAll();
}
}
}
}
Edit: I forgot to explain why you need to move the check above that line. Here goes:
Since you are working with that entity, any code you have regarding that entity that comes before validating it first is prone to causing that "invalid entity index" or "invalid edict" error. You always want to validate an entity first before working with it.
__________________