Sees and hears
A view cone, reaction time, walls and props in the way. Hears gunfire and running footsteps, turns around when shot.
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.
Drop it on any server. Every bot — from bot_add or GMod's own bot command — gets the brain.
A view cone, reaction time, walls and props in the way. Hears gunfire and running footsteps, turns around when shot.
Turn speed, aim error and head shots by difficulty, and pulls against recoil.
Taps pistols, bursts at range, holds still for long shots, strafes up close, rushes with shotguns and melee, backs off to reload.
Any SWEP or HL2 weapon: pistols, rifles, shotguns, snipers, rockets, melee — the best one for the range.
Throws frags on a real arc, fires the SMG grenade and the AR2 ball.
Its own A* on the navmesh, routes along area edges, spots walls the navmesh missed, vaults half walls, gets unstuck.
Bad ways, death traps, threat angles, good spots and its own map of the level — saved per map.
Hunters search the map, campers hold cover spots, snipers take long sight lines.
Goes for health, armour and new weapons, opens doors, breaks props in the way.
Team play with balance and shuffle, or free-for-all. NPCs take sides.
Live overview of every bot, teams, loadouts, models, map brain and settings. Works on dedicated servers.
Every change saves automatically; presets for whole setups.
bot_add, GMod's bot command or another addon — every bot on the server gets the AI.
A watchdog stops runaway bot code and says where; route searches have a time budget.
Change who they fight, where they go, what they carry — or replace the brain.
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.
Players and hostile NPCs inside its view cone, with nothing solid in the way. Shots and footsteps it hears put it on alert.
Fight, chase, hunt the last known spot, grab health or a better gun, help a teammate, camp, snipe or search the map.
A route over its own learned map or the navmesh, avoiding ways that failed and places where its team keeps dying.
Cuts corners only where it fits, jumps ledges and half walls, opens doors, steers round players, and unsticks itself.
Reacts after a short delay, turns at its skill's speed, bursts or taps by range, strafes, and backs off to reload.
reaction 0.65 s
aim error 3.0°
head shots 5%
reaction 0.40 s
aim error 1.6°
head shots 25%
reaction 0.25 s
aim error 0.8°
head shots 50%
reaction 0.15 s
aim error 0.35°
head shots 75%
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.
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.
Where each side dies a lot for how often it goes there. Routes go around them when there's another way.
Where the shots came from. Walking through, bots glance at those corners; holding a spot, they watch them.
Where kills come from (snipers counted apart): cover, camp and sniper spots are chosen with that in mind.
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.
Per weapon and range: spray, burst or tap, strafe or stand, head or body, how hard to pull recoil — whatever has worked best.
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.
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.Four steps, about a minute.
Get G-Bots from the Steam Workshop and start a game with more than one player slot.
Maps without one: run nav_generate in the console once. The map reloads when it's done.
bot_add, GMod's own bot, or set a quota in the menu and press Fill quota.
Open bot_menu: difficulty, teams, loadouts and models. It all saves by itself.
Everything the menu changes is a server ConVar, so it works from the console and server configs too. All 23 are saved automatically.
| ConVar | Default | What it does |
|---|---|---|
| Bots | ||
bot_quota | 0 | Most bots allowed (0 = no limit). Fill quota adds bots up to it. |
bot_difficulty | 1 | 0 easy, 1 normal, 2 hard, 3 expert: reaction time, aim error, turn speed, head shots, view cone, engage range. |
bot_autoadd | 0 | Fill bots up to the quota whenever a human joins. |
bot_stop | 0 | Freeze every bot. |
bot_mimic | 0 | Every bot copies the first human's movement and buttons. |
| Teams | ||
bot_teamplay | 0 | Red vs Blue. Off = free-for-all. |
mp_autoteambalance | 1 | New bots join the smaller team. Off = a random team. |
bot_force_team | 0 | Put every bot on one team: 0 auto, 10 Red, 11 Blue. |
| Behaviour | ||
bot_ignore_player | 0 | Bots and NPCs ignore human players (bots only fight each other and NPCs). |
bot_realistic_movement | 1 | Slow down near jumps, drops and the end of a route: fewer falls. |
bot_move_speed | 0 | Override the run speed (0 = the player's normal speed). |
bot_limitammo | 1 | Don't walk to ammo pickups (health, armour and new weapons only). |
| Spawning | ||
bot_health | 100 | Bot health on spawn (0 = the gamemode's default). |
bot_armor | 0 | Bot armour on spawn. |
bot_player_alike | 0 | Humans spawn with the bot loadout, model, health and armour too. |
| Learning | ||
bot_learn | 1 | Bots learn each map and use what they learned. |
bot_learn_nav | 1 | Route over the learned map when it knows a sure way (the navmesh for the rest). |
bot_learn_explore | 1 | How much bots experiment: 0 = only what worked best, 2 = learn fast. |
bot_ladders | 0 | Routes may climb ladders people were seen climbing. |
| Navigation | ||
bot_generatenav | 0 | Build a navmesh on maps without one when the first bot is added. The game freezes while it builds, then reloads the map. |
bot_waypoint_notify | 0 | Run GBots_OnBotWaypoint when a bot reaches where it was going. |
bot_watchdog_ms | 50 | Stop any gbots code that runs longer than this (ms) and print where it was (0 = off). |
| Saving | ||
bot_autoload | 1 | Load the saved settings on map start. Every change is saved automatically. |
| Command (admins) | What it does |
|---|---|
bot_menu | Open the admin menu. |
bot_add | Add a bot (to the smaller team when teamplay is on). |
bot_add_red / bot_add_blue | Add a bot to Red or Blue. |
bot_add_fill | Add bots up to bot_quota. |
bot_place | Add 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_all | Respawn every bot. |
bot_freeze / bot_unfreeze <name> | Freeze or unfreeze one bot. |
bot_freeze_all / bot_unfreeze_all | Freeze or unfreeze every bot. |
bot_freeze_list | List frozen bots. |
bot_balance / bot_shuffle | Even out Red and Blue, or shuffle the bots between them. |
bot_brain | What the bots know about this map. |
bot_brain combat | What they learned about fighting with each weapon. |
bot_brain train | Training on/off: 10 bots, double speed, more experimenting. |
bot_brain save / show / reset | Save now, draw it in the world (developer 1), or forget this map. |
bot_data_save / bot_data_load | Save or load the settings (they also save by themselves). |
bot_data_reset / bot_data_delete | Reset everything to defaults, or delete the save. |
changeteam | Open the team picker (also F2 / Show Team) when teamplay is on. |
bot | GMod's own bot command works too: every bot on the server gets the AI. |
41 server-side hooks. Hooks that decide something use the first value returned — return nothing to keep G-Bots' own behaviour.
| Hook & arguments | Return | When / what for |
|---|---|---|
| Brain & targeting 12 | ||
GBots_BotThink( bot, brain ) | true | Skip the built-in brain this think and drive the bot yourself (it stands still unless you do). |
GBots_ChooseGoal( bot, brain ) | Vector|Entity, taskName | Send the bot somewhere. Checked first, every think, before fighting, items and roaming. |
GBots_IsEnemy( bot, ent ) | bool | Decide who a bot fights. Nextbots are only fought when this returns true. |
GBots_CanTarget( bot, ent ) | false | Never target this entity. |
GBots_CanAttack( bot, target ) | false | Hold fire this tick (still aims). |
GBots_GetNPCDisposition( bot, npc ) | D_* constant | How 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 ) | false | A bot got hurt. Return false and it won't turn to look for the attacker. |
| Movement & navigation 12 | ||
GBots_CanMove( bot ) | false | Freeze this bot this tick. |
GBots_CanRoam( bot ) | false | With nothing to do, stand still instead of searching the map. |
GBots_GetRoamTarget( bot ) | Vector|Entity | Where to go when there's nothing to fight or pick up. |
GBots_GetMoveSpeed( bot ) | number | Run speed for this bot. |
GBots_CanJump( bot ) | false | Don't jump. |
GBots_CanCrouch( bot ) | false | Don't crouch. |
GBots_CanPickupItem( bot, ent ) | false | Don'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 ) | false | A 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 ) | false | Block a new bot. |
GBots_GetBotName( teamid ) | string | Name for a new bot. |
GBots_GetSpawnPoint( ply, teamid ) | Entity | Where a bot (or player-alike human) spawns. |
GBots_GetRespawnDelay( bot ) | seconds | How 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 path | Playermodel 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. |
GBots tableA global, server-side, for anything the hooks don't cover.
| Field / function | What it is |
|---|---|
GBots.List | Every bot on the server (players). |
GBots.Frozen | Set 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. |
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 )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)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 )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 )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 )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 ) )
endCopy one into lua/autorun/server/ of your addon and change it from there.
-- 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 )-- 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 )-- 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 )-- 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 )-- 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 )-- 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 )-- 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 )-- 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 )-- 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 )-- Every NPC likes the bots (they still fight each other).
hook.Add( "GBots_GetNPCDisposition", "FriendlyNPCs", function( bot, npc )
return D_LI
end )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.
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.
[gbots] error in … in the consoleThe 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.
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).
Yes: admins open it with bot_menu and every change goes through the server.
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.
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.
Yes. Bots read each weapon's type from its hold type, ammo and slot, so any SWEP pack works with the loadout editor.
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.