AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Coding MM:S Plugins & SM Extensions (https://forums.alliedmods.net/forumdisplay.php?f=75)
-   -   SourceMod FindEntityByClassname / SetEntProp extension equivalents? (https://forums.alliedmods.net/showthread.php?t=188061)

Powerlord 06-21-2012 17:23

SourceMod FindEntityByClassname / SetEntProp extension equivalents?
 
Hi guys,

I was wondering if there was an easy way in a SourceMod extension to find an entity by its classname and adjust its properties. This would be quite easy to do in a plugin, but unfortunately, the rest of my logic is already in an extension.

Incidentally, the entity class is vote_controller, and the properties I want to adjust are:
Code:

-Member: m_iActiveIssueIndex (offset 796) (type integer) (bits 32)
 -Member: m_iOnlyTeamToVote (offset 800) (type integer) (bits 32)
  Sub-Class Table (2 Deep): m_nVoteOptionCount
  -Member: 000 (offset 0) (type integer) (bits 8)
  -Member: 001 (offset 4) (type integer) (bits 8)
  -Member: 002 (offset 8) (type integer) (bits 8)
  -Member: 003 (offset 12) (type integer) (bits 8)
  -Member: 004 (offset 16) (type integer) (bits 8)
 -Member: m_nPotentialVotes (offset 824) (type integer) (bits 32)
 -Member: m_bIsYesNoVote (offset 828) (type integer) (bits 1)

(yes, all of them)

psychonic 06-21-2012 20:11

Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
 
Quote:

Originally Posted by Powerlord (Post 1733460)
Hi guys,

I was wondering if there was an easy way in a SourceMod extension to find an entity by its classname and adjust its properties. This would be quite easy to do in a plugin, but unfortunately, the rest of my logic is already in an extension.

Incidentally, the entity class is vote_controller, and the properties I want to adjust are:
Code:

-Member: m_iActiveIssueIndex (offset 796) (type integer) (bits 32)
 -Member: m_iOnlyTeamToVote (offset 800) (type integer) (bits 32)
  Sub-Class Table (2 Deep): m_nVoteOptionCount
  -Member: 000 (offset 0) (type integer) (bits 8)
  -Member: 001 (offset 4) (type integer) (bits 8)
  -Member: 002 (offset 8) (type integer) (bits 8)
  -Member: 003 (offset 12) (type integer) (bits 8)
  -Member: 004 (offset 16) (type integer) (bits 8)
 -Member: m_nPotentialVotes (offset 824) (type integer) (bits 32)
 -Member: m_bIsYesNoVote (offset 828) (type integer) (bits 1)

(yes, all of them)

For FEBC, you can copy the native implementation using IServerTools right out of SDK Tools.
http://hg.alliedmods.net/sourcemod-c...tives.cpp#l638

For finding datadesc property offsets and values, use GetDataMap and FindInDataMap on IGameHelpers.
PHP Code:

datamap_t *pMap gamehelpers->GetDataMap(pEntity);
typedescription_t *td gamehelpers->FindInDataMap(pMap"m_nVoteOptionCount");
uint32 nVoteOptionCount = *(uint32 *)((intptr_t)pEntity GetTypeDescOffs(td)); 


Powerlord 06-21-2012 20:12

Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
 
Quote:

Originally Posted by psychonic (Post 1733539)
For FEBC, you can copy the native implementation using IServerTools right out of SDK Tools.
http://hg.alliedmods.net/sourcemod-c...tives.cpp#l638

For finding datadesc property offsets and values, use GetDataMap and FindInDataMap on IGameHelpers.
PHP Code:

datamap_t *pMap gamehelpers->GetDataMap(pEntity);
typedescription_t *td gamehelpers->FindInDataMap(pMap"m_nVoteOptionCount");
uint32 nVoteOptionCount = *(uint32 *)((intptr_t)pEntity GetTypeDescOffs(td)); 


These are Netprops by the way, would this still be the correct way to access them?

psychonic 06-21-2012 20:22

Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
 
Quote:

Originally Posted by Powerlord (Post 1733540)
These are Netprops by the way, would this still be the correct way to access them?

Actually, they exist as both. I sillily search for vote_controller instead of CVoteController in the netprop dump, ofc didn't find it, and then looked in the datamap dump.

Netprops, specifically for integers are a little trickier due to the varying bit counts.

Look at SM's core/smn_entities.cpp and GetEntProp for an example.

TheDS1337 01-29-2016 15:52

Re: SourceMod FindEntityByClassname / SetEntProp extension equivalents?
 
Hey, sorry to bump this since I'm trying to do the same thing

can you tell me why this doesnt work ?
PHP Code:

CBaseEntity *UTIL_FindEntityByClassname(int start, const char *pEntityClassname)
{
    
CBaseEntity *pEntity;

    if (
start == -1)
    {
        
pEntity = (CBaseEntity *)g_pServerTools->FirstEntity();
    }
    else
    {
        
pEntity gamehelpers->ReferenceToEntity(start);

        if (
pEntity)
        {
            
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
        }
    }

    if (
pEntity)
    {
        static 
int offset = -1;

        if (
offset == -1)
        {
            
sm_datatable_info_t info;

            if (
gamehelpers->FindDataMapInfo(gamehelpers->GetDataMap(pEntity), "m_iClassname", &info))
            {
                
offset info.actual_offset;
            }
        }

        const 
char *pClassname;
        
string_t str;

        
int lastLetter;

        while (
pEntity)
        {
            
str = *(string_t *)((uint8_t *)pEntity offset);

            if (
str == NULL_STRING)
            {
                
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
                continue;
            }

            
pClassname STRING(str);

            
lastLetter strlen(pEntityClassname) - 1;

            if (
pEntityClassname[lastLetter] == '*' && !strncasecmp(pEntityClassnamepClassnamelastLetter))
            {
                return 
pEntity;
            }
            else if (!
strcasecmp(pEntityClassnamepClassname))
            {
                return 
pEntity;
            }

            
pEntity = (CBaseEntity *)g_pServerTools->NextEntity(pEntity);
        }
    }

    return 
pEntity;
}; 

Basically I'm trying to find the fov ("ent_fov_controller") and edit it also is there any equivalent to SetVariant* and AcceptEntityInput

PHP Code:

void OnServer_Activate(edict_t *pEdictint edictCountint clientMax)
{
    
engine->LightStyle(0MAP_LIGHT);

/*
    CBaseEntity *pFogEntity = UTIL_FindEntityByClassname(-1, "env_fog_controller");

    if (!pFogEntity)
    {
        g_pServerTools->DispatchSpawn(pFogEntity);
    }

    g_pServerTools->SetKeyValue(pFogEntity, "fogmaxdensity", 0.6);
    
    SetVariantInt(FogStartDist);
    AcceptEntityInput(FogControllerIndex, "SetStartDist");
        
    SetVariantInt(FogEndDist);
    AcceptEntityInput(FogControllerIndex, "SetEndDist");
    
    SetVariantInt(FogZPlane);
    AcceptEntityInput(FogControllerIndex, "SetFarZ");

    SetVariantString(FogColor);
    AcceptEntityInput(FogControllerIndex, "SetColor");

    SetVariantString(FogColor);
    AcceptEntityInput(FogControllerIndex, "SetColorSecondary");
    
    SET START DIST, END DIST, FARZ
*/


The lightning works fine, but others doesnt


All times are GMT -4. The time now is 05:55.

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