Raised This Month: $ Target: $400
 0% 

How to loop all entities?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-19-2011 , 04:46   Re: How to loop all entities?
Reply With Quote #1

It doesn't slow it that much but it would be faster to store attached entities on creation.... unless your plugin doesn't make them, in that case, this searches for entities near players:

Code:
new g_iMaxPlayers

// plugin_init()
g_iMaxPlayers = get_maxplayers()

// your function
new const Float:fRadius = 8.0 // I really dunno how much to set here =) if it doesn't detect squat, increase
new Float:fOrigin[3]
new ent

for(new id = 1; id <= g_iMaxPlayers; id++)
{
    if(is_user_alive(id))
    {
        entity_get_vector(id, EV_VEC_origin, fOrigin)

        ent = g_iMaxPlayers // skip players from the search

        while((ent = find_ent_in_sphere(ent, fOrigin, fRadius))
        {
            if(entity_get_int(ent, EV_ENT_aiment) == id && entity_get_int(ent, EV_INT_movetype) == MOVETYPE_FOLLOW)
            {
                // ent is attached to id
            }
        }
    }
}
__________________
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:11.


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