Foreach player

From EventScripts Community Encyclopedia

Overview

Syntax: foreach player <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: foreach

Description

Runs a command on every player of a group or on a single player. It stores the current player in variable. You can also use it with an es before it.

Note: It doesn't expand server variables!


Parameters

  • variable - a variable where you wish to store the token
  • identifier - the target player/group/sort of players
    • <playername>
    • <steamid>
    • <userid> (not recommended, because there is no need of it!)
    • #all - all players
    • #ct - counter-terrorists
    • #t - terrorists
    • #spec - spectators
    • #un - unassigned (people who never joined a team or spec after connecting)
    • #dead - dead players
    • #alive - living players
    • #human - real players
    • #bot - bots
  • command - the command that will be looped, use es_* commands in it to expand variables.


Examples

 // foreach requires the corelib that comes with EventScripts. This is usually loaded for you when ES starts.
 es_load corelib 
 // let the bots and humans say something
 foreach player tempuserid #bot "es_sexec server_var(tempuserid) say I am a silly bot!" 
 foreach player tempuserid #human "es_sexec server_var(tempuserid) say I am a real player!"


Notes

  • The variable you defined with <variable> will be set to the current userid from the loop. You can access it with server_var(<variable>)
  • If the players died just before the round end, the Source engine still classifies them as alive. So for a reliable #dead/#alive indentifier, use the new deadflag method of ES 1.5 eventscripts_deadflag
  • You can use multiple filters such as #human#alive.


See also

blog comments powered by Disqus