Garry's Mod Wiki


The player library is used to get the Lua objects that represent players in-game.


Player player.CreateNextBot( string botName )
Similar to the serverside command "bot", this function creates a new Player bot with the given name. This bot will not obey to the usual "bot_*" commands, and it's the same bot base used in TF2 and CS:S. The best way to control the behaviour of a Player bot right now is to use the GM:StartCommand hook and modify its input serverside. Despite this Player being fake, it has to be removed from the server by using Player:Kick and NOT Entity:Remove. Also keep in mind that these bots still u..
table player.GetAll()
Gets all the current players in the server (not including connecting clients). This function returns bots as well as human players. See player.GetBots and player.GetHumans.This function returns a sequential table, meaning it should be looped with ipairs instead of pairs for efficiency reasons.
table player.GetBots()
Returns a table of all bots on the server.
Player player.GetByAccountID( number accountID )
Gets the player with the specified AccountID.
Player player.GetByID( number connectionID )
Gets the player with the specified connection ID. Connection ID can be retrieved via gameevent.Listen events. For a function that returns a player based on their Entity:EntIndex, see Entity. For a function that returns a player based on their Player:UserID, see Player.
Player player.GetBySteamID( string steamID )
Gets the player with the specified SteamID.
Player player.GetBySteamID64( string steamID64 )
Gets the player with the specified SteamID64.
Player player.GetByUniqueID( string uniqueID )
Gets the player with the specified uniqueID (not recommended way to identify players). It is highly recommended to use player.GetByAccountID, player.GetBySteamID or player.GetBySteamID64 instead as this function can have collisions ( be same for different people ) while SteamID is guaranteed to unique to each player.
number player.GetCount()
Gives you the player count. Similar to #player.GetAll but with much better performance.
table player.GetHumans()
Returns a table of all human ( non bot/AI ) players. Unlike player.GetAll, this does not include bots.

Page Links

Special Pages



Render Time: 28ms

DB GetPage 4
Generate Html 2
SaveChanges (1) 9
Render Body 0
Render Sidebar 10