Garry's Mod Wiki


  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 use player slots, so you won't be able to spawn them in singleplayer!
Any Bot created using this method will be considered UnAuthed by Garry's Mod


1 string botName
The name of the bot, using an already existing name will append brackets at the end of it with a number pertaining it.

Example: "Bot name test", "Bot name test(1)".


1 Player
The newly created Player bot. Returns NULL if there's no Player slots available to host it.


Create a bot if that is possible.

local listBots = {} function CreateBot() if ( !game.SinglePlayer() && player.GetCount() < game.MaxPlayers() ) then local num = #listBots listBots[ num ] = player.CreateNextBot("Bot_" .. ( num + 1 ) ) return listBots[ num ] else print( "Can't create bot!" ) end end