Raised This Month: $32 Target: $400
 8% 

cs_find_ent_by_class issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Netsys
Senior Member
Join Date: Feb 2010
Old 11-11-2015 , 10:06   cs_find_ent_by_class issue
Reply With Quote #1

Linux
Build 6153
Metamod v1.21p37
AMX Mod X 1.8.3-dev+4936

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <engine>

public plugin_init()
{
    
register_concmd("test1""commandTest1");
    
register_concmd("test2""commandTest2");
}

public 
commandTest1iPlayerID )
{
    
/* Create the entity */
    
new iEntityID cs_create_entity("info_target");

    if (!
is_valid_ent(iEntityID))
    {
        
console_print(iPlayerID"[Test1] invalid entity");
        return;
    }

    
entity_set_string(iEntityIDEV_SZ_classname"testEntity1");

    
/* Try to find the entity */
    
console_print(iPlayerID"[Test1] cs_find_ent_by_class: %d"cs_find_ent_by_class(-1"testEntity1"));
    
console_print(iPlayerID"[Test1] find_ent_by_class: %d"find_ent_by_class(-1"testEntity1"));
}


public 
commandTest2iPlayerID )
{
    
/* Create the entity */
    
new iEntityID create_entity("info_target");

    if (!
is_valid_ent(iEntityID))
    {
        
console_print(iPlayerID"[Test2] invalid entity");
        return;
    }

    
entity_set_string(iEntityIDEV_SZ_classname"testEntity2");

    
/* Try to find the entity */
    
console_print(iPlayerID"[Test2] cs_find_ent_by_class: %d"cs_find_ent_by_class(-1"testEntity2"));
    
console_print(iPlayerID"[Test2] find_ent_by_class: %d"find_ent_by_class(-1"testEntity2"));

Output:
PHP Code:
test1
[Test1cs_find_ent_by_class0
[Test1find_ent_by_class37
test2
[Test2cs_find_ent_by_class0
[Test2find_ent_by_class38 
cs_find_ent_by_class should return the entity index on test1

Last edited by Netsys; 11-13-2015 at 22:32.
Netsys is offline
Netsys
Senior Member
Join Date: Feb 2010
Old 11-15-2015 , 21:27   Re: cs_find_ent_by_class issue
Reply With Quote #2

I did something wrong or this is a bug?
Netsys is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-16-2015 , 04:15   Re: cs_find_ent_by_class issue
Reply With Quote #3

I was going to answer soon.

Your issue is that it's the expected behavior from game. The hashtable code in game is working based on engine classname.

When you create an entity with cs_create_entity, a new hash is added in the table based on the classname you passed, here info_target.
Once you modify the classname, and you're using cs_find_ent_by_class, CS tries first to compute hash from given classname to see if it exists in table, and that's why it fails because hash was not saved from testEntity1.

Well, after discussing this with Nextra, considering it's useful and for consistency, it would be okay to add a new native to set a classname and updating hash. CS doesn't offer a way to update directly a hash so this will do: removing hash -> updating classname -> add new hash.

Right now, we are stucked to find proper native name \o/.
__________________
Arkshine is offline
Netsys
Senior Member
Join Date: Feb 2010
Old 11-16-2015 , 05:19   Re: cs_find_ent_by_class issue
Reply With Quote #4

Maybe with
PHP Code:
cs_create_entity(szClass[], szClassName[] = ""
or
PHP Code:
cs_set_entity_classname(iEntityIDszClassName[]) 

Last edited by Netsys; 11-16-2015 at 10:45.
Netsys 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 06:30.


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