EntityIter

Post Python examples to help other users.
User avatar
satoon101
Project Leader
Posts: 2436
Joined: Sat Jul 07, 2012 1:59 am

EntityIter

Postby satoon101 » Mon Apr 07, 2014 10:29 pm

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.
User avatar
BackRaw
Senior Member
Posts: 430
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Oct 10, 2014 11:53 am

quick question: does "edict" return a BaseEntity instance?
User avatar
L'In20Cible
Project Leader
Posts: 999
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Fri Oct 10, 2014 12:15 pm

-> 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']):
...
User avatar
satoon101
Project Leader
Posts: 2436
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Oct 10, 2014 12:57 pm

Image
User avatar
BackRaw
Senior Member
Posts: 430
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Oct 10, 2014 8:43 pm

aaaah thanks. I thought it would be "entity", too.

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: No registered users and 1 guest