Foreach entity

From EventScripts Community Encyclopedia


Syntax: foreach entity <index-variable> <class-variable> <identifier> <command>

Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.

Variation of this command that doesn't expand variables: {{{x}}}


Runs a command on every entity of an entity class. It stores the entity index in index-variable and the entity class in class-variable. You can also use it with an es before it.

Note: It doesn't expand server variables!


  • index-variable - a variable where you wish to store the entity index
  • class-variable - a variable where you wish to store the entity class
  • identifier - the entity class
  • command - the command that will be looped, use es_* commands in it to expand variables.


 // foreach requires the corelib that comes with EventScripts. This is usually loaded for you when ES starts.
 es_load corelib 
 // Remove all ragdolls
 foreach entity entity_index entity_class cs_ragdoll "es_remove server_var(entity_index)"


  • The variable you defined with <index-variable> will be set to the current index from the loop. You can access it with server_var(<index-variable>). All as <class-variable>.

See also

External links

foreach entity


blog comments powered by Disqus