Raised This Month: $51 Target: $400
 12% 

How to loop all entities?


Post New Thread Reply   
 
Thread Tools Display Modes
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 07-19-2011 , 15:49   Re: How to loop all entities?
Reply With Quote #11

It would be helpful to be able to get the highest index though. I wonder about registering FM_Spawn or some fakemeta forward and increasing entities by 1 every call.
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 15:50   Re: How to loop all entities?
Reply With Quote #12

I don't think create_entity() calls FM_Spawn forward.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-19-2011 , 16:03   Re: How to loop all entities?
Reply With Quote #13

dllfunc( Dllfunc_Spawn, ... ) calls FM_Spawn ?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 16:26   Re: How to loop all entities?
Reply With Quote #14

Quote:
Originally Posted by abdul-rehman View Post
dllfunc( Dllfunc_Spawn, ... ) calls FM_Spawn ?
No. It's like not being able to hook messages from message_begin().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 07-19-2011 , 16:29   Re: How to loop all entities?
Reply With Quote #15

Using this test plugin:
Code:
#include <amxmodx> #include <engine> #include <fakemeta> public plugin_init() {     register_plugin( "Spawn Test", "1.0", "Wrecked" )         register_clcmd( "say /make", "CmdMake" )         register_forward( FM_Spawn, "Spawn" ) } public CmdMake( id ) {     new ent = create_entity( "info_target" )         client_print( 0, print_chat, "%d", ent ) } public Spawn( ent ) {     client_print( 0, print_chat, "%d", ent ) }

It seems create_entity() doesn't call FM_Spawn. However, it also shows that entity ids can fluctuate even when created within a short time period.

Ingame Chat (de_aztec):
Code:
58
Wrecked :  /make

59
Wrecked :  /make

252
Wrecked :  /make

256
Wrecked :  /make

257
Wrecked :  /make
The number only printed once, meaning FM_Spawn wasn't called after create_entity.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT

Last edited by wrecked_; 07-19-2011 at 16:32.
wrecked_ is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 16:49   Re: How to loop all entities?
Reply With Quote #16

Quote:
Originally Posted by wrecked_ View Post
However, it also shows that entity ids can fluctuate even when created within a short time period.
Most likely because those entity indexes were being used.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 07-19-2011 , 22:17   Re: How to loop all entities?
Reply With Quote #17

I just toyed around with a bunch of different forwards, and I can't find anything. I could track model change on map entities (like func_wall), but that missed about the first 71 entities. FM_CreateEntity will forward the creation of the worldspawn entity, but that's it. FM_CreateNamedEntity was really weird though. Whenever I would create an entity using fakemeta, it would reforward everything. It also forwarded MANY entities that do not exist in my map. I was thinking it does this to create them in the mod? This was the output... notice how it prints the list twice? The second print is after creating an entity using this code

// edit
I'm now trying to see if I can try and use FM_AllocString. It is giving me all of the entity classnames as they spawn, but I believe it misses the first creation of every entity type because it checks if the entity exists, and I think this is executed before the entity exists.

Code:
dllfunc(DLLFunc_Spawn, engfunc(EngFunc_CreateNamedEntity, "my entity!"));
Quote:
L 07/19/2011 - 19:15:46: Entity Created! 64411348; "item_suit"
L 07/19/2011 - 19:15:46: Entity Created! 64395052; "item_battery"
L 07/19/2011 - 19:15:46: Entity Created! 64411376; "item_antidote"
L 07/19/2011 - 19:15:46: Entity Created! 64411360; "item_security"
L 07/19/2011 - 19:15:46: Entity Created! 64436888; "item_longjump"
L 07/19/2011 - 19:15:46: Entity Created! 64348348; "item_kevlar"
L 07/19/2011 - 19:15:46: Entity Created! 64348316; "item_assaultsuit"
L 07/19/2011 - 19:15:46: Entity Created! 64413756; "item_thighpack"
L 07/19/2011 - 19:15:46: Entity Created! 64348664; "weapon_awp"
L 07/19/2011 - 19:15:46: Entity Created! 64386136; "ammo_338magnum"
L 07/19/2011 - 19:15:46: Entity Created! 64348648; "weapon_g3sg1"
L 07/19/2011 - 19:15:46: Entity Created! 64348708; "weapon_ak47"
L 07/19/2011 - 19:15:46: Entity Created! 64348692; "weapon_scout"
L 07/19/2011 - 19:15:46: Entity Created! 64386120; "ammo_762nato"
L 07/19/2011 - 19:15:46: Entity Created! 64348388; "weapon_m249"
L 07/19/2011 - 19:15:46: Entity Created! 64386076; "ammo_556natobox"
L 07/19/2011 - 19:15:46: Entity Created! 64348620; "weapon_m4a1"
L 07/19/2011 - 19:15:46: Entity Created! 64348676; "weapon_sg552"
L 07/19/2011 - 19:15:46: Entity Created! 64348608; "weapon_aug"
L 07/19/2011 - 19:15:46: Entity Created! 64348592; "weapon_sg550"
L 07/19/2011 - 19:15:46: Entity Created! 64386012; "ammo_556nato"
L 07/19/2011 - 19:15:46: Entity Created! 64348488; "weapon_m3"
L 07/19/2011 - 19:15:46: Entity Created! 64348472; "weapon_xm1014"
L 07/19/2011 - 19:15:46: Entity Created! 64386104; "ammo_buckshot"
L 07/19/2011 - 19:15:46: Entity Created! 64348564; "weapon_usp"
L 07/19/2011 - 19:15:46: Entity Created! 64348456; "weapon_mac10"
L 07/19/2011 - 19:15:46: Entity Created! 64348412; "weapon_ump45"
L 07/19/2011 - 19:15:46: Entity Created! 64386092; "ammo_45acp"
L 07/19/2011 - 19:15:46: Entity Created! 64348500; "weapon_fiveseven"
L 07/19/2011 - 19:15:46: Entity Created! 64348400; "weapon_p90"
L 07/19/2011 - 19:15:46: Entity Created! 64386064; "ammo_57mm"
L 07/19/2011 - 19:15:46: Entity Created! 64348536; "weapon_deagle"
L 07/19/2011 - 19:15:46: Entity Created! 64386040; "ammo_50ae"
L 07/19/2011 - 19:15:46: Entity Created! 64348552; "weapon_p228"
L 07/19/2011 - 19:15:46: Entity Created! 64386028; "ammo_357sig"
L 07/19/2011 - 19:15:46: Entity Created! 64422004; "weapon_knife"
L 07/19/2011 - 19:15:46: Entity Created! 64348576; "weapon_glock18"
L 07/19/2011 - 19:15:46: Entity Created! 64348428; "weapon_mp5navy"
L 07/19/2011 - 19:15:46: Entity Created! 64348444; "weapon_tmp"
L 07/19/2011 - 19:15:46: Entity Created! 64348520; "weapon_elite"
L 07/19/2011 - 19:15:46: Entity Created! 64386052; "ammo_9mm"
L 07/19/2011 - 19:15:46: Entity Created! 64348296; "weapon_flashbang"
L 07/19/2011 - 19:15:46: Entity Created! 64348276; "weapon_hegrenade"
L 07/19/2011 - 19:15:46: Entity Created! 64348256; "weapon_smokegrenade"
L 07/19/2011 - 19:15:46: Entity Created! 64358940; "weapon_c4"
L 07/19/2011 - 19:15:46: Entity Created! 64348720; "weapon_galil"
L 07/19/2011 - 19:15:46: Entity Created! 64348632; "weapon_famas"
L 07/19/2011 - 19:15:46: Entity Created! 64413744; "weaponbox"
L 07/19/2011 - 19:15:46: Entity Created! 64411348; "item_suit"
L 07/19/2011 - 19:15:46: Entity Created! 64395052; "item_battery"
L 07/19/2011 - 19:15:46: Entity Created! 64411376; "item_antidote"
L 07/19/2011 - 19:15:46: Entity Created! 64411360; "item_security"
L 07/19/2011 - 19:15:46: Entity Created! 64436888; "item_longjump"
L 07/19/2011 - 19:15:46: Entity Created! 64348348; "item_kevlar"
L 07/19/2011 - 19:15:46: Entity Created! 64348316; "item_assaultsuit"
L 07/19/2011 - 19:15:46: Entity Created! 64413756; "item_thighpack"
L 07/19/2011 - 19:15:46: Entity Created! 64348664; "weapon_awp"
L 07/19/2011 - 19:15:46: Entity Created! 64386136; "ammo_338magnum"
L 07/19/2011 - 19:15:46: Entity Created! 64348648; "weapon_g3sg1"
L 07/19/2011 - 19:15:46: Entity Created! 64348708; "weapon_ak47"
L 07/19/2011 - 19:15:46: Entity Created! 64348692; "weapon_scout"
L 07/19/2011 - 19:15:46: Entity Created! 64386120; "ammo_762nato"
L 07/19/2011 - 19:15:46: Entity Created! 64348388; "weapon_m249"
L 07/19/2011 - 19:15:46: Entity Created! 64386076; "ammo_556natobox"
L 07/19/2011 - 19:15:46: Entity Created! 64348620; "weapon_m4a1"
L 07/19/2011 - 19:15:46: Entity Created! 64348676; "weapon_sg552"
L 07/19/2011 - 19:15:46: Entity Created! 64348608; "weapon_aug"
L 07/19/2011 - 19:15:46: Entity Created! 64348592; "weapon_sg550"
L 07/19/2011 - 19:15:46: Entity Created! 64386012; "ammo_556nato"
L 07/19/2011 - 19:15:46: Entity Created! 64348488; "weapon_m3"
L 07/19/2011 - 19:15:46: Entity Created! 64348472; "weapon_xm1014"
L 07/19/2011 - 19:15:46: Entity Created! 64386104; "ammo_buckshot"
L 07/19/2011 - 19:15:46: Entity Created! 64348564; "weapon_usp"
L 07/19/2011 - 19:15:46: Entity Created! 64348456; "weapon_mac10"
L 07/19/2011 - 19:15:46: Entity Created! 64348412; "weapon_ump45"
L 07/19/2011 - 19:15:46: Entity Created! 64386092; "ammo_45acp"
L 07/19/2011 - 19:15:46: Entity Created! 64348500; "weapon_fiveseven"
L 07/19/2011 - 19:15:46: Entity Created! 64348400; "weapon_p90"
L 07/19/2011 - 19:15:46: Entity Created! 64386064; "ammo_57mm"
L 07/19/2011 - 19:15:46: Entity Created! 64348536; "weapon_deagle"
L 07/19/2011 - 19:15:46: Entity Created! 64386040; "ammo_50ae"
L 07/19/2011 - 19:15:46: Entity Created! 64348552; "weapon_p228"
L 07/19/2011 - 19:15:46: Entity Created! 64386028; "ammo_357sig"
L 07/19/2011 - 19:15:46: Entity Created! 64422004; "weapon_knife"
L 07/19/2011 - 19:15:46: Entity Created! 64348576; "weapon_glock18"
L 07/19/2011 - 19:15:46: Entity Created! 64348428; "weapon_mp5navy"
L 07/19/2011 - 19:15:46: Entity Created! 64348444; "weapon_tmp"
L 07/19/2011 - 19:15:46: Entity Created! 64348520; "weapon_elite"
L 07/19/2011 - 19:15:46: Entity Created! 64386052; "ammo_9mm"
L 07/19/2011 - 19:15:46: Entity Created! 64348296; "weapon_flashbang"
L 07/19/2011 - 19:15:46: Entity Created! 64348276; "weapon_hegrenade"
L 07/19/2011 - 19:15:46: Entity Created! 64348256; "weapon_smokegrenade"
L 07/19/2011 - 19:15:46: Entity Created! 64358940; "weapon_c4"
L 07/19/2011 - 19:15:46: Entity Created! 64348720; "weapon_galil"
L 07/19/2011 - 19:15:46: Entity Created! 64348632; "weapon_famas"
L 07/19/2011 - 19:15:46: Entity Created! 64413744; "weaponbox"
__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]

Last edited by Tirant; 07-19-2011 at 22:55.
Tirant is offline
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 07-19-2011 , 23:16   Re: How to loop all entities?
Reply With Quote #18

Okay, this is what I came up with, and it works for checking the entities at the start of the map. You could probably reduce the task, but there needs to be some kind of delay in order to check if the entity exists. I know how bad this method must look creating soo many tasks, but it works. I tested it on 4 standard maps (office, aztec, dust, dust2) and also a few of my base builder maps which have a huge number of entities.

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

// Compensate for entity 32 which cannot be tracked
new g_iTotalEntities 1;

public 
plugin_precache() {
    
register_forward(FM_AllocString"fw_AllocString");
    
register_forward(FM_CreateEntity"fw_CreateEntity");
}

public 
plugin_init() {
    
register_plugin("FM_CreateEntity Test""0.0.1""Tirant");

    
set_task(1.0"delayedCheck");
}

public 
delayedCheck() {
    new 
entCount entity_count();
    
    
g_iTotalEntities += get_maxplayers();
    
server_print("Entities found: %d; Total counted: %d; %s"g_iTotalEntitiesentCountg_iTotalEntities == entCount "SUCCESS!" "FAILURE!");
    
    if (
g_iTotalEntities != entCount) {
        static 
szEntityName[32];
        for (new 
ientCounti++) {
            if (!
pev_valid(i)) {
                
server_print("Invalid entity (%d)"i);
                continue;
            }
                
            
szEntityName[0] = '^0';
            
pev(ipev_classnameszEntityName31);
            
server_print("Entity Found! %d; ^"%s^""iszEntityName);        
        }
    }
}

public 
fw_AllocString(const string[]) {
    
set_task(1.0"checkExisting"_string31);
}

public 
checkExisting(string[], id) {
    if (
find_ent_by_class(-1string)) {
        
g_iTotalEntities++;
        
//server_print("Allocating string: ^"%s^"", string);
    
}
}

public 
fw_CreateEntity(ent) {
    
g_iTotalEntities++;
    
    
//static szEntityName[32];
    //pev(ent, pev_classname, szEntityName, 31);
    //server_print("Entity Created! %d; ^"%s^"", ent, szEntityName);

__________________

PM me if you're interested in buying the Credits addition for Base Builder
Battlefield Rebirth [66% done]
Call of Duty: MW2 [100% done]
Base Builder [100% done]
Tirant is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-20-2011 , 05:30   Re: How to loop all entities?
Reply With Quote #19

Instead of looping through all entities each second, I think my method of is more efficient.
__________________
Hunter-Digital 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 01:17.


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