If you don't know the classname, you could use "HasEntProp" under the OnEntityCreated forward, to figure which entity is an item. But that's less than ideal.
However, since DHooks is part of Sourcemod, you could simply do exactly what tf2items does in your plugin.
PHP Code:
static DynamicHook g_dhookCTFPlayer_GiveNamedItem;
static void GameData_Init()
{
GameData data = new GameData("yourgamedata");
if (data == null)
{
SetFailState("Missing gamedata");
}
int offset = data.GetOffset("CTFPlayer::GiveNamedItem");
g_dhookCTFPlayer_GiveNamedItem = new DynamicHook(offset, HookType_Entity, ReturnType_CBaseEntity, ThisPointer_CBaseEntity);
g_dhookCTFPlayer_GiveNamedItem.AddParam(HookParamType_CharPtr);
g_dhookCTFPlayer_GiveNamedItem.AddParam(HookParamType_Int);
g_dhookCTFPlayer_GiveNamedItem.AddParam(HookParamType_ObjectPtr);
g_dhookCTFPlayer_GiveNamedItem.AddParam(HookParamType_Bool);
}
public void OnClientPutInServer(int client)
{
g_dhookCTFPlayer_GiveNamedItem.HookEntity(Hook_Post, client, CTFPlayer_GiveNamedItem_Post);
}
static MRESReturn CTFPlayer_GiveNamedItem_Post(int player /* The item's owner */, DHookReturn hReturn, DHookParam hParams)
{
int item = hReturn.Value; /* The item entity index */
char classname[32];
GetEntityClassname(item, classname, sizeof(classname)); /* The item's classname */
int itemDefIndex = GetEntProp(item, Prop_Send, "m_iItemDefinitionIndex"); /* The item's def index */
int level = GetEntProp(item, Prop_Send, "m_iEntityLevel"); /* The item's level */
int quality = GetEntProp(item, Prop_Send, "m_iEntityQuality"); /* The item's quality */
return MRES_Ignored;
}
The gamedata can be tf2item's or yours, doesn't matter. Just make sure to change the key
CTFPlayer::GiveNamedItem accordingly.
Edit :
If you're still going for a no gamedata approach. Then consider HasEntProp
PHP Code:
public void OnEntityCreated(int entity, const char[] classname)
{
if (HasEntProp(entity, Prop_Send, "m_Item"))
{
SDKHook(entity, SDKHook_TouchPost, Item_TouchPost);
}
}
static void Item_TouchPost(int item /* The item entity index */, int player /* The item's owner */)
{
char classname[32];
GetEntityClassname(item, classname, sizeof(classname)); /* The item's classname */
int itemDefIndex = GetEntProp(item, Prop_Send, "m_iItemDefinitionIndex"); /* The item's def index */
int level = GetEntProp(item, Prop_Send, "m_iEntityLevel"); /* The item's level */
int quality = GetEntProp(item, Prop_Send, "m_iEntityQuality"); /* The item's quality */
SDKUnhook(item, SDKHook_TouchPost, Item_TouchPost);
}
__________________