Discord Support on Ko-fi by MightyX3N
Early access · Beta

Bots that learn your maps.

G-Bots drives every bot on your Garry's Mod server with a real brain: it sees, hears, aims, picks the right weapon, finds its way — and gets better at each map the more it's played. Works in Sandbox, HL2 deathmatch and any other gamemode.

41hooks
23ConVars
4difficulties
Anygamemode
01

What you get

Drop it on any server. Every bot — from bot_add or GMod's own bot command — gets the brain.

Sees and hears

A view cone, reaction time, walls and props in the way. Hears gunfire and running footsteps, turns around when shot.

Aims like a player

Turn speed, aim error and head shots by difficulty, and pulls against recoil.

Fights smart

Taps pistols, bursts at range, holds still for long shots, strafes up close, rushes with shotguns and melee, backs off to reload.

Picks the right gun

Any SWEP or HL2 weapon: pistols, rifles, shotguns, snipers, rockets, melee — the best one for the range.

Grenades & alt fire

Throws frags on a real arc, fires the SMG grenade and the AR2 ball.

Real pathfinding

Its own A* on the navmesh, routes along area edges, spots walls the navmesh missed, vaults half walls, gets unstuck.

Learns your maps

Bad ways, death traps, threat angles, good spots and its own map of the level — saved per map.

Roles

Hunters search the map, campers hold cover spots, snipers take long sight lines.

Pickups & doors

Goes for health, armour and new weapons, opens doors, breaks props in the way.

Red vs Blue

Team play with balance and shuffle, or free-for-all. NPCs take sides.

Admin menu

Live overview of every bot, teams, loadouts, models, map brain and settings. Works on dedicated servers.

Saves itself

Every change saves automatically; presets for whole setups.

Every bot

bot_add, GMod's bot command or another addon — every bot on the server gets the AI.

Can't freeze your game

A watchdog stops runaway bot code and says where; route searches have a time budget.

41 hooks

Change who they fight, where they go, what they carry — or replace the brain.

02

How a bot thinks

Five times a second each bot decides what to do; every tick it moves and aims like a player would, through the same buttons you press.

  1. 01 · SEE

    Find enemies

    Players and hostile NPCs inside its view cone, with nothing solid in the way. Shots and footsteps it hears put it on alert.

  2. 02 · DECIDE

    Pick a goal

    Fight, chase, hunt the last known spot, grab health or a better gun, help a teammate, camp, snipe or search the map.

  3. 03 · ROUTE

    Plan the way

    A route over its own learned map or the navmesh, avoiding ways that failed and places where its team keeps dying.

  4. 04 · MOVE

    Walk it

    Cuts corners only where it fits, jumps ledges and half walls, opens doors, steers round players, and unsticks itself.

  5. 05 · FIGHT

    Aim and shoot

    Reacts after a short delay, turns at its skill's speed, bursts or taps by range, strafes, and backs off to reload.

0 · EASY

reaction 0.65 s
aim error 3.0°
head shots 5%

1 · NORMAL

reaction 0.40 s
aim error 1.6°
head shots 25%

2 · HARD

reaction 0.25 s
aim error 0.8°
head shots 50%

3 · EXPERT

reaction 0.15 s
aim error 0.35°
head shots 75%

03

The map brain

Every map gets a brain that fills in while people play — bots and humans both. Nothing to set up: the longer a map is played, the better its bots get.

Ways that don't work

Walls the navmesh missed, fake doors, spots bots got stuck: avoided from then on, and tried again now and then in case a door opened.

Death traps

Where each side dies a lot for how often it goes there. Routes go around them when there's another way.

Threat angles

Where the shots came from. Walking through, bots glance at those corners; holding a spot, they watch them.

Good spots

Where kills come from (snipers counted apart): cover, camp and sniper spots are chosen with that in mind.

Their own map

Every step anyone takes becomes a map of the level — jumps, crouches, drops and ladders included. Bots route over it, even on maps with no navmesh.

How to fight

Per weapon and range: spray, burst or tap, strafe or stand, head or body, how hard to pull recoil — whatever has worked best.

DEATH TRAPSKILL SPOTSTRAFFICOWN MAPDEAD ENDS

The Map brain page in the menu: a top-down view of what the bots learned. Show in world draws it around you for 20 seconds.

Teach a map fast: press Train on the Map brain page (or bot_brain train). The server fills with 10 bots at double speed and they experiment more; press it again to stop and save. Brains are saved per map in data/gbots/brain/ and survive a regenerated navmesh.
05

Getting started

Four steps, about a minute.

1

Subscribe

Get G-Bots from the Steam Workshop and start a game with more than one player slot.

2

Give it a navmesh

Maps without one: run nav_generate in the console once. The map reloads when it's done.

3

Add bots

bot_add, GMod's own bot, or set a quota in the menu and press Fill quota.

4

Tune it

Open bot_menu: difficulty, teams, loadouts and models. It all saves by itself.

06

ConVars & commands

Everything the menu changes is a server ConVar, so it works from the console and server configs too. All 23 are saved automatically.

ConVarDefaultWhat it does
Bots
bot_quota0Most bots allowed (0 = no limit). Fill quota adds bots up to it.
bot_difficulty10 easy, 1 normal, 2 hard, 3 expert: reaction time, aim error, turn speed, head shots, view cone, engage range.
bot_autoadd0Fill bots up to the quota whenever a human joins.
bot_stop0Freeze every bot.
bot_mimic0Every bot copies the first human's movement and buttons.
Teams
bot_teamplay0Red vs Blue. Off = free-for-all.
mp_autoteambalance1New bots join the smaller team. Off = a random team.
bot_force_team0Put every bot on one team: 0 auto, 10 Red, 11 Blue.
Behaviour
bot_ignore_player0Bots and NPCs ignore human players (bots only fight each other and NPCs).
bot_realistic_movement1Slow down near jumps, drops and the end of a route: fewer falls.
bot_move_speed0Override the run speed (0 = the player's normal speed).
bot_limitammo1Don't walk to ammo pickups (health, armour and new weapons only).
Spawning
bot_health100Bot health on spawn (0 = the gamemode's default).
bot_armor0Bot armour on spawn.
bot_player_alike0Humans spawn with the bot loadout, model, health and armour too.
Learning
bot_learn1Bots learn each map and use what they learned.
bot_learn_nav1Route over the learned map when it knows a sure way (the navmesh for the rest).
bot_learn_explore1How much bots experiment: 0 = only what worked best, 2 = learn fast.
bot_ladders0Routes may climb ladders people were seen climbing.
Navigation
bot_generatenav0Build a navmesh on maps without one when the first bot is added. The game freezes while it builds, then reloads the map.
bot_waypoint_notify0Run GBots_OnBotWaypoint when a bot reaches where it was going.
bot_watchdog_ms50Stop any gbots code that runs longer than this (ms) and print where it was (0 = off).
Saving
bot_autoload1Load the saved settings on map start. Every change is saved automatically.
Command (admins)What it does
bot_menuOpen the admin menu.
bot_addAdd a bot (to the smaller team when teamplay is on).
bot_add_red / bot_add_blueAdd a bot to Red or Blue.
bot_add_fillAdd bots up to bot_quota.
bot_placeAdd a bot where you're looking.
bot_kick [name]Kick a bot by name, or every bot.
bot_kill [name|all]Kill a bot by name, or all of them.
bot_respawn_allRespawn every bot.
bot_freeze / bot_unfreeze <name>Freeze or unfreeze one bot.
bot_freeze_all / bot_unfreeze_allFreeze or unfreeze every bot.
bot_freeze_listList frozen bots.
bot_balance / bot_shuffleEven out Red and Blue, or shuffle the bots between them.
bot_brainWhat the bots know about this map.
bot_brain combatWhat they learned about fighting with each weapon.
bot_brain trainTraining on/off: 10 bots, double speed, more experimenting.
bot_brain save / show / resetSave now, draw it in the world (developer 1), or forget this map.
bot_data_save / bot_data_loadSave or load the settings (they also save by themselves).
bot_data_reset / bot_data_deleteReset everything to defaults, or delete the save.
changeteamOpen the team picker (also F2 / Show Team) when teamplay is on.
botGMod's own bot command works too: every bot on the server gets the AI.
07

Hook reference

41 server-side hooks. Hooks that decide something use the first value returned — return nothing to keep G-Bots' own behaviour.

Hook & argumentsReturnWhen / what for
Brain & targeting 12
GBots_BotThink( bot, brain )trueSkip the built-in brain this think and drive the bot yourself (it stands still unless you do).
GBots_ChooseGoal( bot, brain )Vector|Entity, taskNameSend the bot somewhere. Checked first, every think, before fighting, items and roaming.
GBots_IsEnemy( bot, ent )boolDecide who a bot fights. Nextbots are only fought when this returns true.
GBots_CanTarget( bot, ent )falseNever target this entity.
GBots_CanAttack( bot, target )falseHold fire this tick (still aims).
GBots_GetNPCDisposition( bot, npc )D_* constantHow an NPC feels about this bot (D_HT, D_LI, D_NU, D_FR).
GBots_OnTargetFound( bot, target )—A bot spotted a new enemy.
GBots_OnTargetLost( bot, target )—A bot lost sight of its enemy.
GBots_OnBotAttack( bot, target, weapon )—A bot pressed fire.
GBots_OnBotReload( bot, weapon )—A bot is reloading.
GBots_OnBotSwitchWeapon( bot, old, new )—A bot picked a different weapon.
GBots_OnBotDamaged( bot, dmginfo )falseA bot got hurt. Return false and it won't turn to look for the attacker.
Movement & navigation 12
GBots_CanMove( bot )falseFreeze this bot this tick.
GBots_CanRoam( bot )falseWith nothing to do, stand still instead of searching the map.
GBots_GetRoamTarget( bot )Vector|EntityWhere to go when there's nothing to fight or pick up.
GBots_GetMoveSpeed( bot )numberRun speed for this bot.
GBots_CanJump( bot )falseDon't jump.
GBots_CanCrouch( bot )falseDon't crouch.
GBots_CanPickupItem( bot, ent )falseDon't walk to this item or weapon.
GBots_OnPathComputed( bot, path )—A route was made: a list of { pos = Vector, area = CNavArea } (learned routes have path.learned).
GBots_OnBotWaypoint( bot, pos )—A bot reached where it was going (needs bot_waypoint_notify 1).
GBots_OnBotStuck( bot )—A bot gave up on a destination it couldn't reach.
GBots_OnObstructionFound( bot, ent, isDoor )falseA door or breakable prop is in the way. Return false to ignore it.
GBots_NavReset( )—The navmesh changed or is being built: every route was dropped.
Spawn & loadout 7
GBots_CanBotBeCreated( teamid )falseBlock a new bot.
GBots_GetBotName( teamid )stringName for a new bot.
GBots_GetSpawnPoint( ply, teamid )EntityWhere a bot (or player-alike human) spawns.
GBots_GetRespawnDelay( bot )secondsHow long a dead bot waits (default 1).
GBots_GetLoadout( ply, teamid ){ classes }Weapons to give on spawn, instead of the loadouts.
GBots_GetPlayerModel( ply, teamid )model pathPlayermodel on spawn.
GBots_OnLoadoutGiven( ply, classes )—Weapons were given.
Lifecycle 7
GBots_OnBotCreated( bot, teamid )—A bot joined (bot_add, the bot command, or another addon).
GBots_OnBotSpawned( bot )—A bot spawned and got its loadout.
GBots_OnBotDeath( bot, attacker )—A bot died.
GBots_OnBotKicked( bot )—A bot is being kicked.
GBots_OnTeamAssigned( ply, teamid )—A bot (or a moved player) got a team.
GBots_OnBotTeamKill( attacker, victim )—A bot killed a teammate.
GBots_OnBotFrozen( bot, frozen )—A bot was frozen or unfrozen.
Admin & settings 3
GBots_OnMenuOpened( ply )—An admin opened the menu.
GBots_OnSettingsSaved( )—Settings were saved (happens a second after any change).
GBots_OnSettingsLoaded( )—Saved settings were loaded.

The GBots table

A global, server-side, for anything the hooks don't cover.

Field / functionWhat it is
GBots.ListEvery bot on the server (players).
GBots.FrozenSet of frozen bots: GBots.Frozen[bot] = true.
GBots:Create( teamid )Add a bot; returns it (or nil).
GBots:Kick( bot, reason ) / GBots:KillBot( bot )Remove or kill a bot.
GBots:GetSkill()The current difficulty profile (reaction, turn, error, head, fov, …).
GBots.Brain.State( bot )A bot's brain: enemy, goal, task, role, path, …
GBots.Brain.Describe( bot )What it's doing, in words ("Chasing Kevin · own map").
GBots.Brain.FindPath( from, to )A route between two points (learned map or navmesh).
GBots.Brain.IsEnemy( bot, ent ) / CanSee( bot, ent )Would it fight this? Can it see it?
GBots.Brain.WeaponInfo( class ){ kind = "auto" | "pistol" | "sniper" | …, melee, auto }
GBots.Brain.Learn.Stats()What the bots know about this map.
GBots.SaveSettings() / GBots.LoadSettings()Save or load everything now.
GBots.Guard( name, fn, … )Run a function with errors contained and reported once.
08

Making an addon for G-Bots

Five steps from an empty file to bots that do what you want. A whole addon can be this small:

hook.Add( "GBots_IsEnemy", "MyAddon_NoHumans", function( bot, ent )
	if ent:IsPlayer() and not ent:IsBot() then return false end
end )
  1. 01

    Make a server file

    Create lua/autorun/server/my_gbots_addon.lua in your addon. Hooks are server-side.

    -- lua/autorun/server/my_gbots_addon.lua
    -- (server only: nothing to send to clients)
  2. 02

    Wait until G-Bots is there

    Addons load in any order, so set up in Initialize and check for the GBots table.

    hook.Add( "Initialize", "MyAddon_Setup", function()
    	if not GBots then
    		print( "[MyAddon] G-Bots isn't installed" )
    		return
    	end
    	print( "[MyAddon] G-Bots found: " .. #GBots.List .. " bots" )
    end )
  3. 03

    Add hooks with your own name

    Give every hook a unique identifier so you don't replace someone else's.

    hook.Add( "GBots_OnBotSpawned", "MyAddon_Welcome", function( bot )
    	bot:SetHealth( 150 )
    end )
  4. 04

    Return a value to change what bots do

    Hooks that decide something use the first value returned. Return nothing to keep the default.

    hook.Add( "GBots_CanTarget", "MyAddon_SpareMedics", function( bot, ent )
    	if ent:IsPlayer() and ent:GetNWBool( "IsMedic" ) then return false end
    end )
  5. 05

    Read a bot's brain

    GBots.Brain.State( bot ) has its enemy, goal, task and role; Describe puts it in words.

    for _, bot in ipairs( GBots.List ) do
    	local b = GBots.Brain.State( bot )
    	print( bot:Nick(), b and b.task, GBots.Brain.Describe( bot ) )
    end
09

Example addons

Copy one into lua/autorun/server/ of your addon and change it from there.

lua/autorun/server/my_gbots_escort.lua
-- Bots stay with the closest human on their team and fight what comes at them.
hook.Add( "GBots_ChooseGoal", "Escort_Follow", function( bot, brain )
	if IsValid( brain.enemy ) then return end   -- fighting: let the brain handle it

	local leader, best
	for _, ply in ipairs( player.GetHumans() ) do
		if ply:Alive() and ply:Team() == bot:Team() then
			local d = ply:GetPos():DistToSqr( bot:GetPos() )
			if not best or d < best then leader, best = ply, d end
		end
	end
	if not leader then return end

	if best > 200 * 200 then return leader:GetPos(), "follow" end
	return bot:GetPos(), "follow"   -- close enough: wait here
end )

-- and never shoot people
hook.Add( "GBots_IsEnemy", "Escort_Friendly", function( bot, ent )
	if ent:IsPlayer() and not ent:IsBot() then return false end
end )
lua/autorun/server/my_gbots_guard_post.lua
-- Admins type "guard_here" and every bot holds that spot.
local post

concommand.Add( "guard_here", function( ply )
	if not IsValid( ply ) or not ply:IsAdmin() then return end
	post = ply:GetPos()
	ply:ChatPrint( "Bots now guard this spot." )
end )

hook.Add( "GBots_ChooseGoal", "Guard_Post", function( bot, brain )
	if post and not IsValid( brain.enemy ) then return post, "guard" end
end )
lua/autorun/server/my_gbots_patrol.lua
-- Bots walk a loop of points, one after the other.
local route = {
	Vector( 0, 0, 0 ), Vector( 800, 0, 0 ), Vector( 800, 800, 0 ), Vector( 0, 800, 0 ),
}

hook.Add( "GBots_ChooseGoal", "Patrol_Route", function( bot, brain )
	if IsValid( brain.enemy ) then return end
	brain.patrol = brain.patrol or 1
	if bot:GetPos():DistToSqr( route[ brain.patrol ] ) < 100 * 100 then
		brain.patrol = brain.patrol % #route + 1
	end
	return route[ brain.patrol ], "patrol"
end )
lua/autorun/server/my_gbots_waves.lua
-- Each wave adds more bots; dead bots stay dead until the next wave.
local wave = 0

local function NextWave()
	wave = wave + 1
	for i = #GBots.List, 1, -1 do GBots:Kick( GBots.List[ i ], "Next wave" ) end
	for i = 1, 2 + wave * 2 do GBots:Create() end
	PrintMessage( HUD_PRINTCENTER, "Wave " .. wave )
end

hook.Add( "GBots_GetRespawnDelay", "Waves_NoRespawn", function() return 1e9 end )

hook.Add( "GBots_OnBotDeath", "Waves_Check", function()
	timer.Simple( 0.1, function()
		for _, b in ipairs( GBots.List ) do if IsValid( b ) and b:Alive() then return end end
		timer.Simple( 5, NextWave )
	end )
end )

concommand.Add( "waves_start", function( ply ) if not IsValid( ply ) or ply:IsAdmin() then NextWave() end end )
lua/autorun/server/my_gbots_darkrp.lua
-- Bots dress and arm like police and only go after wanted players.
hook.Add( "GBots_GetPlayerModel", "RP_Police", function() return "models/player/police.mdl" end )
hook.Add( "GBots_GetLoadout", "RP_Police", function() return { "weapon_stunstick", "weapon_pistol" } end )

hook.Add( "GBots_IsEnemy", "RP_Police", function( bot, ent )
	if not ent:IsPlayer() or ent:IsBot() then return end
	return ent.isWanted ~= nil and ent:isWanted() or false
end )
lua/autorun/server/my_gbots_scores.lua
-- Print a bot leaderboard to everyone after each bot kill.
hook.Add( "PlayerDeath", "Scores_Board", function( victim, inflictor, attacker )
	if not ( IsValid( attacker ) and attacker:IsPlayer() and attacker:IsBot() ) then return end
	local bots = table.Copy( GBots.List )
	table.sort( bots, function( a, b ) return a:Frags() > b:Frags() end )
	for i = 1, math.min( 3, #bots ) do
		PrintMessage( HUD_PRINTTALK, i .. ". " .. bots[ i ]:Nick() .. " — " .. bots[ i ]:Frags() )
	end
end )
lua/autorun/server/my_gbots_pickups.lua
-- Bots never walk to an RPG lying on the ground.
hook.Add( "GBots_CanPickupItem", "NoRPG", function( bot, ent )
	if ent:GetClass() == "weapon_rpg" then return false end
end )
lua/autorun/server/my_gbots_logging.lua
-- Log every time a bot kills a teammate.
hook.Add( "GBots_OnBotTeamKill", "FF_Log", function( attacker, victim )
	ServerLog( "[gbots] " .. attacker:Nick() .. " team-killed " .. victim:Nick() .. "\n" )
end )
lua/autorun/server/my_gbots_rounds.lua
-- Your gamemode has a freeze time: bots stand still until it's over.
hook.Add( "GBots_BotThink", "MyMode_Freeze", function( bot, brain )
	if MyMode and MyMode.InFreezeTime() then return true end
end )
lua/autorun/server/my_gbots_npcs.lua
-- Every NPC likes the bots (they still fight each other).
hook.Add( "GBots_GetNPCDisposition", "FriendlyNPCs", function( bot, npc )
	return D_LI
end )
10

Questions & fixes

Bots stand still or walk into walls

They need a navmesh. Run nav_generate once on the map (the map reloads when it's done), or turn on bot_generatenav. Without one, bots walk straight at things until people have walked the map: then they route over what they learned.

The game stops responding when I add the first bot

That's GMod building a navmesh because bot_generatenav is on and the map has none. It can take minutes on big maps and then reloads the map. Turn it off, or run nav_generate once yourself.

I see [gbots] error in … in the console

The bot code hit an error; that bot resets for a second and the error is shown once every 10 seconds instead of every tick. Send the first lines on Discord.

My settings don't stick

They save by themselves a second after every change, to data/gbots/settings.json, and load on map start while bot_autoload is 1 (the default).

Can I use the menu on a dedicated server?

Yes: admins open it with bot_menu and every change goes through the server.

How heavy are the bots?

The menu's header shows the AI's cost per tick. Route searches share a small budget each tick, so many bots on a big map can't freeze the server.

Where is the map brain saved?

data/gbots/brain/<map>.json per map and _combat.json for fighting. Ship a starter brain in data_static/gbots/brain/ with your map pack.

Do they work with TFA, ARC9 and other weapon packs?

Yes. Bots read each weapon's type from its hold type, ammo and slot, so any SWEP pack works with the loadout editor.

OpenSource

Want real team games?

G-Bots' brain comes from OpenSource, a Counter-Strike: Source gamemode for Garry's Mod built to be modified. There the bots get something to play for.

  • Rounds, buy time, money and a buy menu
  • Plant and defuse the bomb, rescue hostages, escort the VIP
  • Bots buy their own gear, plan each round and talk on the radio
  • Bots follow your radio orders; take over a bot when you die
  • Deathmatch, Arena and Gun Game modes
Which one?

Stay with G-Bots if…

  • you want bots in Sandbox or another gamemode
  • you're building, testing maps or fighting NPCs
  • you just want a quick deathmatch

Use OpenSource if…

  • you want proper team games with rounds and objectives
  • you want bots that buy, plan, talk and follow orders
  • you want the full Counter-Strike: Source experience