AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CS:GO] Invalid Edict. (https://forums.alliedmods.net/showthread.php?t=332120)

SmokieCS 04-24-2021 01:21

[CS:GO] Invalid Edict.
 
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!

Psyk0tik 04-24-2021 01:38

Re: [CS:GO] Invalid Edict.
 
So which one is line 334?

SmokieCS 04-24-2021 05:18

Re: [CS:GO] Invalid Edict.
 
Quote:

Originally Posted by Crasher_3637 (Post 2744953)
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");


Psyk0tik 04-24-2021 05:51

Re: [CS:GO] Invalid Edict.
 
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.

SmokieCS 04-25-2021 01:14

Re: [CS:GO] Invalid Edict.
 
Quote:

Originally Posted by Crasher_3637 (Post 2744961)
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!


All times are GMT -4. The time now is 19:48.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.