AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting light entities in a map (https://forums.alliedmods.net/showthread.php?t=214246)

MousePad 04-24-2013 17:01

Getting light entities in a map
 
I'm trying to find all the light entities in the map. I decompiled the maps I tested and I can see int the entity report of Hammer that they have several light entities with the classname "light". This is how I'm trying to detect light entities:
PHP Code:

new g_max_clients global_get(glb_maxClients)
new 
entitiesnum global_get(glb_maxEntities)
new 
classname[33]

for(new 
g_max_clients 1entitiesnum i++)
{
    if (!
pev_valid(i))
    {
    }
    else
    {
        
pev(ipev_classnameclassname32)
        
log_amx("Entity %d: %s"iclassname)
    }


However I can't see any entities with the classname "light". I also tried several entity related plugins here none of them could find the light entities. Is it possible that you can only detect lights which have actual switches in the map for them? If so, is there any other way I can detect the ones that don't? Any comment would be appreciated.

hornet 04-24-2013 19:41

Re: Getting light entities in a map
 
Light entities are destroyed right after they are spawned if they do not have a valid targetname.

MousePad 04-24-2013 19:48

Re: Getting light entities in a map
 
Wow thanks a lot for clarifying that! Is there any way I can alter those entities and set a target name before they spawn?

hornet 04-24-2013 22:13

Re: Getting light entities in a map
 
This should solve your problem:
Code:
#include <amxmodx> #include <fakemeta> #include <engine> public plugin_precache() {     register_forward( FM_Spawn, "Forward_Spawn" );         set_task( 1.0, "FindLights" ); } public Forward_Spawn( iEnt ) {       static szName[ 32 ];         pev( iEnt, pev_targetname, szName, charsmax( szName ) );         if( !strlen( szName ) )         DispatchKeyValue( iEnt, "targetname", "some_targetname" ); } public FindLights() {     new iEnt = -1, szClass[ 32 ], szName[ 32 ];         while( ( iEnt = engfunc( EngFunc_FindEntityByString, iEnt, "classname", "light" ) ) )     {         pev( iEnt, pev_classname, szClass, charsmax( szClass ) );         pev( iEnt, pev_targetname, szName, charsmax( szName ) );                 server_print( "Entity: %i : %s : %s", iEnt, szClass, szName );     } }

MousePad 04-24-2013 23:53

Re: Getting light entities in a map
 
Thank you so much! The reason I wanted to keep them was to set flickering lights to normal. The map that I'm testing has lights set their appearance to "Flicker B", which corresponds to value 6 for m_iStyle

http://wiki.amxmodx.org/CLight_%28CS%29

From that link I actually verified that I can read that style using get_pdata_int(iEnt, 33) and I do read 6 for the ones that flicker. In your spawn hook function I added a set_pdata_int line and when I do that I do read 0 for the m_iStyle value; however the lights still flicker.

PHP Code:

public Forward_SpawniEnt )
{
        static 
szName32 ];
        
peviEntpev_targetnameszNamecharsmaxszName ) );
        if( !
strlenszName ) )
        {
                
set_pdata_int(iEnt330)
                
DispatchKeyValueiEnt"targetname""some_targetname" );
        }


Is DispatchKeyValue the only way to modify an entity before spawn? As far as I researched, the DispatchKeyValue function only accepts strings for key-value pairs. And unfortunately I couldn't find a pev_* variable for m_iStyle. Any ideas?
Thanks a lot again!

hornet 04-24-2013 23:57

Re: Getting light entities in a map
 
You could try just "style" as the key name.

MousePad 04-25-2013 00:08

Re: Getting light entities in a map
 
Wow thanks, never thought of it :shock:

I tried:
DispatchKeyValue( iEnt, "style", "0")
DispatchKeyValue( iEnt, "style", 0)

In both cases m_iStyle did actually change to 0. But the lights still flicker. I also tried:
DispatchKeyValue( iEnt, "pattern", "m")

No luck :(

ConnorMcLeod 04-25-2013 00:55

Re: Getting light entities in a map
 
Try to create all stuff in plugin_precache, it sometimes help.

Also, sources may help you
Code:

//
// Cache user-entity-field values until spawn is called.
//
void CLight :: KeyValue( KeyValueData* pkvd)
{
        if (FStrEq(pkvd->szKeyName, "style"))
        {
                m_iStyle = atoi(pkvd->szValue);
                pkvd->fHandled = TRUE;
        }
        else if (FStrEq(pkvd->szKeyName, "pitch"))
        {
                pev->angles.x = atof(pkvd->szValue);
                pkvd->fHandled = TRUE;
        }
        else if (FStrEq(pkvd->szKeyName, "pattern"))
        {
                m_iszPattern = ALLOC_STRING( pkvd->szValue );
                pkvd->fHandled = TRUE;
        }
        else
        {
                CPointEntity::KeyValue( pkvd );
        }
}

/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) LIGHT_START_OFF
Non-displayed light.
Default light value is 300
Default style is 0
If targeted, it will toggle between on or off.
*/

void CLight :: Spawn( void )
{
        if (FStringNull(pev->targetname))
        {      // inert light
                REMOVE_ENTITY(ENT(pev));
                return;
        }
       
        if (m_iStyle >= 32)
        {
//                CHANGE_METHOD(ENT(pev), em_use, light_use);
                if (FBitSet(pev->spawnflags, SF_LIGHT_START_OFF))
                        LIGHT_STYLE(m_iStyle, "a");
                else if (m_iszPattern)
                        LIGHT_STYLE(m_iStyle, (char *)STRING( m_iszPattern ));
                else
                        LIGHT_STYLE(m_iStyle, "m");
        }
}


void CLight :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
        if (m_iStyle >= 32)
        {
                if ( !ShouldToggle( useType, !FBitSet(pev->spawnflags, SF_LIGHT_START_OFF) ) )
                        return;

                if (FBitSet(pev->spawnflags, SF_LIGHT_START_OFF))
                {
                        if (m_iszPattern)
                                LIGHT_STYLE(m_iStyle, (char *)STRING( m_iszPattern ));
                        else
                                LIGHT_STYLE(m_iStyle, "m");
                        ClearBits(pev->spawnflags, SF_LIGHT_START_OFF);
                }
                else
                {
                        LIGHT_STYLE(m_iStyle, "a");
                        SetBits(pev->spawnflags, SF_LIGHT_START_OFF);
                }
        }
}


MousePad 04-25-2013 02:03

Re: Getting light entities in a map
 
Connor I had already looked at that source but never paid attention to the >=32 check. That gave me new hopes but things still fail even when I set m_iStyle to 32 and try with and without dispatching a pattern value. The Dispatch functions are working and I can successfully set these values before entity spawn. Nonetheless, the lights still flicker.
Also I really don't understand what you mean when you say create everything in plugin_precache.

MousePad 04-25-2013 22:14

Re: Getting light entities in a map
 
Maybe this can make things simpler. Is there any way I can remove a light entity as if it never existed in the map? Seems like when you remove light entities their lighting still remains. Just like when they don't have a targetname they get removed in the engine anyway.


All times are GMT -4. The time now is 10:48.

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