Junior Member
Join Date: Mar 2014
Location: United Kingdom
|
03-03-2014
, 14:25
[TF2] Entity is not a CBaseEntity
|
#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: [SM] Native "AcceptEntityInput" reported: Entity 1095 (1095) is not a CBaseEntity
L 03/03/2014 - 19:11:23: [SM] Displaying call stack trace for plugin "DFSPets3.smx":
L 03/03/2014 - 19:11:23: [SM] [0] Line 388, src\dfs\STOREHOUSE\STAGE3\DFSPets3.sp::KillPet()
L 03/03/2014 - 19:11:23: [SM] [1] Line 151, src\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=1; i<=GetMaxClients(); i++)
{
if(!IsValidEntity(i)) continue;
if(!IsValidEntity(pet[i])) continue;
KillPet(i);
}
}
public OnMapStart()
{
for(new i=1; i<=GetMaxClients(); i++)
{
if(!IsValidEntity(i)) continue;
if(!IsValidEntity(pet[i])) continue;
KillPet(i);
}
PrecacheSound(SOUND_SPAWN);
for(new i=1; i<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(client, args)
{
if(petType[client] == 0)
{
ReplyToCommand(client, "You don't have a pet!");
return Plugin_Handled;
}
new Handle:panel = CreatePanel();
decl String:line[64];
Format(line, sizeof(line), "%s the %s", petName[client], petInfo[petType[client]][iName]);
SetPanelTitle(panel, line);
if(petHappiness[client] >= 16)
Format(line, sizeof(line), "Happiness: Supreme");
else if(petHappiness[client] >= 8)
Format(line, sizeof(line), "Happiness: Content");
else if(petHappiness[client] >= 4)
Format(line, sizeof(line), "Happiness: Poor");
else
Format(line, sizeof(line), "Happiness: Terrible");
DrawPanelText(panel, line);
DrawPanelText(panel, " ");
if(petEnabled[client])
DrawPanelItem(panel, "Put Away");
else
DrawPanelItem(panel, "Send Out");
DrawPanelItem(panel, "Close");
SendPanelToClient(panel, client, Menu_Pet, 60);
CloseHandle(panel);
return Plugin_Handled;
}
public Menu_Pet(Handle:menu, MenuAction:action, client, option)
{
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(client, petName[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(client, pos);
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], pos, NULL_VECTOR, NULL_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], pos, pet[client]);
EmitAmbientSound(SOUND_SPAWN, pos);
SetEntityRenderMode(pet[client], RENDER_TRANSADD);
switch(User_GetPetColor(client))
{
case PETCOLOR_RED: SetEntityRenderColor(pet[client], 255, 0, 0, 255);
case PETCOLOR_GREEN: SetEntityRenderColor(pet[client], 0, 255, 0, 255);
case PETCOLOR_BLUE: SetEntityRenderColor(pet[client], 0, 0, 255, 255);
case PETCOLOR_PINK: SetEntityRenderColor(pet[client], 255, 128, 128, 255);
case PETCOLOR_ORANGE: SetEntityRenderColor(pet[client], 255, 128, 0, 255);
case PETCOLOR_CYAN: SetEntityRenderColor(pet[client], 128, 255, 255, 255);
case PETCOLOR_LIME: SetEntityRenderColor(pet[client], 128, 255, 0, 255);
case PETCOLOR_BLACK: SetEntityRenderColor(pet[client], 0, 0, 0, 255);
case PETCOLOR_TEAM:
{
if(GetClientTeam(client) == 2) SetEntityRenderColor(pet[client], 255, 0, 0, 255);
else SetEntityRenderColor(pet[client], 0, 0, 255, 255);
}
case PETCOLOR_LTEAM:
{
if(GetClientTeam(client) == 2) SetEntityRenderColor(pet[client], 255, 128, 128, 255);
else SetEntityRenderColor(pet[client], 128, 128, 255, 255);
}
case PETCOLOR_DTEAM:
{
if(GetClientTeam(client) == 2) SetEntityRenderColor(pet[client], 128, 0, 0, 255);
else SetEntityRenderColor(pet[client], 0, 0, 128, 255);
}
case PETCOLOR_MAGIC: SetEntityRenderColor(pet[client], GetRandomInt(0, 2) * 127 + 1, GetRandomInt(0, 2) * 127 + 1, GetRandomInt(0, 2) * 127 + 1, 255);
}
if(petHappiness[client] >= 16)
{
SetPetParticle(client, "superrare_beams1_newstyle");
PrintToChat(client, "%s%s\x01: Hi, %N!", NPCCOLOR, petName[client], client);
}
else if(petHappiness[client] >= 8)
{
PrintToChat(client, "%s%s\x01: Hi, %N.", NPCCOLOR, petName[client], client);
}
else if(petHappiness[client] >=4)
{
SetPetParticle(client, "superrare_flies");
PrintToChat(client, "%s%s\x01: Hey %N, I'm kind of hungry...", NPCCOLOR, petName[client], client);
}
else if(petHappiness[client] >= 1)
{
SetPetParticle(client, "superrare_stormcloud");
PrintToChat(client, "%s%s\x01: Food...", NPCCOLOR, petName[client]);
}
else if(petHappiness[client] == 0)
{
KillPet(client);
PrintToChat(client, "%s%s\x01 needs food to live", NPCCOLOR, petName[client]);
}
if(soundTimer[client] != INVALID_HANDLE)
{
KillTimer(soundTimer[client]);
soundTimer[client] = INVALID_HANDLE;
}
soundTimer[client] = CreateTimer(10.0, Timer_GenericSound, client);
SDKHook(client, SDKHook_PreThink, PetThink);
}
public PetThink(client)
{
if(!IsValidEntity(pet[client]))
{
SDKUnhook(client, SDKHook_PreThink, PetThink);
return;
}
if(TF2_IsPlayerInCondition(client, TFCond_Cloaked) || TF2_IsPlayerInCondition(client, TFCond_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(client, clientPos);
new Float:dist = GetVectorDistance(clientPos, pos);
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.0, 4.0);
if(FloatAbs(speed) < 0.3)
speed *= 0.1;
// Teleport to owner if too far
if(dist > 1024.0)
{
decl Float:posTmp[3];
GetClientAbsOrigin(client, posTmp);
OffsetLocation(posTmp);
TeleportEntity(pet[client], posTmp, NULL_VECTOR, NULL_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_GROUND: pos[2] = clientPos[2];
case HEIGHT_HOVER: pos[2] = clientPos[2] + 32.0;
case HEIGHT_FLY: pos[2] = clientPos[2] + 96.0;
}
// Pet states
if(!(GetEntityFlags(client) & FL_ONGROUND))
SetPetState(client, STATE_JUMPING);
else if(FloatAbs(speed) > 0.2)
SetPetState(client, STATE_WALKING);
else
SetPetState(client, STATE_IDLE);
// Look at owner
ang[1] = (ArcTangent2(distY, distX) * 180) / 3.14;
// Finalize new location
/*if(TR_GetPointContents(pos) == 1)
return;*/
TeleportEntity(pet[client], pos, ang, NULL_VECTOR);
if(petParticle[client] != 0)
{
pos[2] += 4.0;
TeleportEntity(petParticle[client], pos, ang, NULL_VECTOR);
}
}
public Action:Timer_GenericSound(Handle:timer, any:client)
{
if(pet[client] == 0 || !IsValidEntity(pet[client]))
KillTimer(timer);
decl Float:pos[3];
GetEntPropVector(pet[client], Prop_Data, "m_vecOrigin", pos);
EmitAmbientSound(petInfo[petType[client]][iSoundGeneric], pos, pet[client], _, _, 0.5, petInfo[petType[client]][iPitch]);
soundTimer[client] = CreateTimer(GetRandomFloat(20.0, 60.0), Timer_GenericSound, client);
}
SetPetState(client, status)
{
decl Float:pos[3];
GetEntPropVector(pet[client], Prop_Data, "m_vecOrigin", pos);
if(petState[client] == status) return;
switch(status)
{
case STATE_IDLE: SetPetAnim(client, petInfo[petType[client]][iAnimIdle]);
case STATE_WALKING: SetPetAnim(client, petInfo[petType[client]][iAnimWalk]);
case STATE_JUMPING:
{
SetPetAnim(client, petInfo[petType[client]][iAnimJump]);
EmitAmbientSound(petInfo[petType[client]][iSoundJump], pos, pet[client], _, _, 0.13, petInfo[petType[client]][iPitch]);
}
}
petState[client] = status;
}
SetPetParticle(client, String:particle[])
{
if(petParticle[client] == 0)
petParticle[client] = CreateLoopingParticle(pet[client], particle);
}
OffsetLocation(Float:pos[3])
{
pos[0] += GetRandomFloat(-128.0, 128.0);
pos[1] += GetRandomFloat(-128.0, 128.0);
}
KillPet(client)
{
if(pet[client] == 0)
return;
/*decl Float:pos[3];
Entity_GetAbsOrigin(pet[client], pos);*/
SDKUnhook(client, SDKHook_PreThink, PetThink);
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.
|
|