Raised This Month: $209 Target: $400
 52% 

[CS:GO] Invalid Edict.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SmokieCS
AlliedModders Donor
Join Date: Nov 2019
Location: Denmark
Old 04-24-2021 , 01:21   [CS:GO] Invalid Edict.
Reply With Quote #1

Hello.

I have tried searching the forums, but I could not really figure out a solution to my problem. So now I decided to make a thread, to maybe get an answer to my questions.


I have this code
Code:
public OnEntitySpawned(entity)
{
	decl String:class_name[32];
	GetEdictClassname(entity, class_name, 32);
	new owner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
	
	if(StrContains(class_name, "projectile") != -1 && IsValidEntity(entity) && (((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();
	}
}
But I get this error
Code:
L 04/24/2021 - 06:01:16: [SM] Call stack trace:
L 04/24/2021 - 06:01:16: [SM]   [0] GetEdictClassname
L 04/24/2021 - 06:01:16: [SM]   [1] Line 334, /home/forums/content/files/2/4/8/3/8/6/133755.attach::OnEntitySpawned
L 04/24/2021 - 06:01:16: [SM] Exception reported: Invalid edict (2138 - -1484847014)
L 04/24/2021 - 06:01:16: [SM] Blaming: NadeTails.smx
What could be wrong? At first I thought it was the "m_hOwnerEntity that could be the problem, but then I noticed it was in Line 334.

Thank you in advance!
__________________
Co-Owner - https://tfrag.dk/
Server Manager - https://hartegif.dk/e-sport/
Freelance Server Helper etc.
SmokieCS is offline
Crasher_3637
Veteran Member
Join Date: May 2012
Old 04-24-2021 , 01:38   Re: [CS:GO] Invalid Edict.
Reply With Quote #2

So which one is line 334?
__________________
AFK like JFK
Crasher_3637 is offline
SmokieCS
AlliedModders Donor
Join Date: Nov 2019
Location: Denmark
Old 04-24-2021 , 05:18   Re: [CS:GO] Invalid Edict.
Reply With Quote #3

Quote:
Originally Posted by Crasher_3637 View Post
So which one is line 334?
Damn it! Thought that was taken with the copy. Sorry about that!

It is this line of code:

Code:
333	decl String:class_name[32];
334	GetEdictClassname(entity, class_name, 32);
335	new owner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
__________________
Co-Owner - https://tfrag.dk/
Server Manager - https://hartegif.dk/e-sport/
Freelance Server Helper etc.
SmokieCS is offline
Crasher_3637
Veteran Member
Join Date: May 2012
Old 04-24-2021 , 05:51   Re: [CS:GO] Invalid Edict.
Reply With Quote #4

Move the IsValidEntity(entity) check above that line, like this:
PHP Code:
public OnEntitySpawned(entity)
{
    if(
IsValidEntity(entity))
    {
        
decl String:class_name[32];
        
GetEdictClassname(entityclass_name32);
        new 
owner GetEntPropEnt(entityProp_Data"m_hOwnerEntity");
        if(
owner <= MaxClients && IsClientInGame(owner)) // add any other necessary checks here if you want
        
{
            if(
StrContains(class_name"projectile") != -&& (((GetConVarBool(g_AllowPlayers) || isAdmin(owner)) && Tails[owner]) || GetConVarBool(g_DefaultOn)))
            {
                if(
StrContains(class_name"hegrenade") != -&& GetConVarBool(g_EnableHETails))
                    
GetSetColor(g_HEColor);
                else if(
StrContains(class_name"flashbang") != -&& GetConVarBool(g_EnableFlashTails))
                    
GetSetColor(g_FlashColor);
                else if(
StrContains(class_name"smoke") != -&& GetConVarBool(g_EnableSmokeTails))
                    
GetSetColor(g_SmokeColor);
                else if(
StrContains(class_name"decoy") != -&& GetConVarBool(g_EnableDecoyTails))
                    
GetSetColor(g_DecoyColor);
                else if(
StrContains(class_name"molotov") != -&& GetConVarBool(g_EnableMolotovTails))
                    
GetSetColor(g_MolotovColor);
                else if(
StrContains(class_name"incgrenade") != -&& GetConVarBool(g_EnableIncTails))
                    
GetSetColor(g_IncColor);
                
TE_SetupBeamFollow(entityg_iBeamSprite0GetConVarFloat(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.
__________________
AFK like JFK

Last edited by Crasher_3637; 04-24-2021 at 05:59.
Crasher_3637 is offline
SmokieCS
AlliedModders Donor
Join Date: Nov 2019
Location: Denmark
Old 04-25-2021 , 01:14   Re: [CS:GO] Invalid Edict.
Reply With Quote #5

Quote:
Originally Posted by Crasher_3637 View Post
Move the IsValidEntity(entity) check above that line, like this:
PHP Code:
public OnEntitySpawned(entity)
{
    if(
IsValidEntity(entity))
    {
        
decl String:class_name[32];
        
GetEdictClassname(entityclass_name32);
        new 
owner GetEntPropEnt(entityProp_Data"m_hOwnerEntity");
        if(
owner <= MaxClients && IsClientInGame(owner)) // add any other necessary checks here if you want
        
{
            if(
StrContains(class_name"projectile") != -&& (((GetConVarBool(g_AllowPlayers) || isAdmin(owner)) && Tails[owner]) || GetConVarBool(g_DefaultOn)))
            {
                if(
StrContains(class_name"hegrenade") != -&& GetConVarBool(g_EnableHETails))
                    
GetSetColor(g_HEColor);
                else if(
StrContains(class_name"flashbang") != -&& GetConVarBool(g_EnableFlashTails))
                    
GetSetColor(g_FlashColor);
                else if(
StrContains(class_name"smoke") != -&& GetConVarBool(g_EnableSmokeTails))
                    
GetSetColor(g_SmokeColor);
                else if(
StrContains(class_name"decoy") != -&& GetConVarBool(g_EnableDecoyTails))
                    
GetSetColor(g_DecoyColor);
                else if(
StrContains(class_name"molotov") != -&& GetConVarBool(g_EnableMolotovTails))
                    
GetSetColor(g_MolotovColor);
                else if(
StrContains(class_name"incgrenade") != -&& GetConVarBool(g_EnableIncTails))
                    
GetSetColor(g_IncColor);
                
TE_SetupBeamFollow(entityg_iBeamSprite0GetConVarFloat(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.
Thank you so much for the explanation also! It make so much sense!
__________________
Co-Owner - https://tfrag.dk/
Server Manager - https://hartegif.dk/e-sport/
Freelance Server Helper etc.
SmokieCS is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:16.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode