Raised This Month: $ Target: $400
 0% 

Accessing entity information in MetaMod:Source


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ManuHeel
New Member
Join Date: May 2024
Location: France
Old 05-27-2024 , 17:07   Accessing entity information in MetaMod:Source
Reply With Quote #1

Hi!

MetaMod:Source beginner here, with just a little bit of experience coding in C++ and coding within the Source engine.

I'm currently porting code I made for a Source engine modification, where I was overriding the client.dll and server.dll, to a Metamod:Source plugin as I'd like my addons to be more portable and compatible with different mods overriding these DLLs.

I managed to compile everything from the samples, adapt them into my plugins, code some stuff, link external DLLs and libs, all right, however I'm stuck at interacting with entities (CBaseEntity and such) and edicts (edict_t). I'm used to be in the engine and having access to CBase, CBaseEntity, and most importantly the global gEntList variable which is quite useful, but it seems I cannot do it the same way with a plugin.

I had code like this snippet right there to find NPCs in the map and do something with it (only read data though) :


CBaseEntity *pNPC = nullptr;
while ((pNPC = gEntList.FindEntityByClassname(pNPC, "npc_*")) != nullptr) {
auto *pAI = dynamic_cast<CAI_BaseNPC *>(pNPC);
if (pAI) {
int relationToPlayer = pAI->IRelationType(pPlayer); // I already had a pointer to my player
// something something
}
}

This code is probably written like shit but it worked, I had access to cbase.h so with baseentity.h, so with gEntList and the base classes like CBaseEntity, but now in Metamod I don't.
I tried including the cbase.h header, of course, but I can't find a way to link it, and I'm almost certain that's not the way plugins work, they probably don't know what the hell is happening in the engine and maybe I'm not at all permitted to include cbase.h.
I get this kind of linker error which is expected, even if I link every public/*.lib file in the sdk's source :
error LNK2019: unresolved external symbol "public: class CBaseEntity * __thiscall CGlobalEntityList::FindEntityByClassname(clas s CBaseEntity *,char const *)" (?FindEntityByClassname@CGlobalEntityList@@QA EPAVCBaseEntity@@PAV2@PBD@Z) referenced in function [...]

How can I then find data about what entities are currently in the game? How can I access this data, and use the methods of basic classes like CBaseEntity? Can I even known which entities are in the game with like gEntList?

Navigating through the Source engine's doc, I found info on those edict_t objects, which I found in some plugins' methods' signature (so I guess Metamod deals with them), I can get some info from them (like the player's position with pEdict->GetCollideable()->GetCollisionOrigin()) but I can't get more info from it. The doc says I can do think kind of stuff to get an entity from my edict, but it does not work, and I can't compile with CBaseEntity stuff in any case:
pEdit->GetUnknown()->GetBaseEntity()

ex:

void MyPlugin::Hook_ClientPutInServer(edict_t *pEntity, char const *playername) {
Vector position = pEdict->GetCollideable()->GetCollisionOrigin(); // this works
float health = pEdit->GetUnknown()->GetBaseEntity()->GetHealth(); // this returns me 0.0f in any case, and I can't debug from GetBaseEntity() as I get this result in the immediate window : Function IServerUnknown::GetBaseEntity has no address, possibly due to compiler optimizations.
}

Am I missing something? Is there any explicit doc about how to handle CBaseEntity and/or edicts and their data with Metamod:Source?

Thanks a lot.
Manu.
ManuHeel is offline
 


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 06:31.


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