Page 1 of 1

EntityIter

Posted: Mon Apr 07, 2014 10:29 pm
by satoon101
Since EntityIter was just added yesterday, I thought it would be a good idea to post an example. Just like PlayerIter, WeaponEdictIter, and WeaponClassIter, it will iterate of objects of your liking and yield values of the types you wish. Unlike the other three, there are no "is" or "not" filters. Instead, you pass in a full or partial entity classname or a list of full or partial entity classnames as the first argument. The second argument is a boolean as to whether you want to match full names only or allow partials. The third is the return types, just like the other 3 generators:

Syntax: Select all

from filters.entities import EntityIter 

# Loop through all entities and get their index, Pointer instance, and classname
for index, pointer, classname in EntityIter(return_types=['index', 'pointer', 'classname']):
print(index, pointer, classname)


# Loop through all weapon entities on the server and get their inthandles
# Notice the use of "False" as the second argument to allow all entity classnames with weapon_ to be iterated over
for handle in EntityIter('weapon_', False, 'inthandle'):
print(handle)


# Loop through all players
# Note the use of "True" as the second argument. "player" can also be found in other entity
# classnames, so using True makes sure only entities with the "player" classname are iterated over
for index in EntityIter('player', True, 'index'):
print(index)


Current return types are:
  • index
  • edict
  • basehandle
  • inthandle
  • pointer
  • classname
Other return types will eventually be added, but that is the list for now.

Posted: Fri Oct 10, 2014 11:53 am
by BackRaw
quick question: does "edict" return a BaseEntity instance?

Posted: Fri Oct 10, 2014 12:15 pm
by L'In20Cible
-> isinstance

To answer your question, no it's not. If you want a BaseEntity instance, just use "entity" as return type.

Syntax: Select all

for entity in EntityIter(return_types=['entity']):
...

Posted: Fri Oct 10, 2014 12:57 pm
by satoon101

Posted: Fri Oct 10, 2014 8:43 pm
by BackRaw
aaaah thanks. I thought it would be "entity", too.