AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   Interrogate map entities (https://forums.alliedmods.net/showthread.php?t=117451)

Bilge 02-01-2010 08:49

Interrogate map entities
 
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);



Frus 02-01-2010 11:06

Re: Interrogate map entities
 
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

Bilge 02-01-2010 13:06

Re: Interrogate map entities
 
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.

pheadxdll 02-01-2010 15:56

Re: Interrogate map entities
 
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. :o

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. :wink: Their should be some code out there from other people's work.


All times are GMT -4. The time now is 17:23.

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