Raised This Month: $ Target: $400
 0% 

Interrogate map entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bilge
Junior Member
Join Date: Dec 2009
Old 02-01-2010 , 08:49   Interrogate map entities
Reply With Quote #1

How can I interrogate map entities, such as control points and their properties for a Team Fortress server?

I spent a long time investigating SourceMod because I discovered it had a function called FindEntityByClassname, which sounded ideal, but I can't make head or tail of its cryptic code.

PHP Code:
static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *params)
{
    static 
ValveCall *pCall NULL;
    if (!
pCall)
    {
        
ValvePassInfo pass[3];
        
InitPass(pass[0], Valve_CBaseEntityPassType_BasicPASSFLAG_BYVALVDECODE_FLAG_ALLOWNULL|VDECODE_FLAG_ALLOWWORLD);
        
InitPass(pass[1], Valve_StringPassType_BasicPASSFLAG_BYVAL);
        
InitPass(pass[2], Valve_CBaseEntityPassType_BasicPASSFLAG_BYVAL);
        if (!
CreateBaseCall("FindEntityByClassname"ValveCall_EntityList, &pass[2], pass2, &pCall))
        {
            return 
pContext->ThrowNativeError("\"FindEntityByClassname\" not supported by this mod");
        } else if (!
pCall) {
            return 
pContext->ThrowNativeError("\"FindEntityByClassname\" wrapper failed to initialize");
        }
    }

    
CBaseEntity *pEntity;
    
START_CALL();
    *(
void **)vptr g_EntList
    
DECODE_VALVE_PARAM(1vparams0);
    
DECODE_VALVE_PARAM(2vparams1);
    
FINISH_CALL_SIMPLE(&pEntity);

    return 
gamehelpers->EntityToBCompatRef(pEntity);

Bilge is offline
Frus
Senior Member
Join Date: Aug 2009
Old 02-01-2010 , 11:06   Re: Interrogate map entities
Reply With Quote #2

FindEntityByClassname only gives you the entity index, and it is best suited to be iterated through.

Main link: http://docs.sourcemod.net/api/index....ad=show&id=43&

as an example slightly modified from that page:

Code:
new index = -1;
while ((index = FindEntityByClassname(index, "weapon_m4a1")) != -1)
{
    PrintToChat("Found entity: %d", index);
}
To find information about an entity once you have the index you need to deal with netprops and/or datamaps

You should really read through the entire 'entity' section here: http://docs.sourcemod.net/api/index.php
But these are the more interesting functions for what you want.

http://docs.sourcemod.net/api/index....ad=show&id=81& (*EntProp* functions can be used by themselves, and are a separate method than the following functions)

http://docs.sourcemod.net/api/index....ad=show&id=80&
http://docs.sourcemod.net/api/index....ad=show&id=79&
http://docs.sourcemod.net/api/index....ad=show&id=78&
http://docs.sourcemod.net/api/index....ad=show&id=68&

You will also need to find the datamaps/netprops, which you can get yourself with the sm_dump_datamaps and sm_dump_netprops, or you may find one for the game mod you are using at the wiki http://wiki.alliedmods.net/Category:Game_Resources
Frus is offline
Bilge
Junior Member
Join Date: Dec 2009
Old 02-01-2010 , 13:06   Re: Interrogate map entities
Reply With Quote #3

This isn't a question about SourceMod, I was merely searching its source code for some insight into a problem I have coding for MetaMod.

Last edited by Bilge; 02-01-2010 at 13:10.
Bilge is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 02-01-2010 , 15:56   Re: Interrogate map entities
Reply With Quote #4

That portion of code from SourceMod makes use of an interface called BinTools that's provided by SourceMod: public/extensions/IBinTools.h which is probably not accessible through anything but a SourceMod extension. It makes a call to the actual function that valve uses in the game.

If I was making an MM:S plugin, I'd basically loop through all the entity indexes and check out their classname, then go from there. Their should be some code out there from other people's work.
pheadxdll 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 10:39.


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