Raised This Month: $ Target: $400
 0% 

How to loop all entities?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Tirant
Veteran Member
Join Date: Jul 2008
Location: Los Angeles, California
Old 07-19-2011 , 06:03   Re: How to loop all entities?
Reply With Quote #3

I think this might do the trick. I'm not sure if you create entities or not, so put the entNum before the loops or make it a global variable and initialize at plugin_init(). If you want to reset all entities on round change, I also provided that. I honestly don't think this will slow down the server to any noticeable extent. I mean, in my base builder mod, I reset all entities origin, angles, mins, maxs and owners every round end, and I don't really feel anything (and that's usually ~200 objects). But this will slow down your server, any loop this big would.

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

#define SetAttachedEntity(%1,%2)    (entity_set_int(%1, EV_INT_iuser1, %2))

new entNum = entity_count();

public getAttachedEntities(id) {
    for (new i = get_maxplayers()+1; i < entNum; i++) {
        if (!is_valid_ent(i))
            continue;
        
        if (entity_get_int(i, EV_ENT_aiment) == id && entity_get_int(i, EV_INT_movetype) == MOVETYPE_FOLLOW) {
            SetAttachedEntity(i,id);
        }
    }
}

public resetAttachedEntities() {
    for (new i = get_maxplayers()+1; i < entNum; i++) {
        if (!is_valid_ent(i))
            continue;

        SetAttachedEntity(i,0);
    }
}
__________________

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 06:07.
Tirant is offline
 



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