Raised This Month: $51 Target: $400
 12% 

[TF2] Entity is not a CBaseEntity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Koolman
Junior Member
Join Date: Mar 2014
Location: United Kingdom
Old 03-03-2014 , 14:25   [TF2] Entity is not a CBaseEntity
Reply With Quote #1

Hello there. I am attempting to fix a plugin for the server that I code for, but I am having difficulties solving the issue.

Error given in the console
PHP Code:
L 03/03/2014 19:11:23: [SMNative "AcceptEntityInput" reportedEntity 1095 (1095is not a CBaseEntity
L 03
/03/2014 19:11:23: [SMDisplaying call stack trace for plugin "DFSPets3.smx":
L 03/03/2014 19:11:23: [SM]   [0]  Line 388src\dfs\STOREHOUSE\STAGE3\DFSPets3.sp::KillPet()
L 03/03/2014 19:11:23: [SM]   [1]  Line 151src\dfs\STOREHOUSE\STAGE3\DFSPets3.sp::Event_Spawn() 
Full source code
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
#include <tf2>
#include <tf2_stocks>
#include <gmg\misc>
#include <gmg\users>
#include <dfs\pets>
#include <gmg\colors>
#pragma semicolon 1

#define SOUND_SPAWN "ambient/machines/catapult_throw.wav"

new pet[MAXPLAYERS+1];
new 
petType[MAXPLAYERS+1];
new 
String:petName[MAXPLAYERS+1][32];
new 
petEnabled[MAXPLAYERS+1];
new 
petColor[MAXPLAYERS+1];
new 
petHappiness[MAXPLAYERS+1];
new 
petParticle[MAXPLAYERS+1];
new 
petState[MAXPLAYERS+1];

new 
Handle:soundTimer[MAXPLAYERS+1] = INVALID_HANDLE;

public 
Plugin:myinfo 
{
    
name "DFS - Pets",
    
author "Koolman + noodleboy347",
    
description "Get off me you",
    
version "1.0.0",
    
url "None"
}

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_pet"Command_Pet);
    
HookEvent("player_spawn"Event_Spawn);
    
HookEvent("player_death"Event_Death);
}

public 
OnPluginEnd()
{
    for(new 
i=1i<=GetMaxClients(); i++)
    {
        if(!
IsValidEntity(i)) continue;
        if(!
IsValidEntity(pet[i])) continue;
        
KillPet(i);
    }
}

public 
OnMapStart()
{
    for(new 
i=1i<=GetMaxClients(); i++)
    {
        if(!
IsValidEntity(i)) continue;
        if(!
IsValidEntity(pet[i])) continue;
        
KillPet(i);
    }
    
PrecacheSound(SOUND_SPAWN);
    for(new 
i=1i<sizeof(petInfo); i++)
    {
        
PrecacheModel(petInfo[i][iModel]);
        
PrecacheSound(petInfo[i][iSoundGeneric]);
        
PrecacheSound(petInfo[i][iSoundJump]);
    }
}

public 
OnClientPutInServer(client)
{
    
pet[client] = 0;
    
petColor[client] = 0;
    
petHappiness[client] = 0;
    
petType[client] = 0;
    
petEnabled[client] = true;
}

public 
OnClientDisconnect(client)
{
    
KillPet(client);
}

public 
Action:Command_Pet(clientargs)
{
    if(
petType[client] == 0)
    {
        
ReplyToCommand(client"You don't have a pet!");
        return 
Plugin_Handled;
    }
    
    new 
Handle:panel CreatePanel();
    
    
decl String:line[64];
    
Format(linesizeof(line), "%s the %s"petName[client], petInfo[petType[client]][iName]);
    
    
SetPanelTitle(panelline);
    
    if(
petHappiness[client] >= 16)
        
Format(linesizeof(line), "Happiness: Supreme");
    else if(
petHappiness[client] >= 8)
        
Format(linesizeof(line), "Happiness: Content");
    else if(
petHappiness[client] >= 4)
        
Format(linesizeof(line), "Happiness: Poor");
    else
        
Format(linesizeof(line), "Happiness: Terrible");
        
    
    
DrawPanelText(panelline);
    
    
DrawPanelText(panel" ");
    
    if(
petEnabled[client])
        
DrawPanelItem(panel"Put Away");
    else
        
DrawPanelItem(panel"Send Out");
        
    
DrawPanelItem(panel"Close");
    
    
SendPanelToClient(panelclientMenu_Pet60);
    
CloseHandle(panel);
    return 
Plugin_Handled;
}

public 
Menu_Pet(Handle:menuMenuAction:actionclientoption)
{
    if(
action == MenuAction_Select)
    {
        if(
option != 1)
            return;
        
        
KillPet(client);
        
        
petEnabled[client] = !petEnabled[client];
        
PrintToChat(client"%s was %s"petName[client], petEnabled[client] ? "sent out" "put away");
        if(
petEnabled[client])
            
SpawnPet(client);
    }
}

public 
Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));    
    
    if(
User_GetPet(client) != 0)
    {
        
User_GetPetName(clientpetName[client]);
        
petType[client] = User_GetPet(client);
        
petColor[client] = User_GetPetColor(client);
        
petHappiness[client] = User_GetPetHappiness(client);
        
        
KillPet(client);
        
SpawnPet(client);
    }
    else if(
User_GetPet(client) != petType[client])
    {
        
petType[client] = User_GetPet(client);
        
KillPet(client);
        
SpawnPet(client);
    }
}

public 
Action:Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(
pet[client] != 0)
        
KillPet(client);
}

SpawnPet(client)
{
    if(!
petEnabled[client] || User_GetPet(client) == 0)
        return;
    
    
decl Float:pos[3];
    
GetClientAbsOrigin(clientpos);
    
OffsetLocation(pos);
    
    if(!(
pet[client] = CreateEntityByName("prop_physics_override")))
        return;
        
    
pet[client] = CreateEntityByName("prop_physics_override");
    
PrecacheModel(petInfo[petType[client]][iModel]);
    
SetEntityModel(pet[client], petInfo[petType[client]][iModel]);
    
DispatchKeyValue(pet[client], "StartDisabled""false");
    
DispatchSpawn(pet[client]);
    
TeleportEntity(pet[client], posNULL_VECTORNULL_VECTOR);
    
SetEntityMoveType(pet[client], MOVETYPE_CUSTOM);
    
AcceptEntityInput(pet[client], "Enable");
    
SetEntProp(pet[client], Prop_Send"m_nSolidType"0);
    
    
CreateParticle("ExplosionCore_sapperdestroyed"pos);
    
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pospet[client]);
    
EmitAmbientSound(SOUND_SPAWNpos);
    
    
SetEntityRenderMode(pet[client], RENDER_TRANSADD);
    switch(
User_GetPetColor(client))
    {
        case 
PETCOLOR_REDSetEntityRenderColor(pet[client], 25500255);
        case 
PETCOLOR_GREENSetEntityRenderColor(pet[client], 02550255);
        case 
PETCOLOR_BLUESetEntityRenderColor(pet[client], 00255255);
        case 
PETCOLOR_PINKSetEntityRenderColor(pet[client], 255128128255);
        case 
PETCOLOR_ORANGESetEntityRenderColor(pet[client], 2551280255);
        case 
PETCOLOR_CYANSetEntityRenderColor(pet[client], 128255255255);
        case 
PETCOLOR_LIMESetEntityRenderColor(pet[client], 1282550255);
        case 
PETCOLOR_BLACKSetEntityRenderColor(pet[client], 000255);
        case 
PETCOLOR_TEAM:
        {
            if(
GetClientTeam(client) == 2SetEntityRenderColor(pet[client], 25500255);
            else    
SetEntityRenderColor(pet[client], 00255255);
        }
        case 
PETCOLOR_LTEAM:
        {
            if(
GetClientTeam(client) == 2SetEntityRenderColor(pet[client], 255128128255);
            else    
SetEntityRenderColor(pet[client], 128128255255);
        }
        case 
PETCOLOR_DTEAM:
        {
            if(
GetClientTeam(client) == 2SetEntityRenderColor(pet[client], 12800255);
            else    
SetEntityRenderColor(pet[client], 00128255);
        }
        case 
PETCOLOR_MAGICSetEntityRenderColor(pet[client], GetRandomInt(02) * 127 1GetRandomInt(02) * 127 1GetRandomInt(02) * 127 1255);
    }
    
    if(
petHappiness[client] >= 16)
    {
        
SetPetParticle(client"superrare_beams1_newstyle");
        
PrintToChat(client"%s%s\x01: Hi, %N!"NPCCOLORpetName[client], client);
    }
    else if(
petHappiness[client] >= 8)
    {
        
PrintToChat(client"%s%s\x01: Hi, %N."NPCCOLORpetName[client], client);
    }
    else if(
petHappiness[client] >=4)
    {
        
SetPetParticle(client"superrare_flies");
        
PrintToChat(client"%s%s\x01: Hey %N, I'm kind of hungry..."NPCCOLORpetName[client], client);
    }
    else if(
petHappiness[client] >= 1)
    {
        
SetPetParticle(client"superrare_stormcloud");
        
PrintToChat(client"%s%s\x01: Food..."NPCCOLORpetName[client]);
    }
    else if(
petHappiness[client] == 0)
    {
        
KillPet(client);
        
PrintToChat(client"%s%s\x01 needs food to live"NPCCOLORpetName[client]);
    }
    
    if(
soundTimer[client] != INVALID_HANDLE)
    {
        
KillTimer(soundTimer[client]);
        
soundTimer[client] = INVALID_HANDLE;
    }
    
    
soundTimer[client] = CreateTimer(10.0Timer_GenericSoundclient);
    
SDKHook(clientSDKHook_PreThinkPetThink);
}

public 
PetThink(client)
{
    if(!
IsValidEntity(pet[client]))
    {
        
SDKUnhook(clientSDKHook_PreThinkPetThink);
        return;
    }
    if(
TF2_IsPlayerInCondition(clientTFCond_Cloaked) || TF2_IsPlayerInCondition(clientTFCond_Disguised))
        return;
    
    
// Get locations, angles, distances
    
decl Float:pos[3], Float:ang[3], Float:clientPos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    
GetEntPropVector(pet[client], Prop_Data"m_angRotation"ang);
    
GetClientAbsOrigin(clientclientPos);

    new 
Float:dist GetVectorDistance(clientPospos);
    new 
Float:distX clientPos[0] - pos[0];
    new 
Float:distY clientPos[1] - pos[1];
    new 
Float:speed = (dist 64.0) / 54;
    
Math_Clamp(speed, -4.04.0);
    if(
FloatAbs(speed) < 0.3)
        
speed *= 0.1;
    
    
// Teleport to owner if too far
    
if(dist 1024.0)
    {
        
decl Float:posTmp[3];
        
GetClientAbsOrigin(clientposTmp);
        
OffsetLocation(posTmp);
        
TeleportEntity(pet[client], posTmpNULL_VECTORNULL_VECTOR);
        
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    }
    
    
// Set new location data    
    
if(pos[0] < clientPos[0])    pos[0] += speed;
    if(
pos[0] > clientPos[0])    pos[0] -= speed;
    if(
pos[1] < clientPos[1])    pos[1] += speed;
    if(
pos[1] > clientPos[1])    pos[1] -= speed;
    
    
// Height
    
switch(petInfo[petType[client]][iHeight])
    {
        case 
HEIGHT_GROUNDpos[2] = clientPos[2];
        case 
HEIGHT_HOVERpos[2] = clientPos[2] + 32.0;
        case 
HEIGHT_FLYpos[2] = clientPos[2] + 96.0;
    }
    
    
// Pet states
    
if(!(GetEntityFlags(client) & FL_ONGROUND))
        
SetPetState(clientSTATE_JUMPING);
    else if(
FloatAbs(speed) > 0.2)
        
SetPetState(clientSTATE_WALKING);
    else
        
SetPetState(clientSTATE_IDLE);
    
    
// Look at owner
    
ang[1] = (ArcTangent2(distYdistX) * 180) / 3.14;
    
    
// Finalize new location
    /*if(TR_GetPointContents(pos) == 1)
        return;*/
    
    
TeleportEntity(pet[client], posangNULL_VECTOR);
    
    if(
petParticle[client] != 0)
    {
        
pos[2] += 4.0;
        
TeleportEntity(petParticle[client], posangNULL_VECTOR);
    }
}

public 
Action:Timer_GenericSound(Handle:timerany:client)
{
    if(
pet[client] == || !IsValidEntity(pet[client]))
        
KillTimer(timer);
    
    
decl Float:pos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pospet[client], __0.5petInfo[petType[client]][iPitch]);
    
    
soundTimer[client] = CreateTimer(GetRandomFloat(20.060.0), Timer_GenericSoundclient);
}

SetPetState(clientstatus)
{
    
decl Float:pos[3];
    
GetEntPropVector(pet[client], Prop_Data"m_vecOrigin"pos);
    if(
petState[client] == status) return;
    switch(
status)
    {
        case 
STATE_IDLESetPetAnim(clientpetInfo[petType[client]][iAnimIdle]);
        case 
STATE_WALKINGSetPetAnim(clientpetInfo[petType[client]][iAnimWalk]);
        case 
STATE_JUMPING:
        {
            
SetPetAnim(clientpetInfo[petType[client]][iAnimJump]);
            
EmitAmbientSound(petInfo[petType[client]][iSoundJump], pospet[client], __0.13petInfo[petType[client]][iPitch]);
        }
    }
    
petState[client] = status;
}

SetPetParticle(clientString:particle[])
{
    if(
petParticle[client] == 0)
        
petParticle[client] = CreateLoopingParticle(pet[client], particle);
}

OffsetLocation(Float:pos[3])
{
    
pos[0] += GetRandomFloat(-128.0128.0);
    
pos[1] += GetRandomFloat(-128.0128.0);
}

KillPet(client)
{
    if(
pet[client] == 0)
        return;
    
    
/*decl Float:pos[3];
    Entity_GetAbsOrigin(pet[client], pos);*/
    
    
SDKUnhook(clientSDKHook_PreThinkPetThink);
    
AcceptEntityInput(pet[client], "Kill");
    
//CreateParticle("ExplosionCore_MidAir", pos);
    
pet[client] = 0;
    
    if(
petParticle[client] != 0)
    {
        
AcceptEntityInput(petParticle[client], "Kill");
        
petParticle[client] = 0;
    }

I cannot seem to spot the issue in the source code. Any help would be greatly appreciated.
Koolman is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 03-03-2014 , 14:37   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #2

-nevermind-
__________________
...

Last edited by Oshizu; 03-03-2014 at 14:38.
Oshizu is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-03-2014 , 14:57   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #3

It looks like it's saying perParticle[client] isn't set to an entity (or rather the value it's storing isn't a valid entity index). However, since the code to CreateLoopingParticle isn't in this code, I couldn't say exactly what it is.

What you could do is change it to this:

PHP Code:
if(petParticle[client] != && IsValidEntity(petParticle[client])) 
Granted, you'll probably want to set perParticle[client] to 0 even if IsValidEntity returns false...
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-03-2014 at 15:01.
Powerlord is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 03-03-2014 , 14:59   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #4

Please show us the lines instead of giving us a bunch of code and let us count them.
Eitherway, my guess is that the pet is already gone/dead, so either hook OnEntityDestroyed and/or OnMapEnd to clean up and/or store the entrefs instead of the entity indices (they are like the userIDs for entities).
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Koolman
Junior Member
Join Date: Mar 2014
Location: United Kingdom
Old 03-03-2014 , 15:15   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #5

The line of code producing the error is
PHP Code:
AcceptEntityInput(pet[client], "Kill"); 
Koolman is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 03-03-2014 , 15:22   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #6

Entity index stored in pet[client] is invalid or it points to one which doesn't seems to use CBaseEntity as base
__________________
...
Oshizu is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 03-03-2014 , 15:53   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #7

Duh!
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Koolman
Junior Member
Join Date: Mar 2014
Location: United Kingdom
Old 03-04-2014 , 14:08   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #8

Worked out the problem.
PHP Code:
Searching for entities with class/target name containing substring'prop_physics_override'
   'prop_physics_override' 
'' (entindex 1094
The entity index is 1094. However, when you die, the entity index is always one higher. However, the plugin still refers to the entity index as the original index.
PHP Code:
L 03/04/2014 18:57:01: [SMNative "AcceptEntityInput" reportedEntity 1095 (1095is not a CBaseEntity
L 03
/04/2014 18:57:01: [SMDisplaying call stack trace for plugin "DFSPets3.smx":
L 03/04/2014 18:57:01: [SM]   [0]  Line 388src\dfs\STOREHOUSE\STAGE3\DFSPets3.sp::KillPet()
L 03/04/2014 18:57:01: [SM]   [1]  Line 151src\dfs\STOREHOUSE\STAGE3\DFSPets3.sp::Event_Spawn() 
How does one prevent this from happening?
Koolman is offline
VoiDeD
AlliedModders Donor
Join Date: Mar 2009
Location: Illinois, USA
Old 03-04-2014 , 14:53   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #9

The proper solution is to instead store ent references, rather than an entity index.

You should always be using references when you're storing entities that will be referenced at a later time (next frame, in N frames, in N seconds, etc), as it's possible for the entity being stored at your index to be deleted and potentially replaced with an entirely different entity, which is likely what's happening in your case.
__________________
VoiDeD is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 03-05-2014 , 03:04   Re: [TF2] Entity is not a CBaseEntity
Reply With Quote #10

Hey that's what I said!
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Reply



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 02:34.


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