Skip to content

add CDirector::AddSurvivorBot native for spawn survivors (L4D2 only), called via sb_add command#30

Open
spumer wants to merge 1 commit intoSilvDev:mainfrom
spumer:main
Open

add CDirector::AddSurvivorBot native for spawn survivors (L4D2 only), called via sb_add command#30
spumer wants to merge 1 commit intoSilvDev:mainfrom
spumer:main

Conversation

@spumer
Copy link

@spumer spumer commented Feb 13, 2026

Summary

Adds L4D2Direct_AddSurvivorBot(int characterType) native — a direct wrapper around
CDirector::AddSurvivorBot(SurvivorCharacterType) that allows plugins to spawn a new survivor bot with a specific character type.

Motivation

There was no clean way to programmatically add a survivor bot in Left4DHooks. Existing alternatives
have significant drawbacks:

  • ServerCommand("sb_add") — executes asynchronously (next server tick), no return value, no immediate
    control over the created bot
  • CreateFakeClient() + manual setup — low-level and fragile, requires manually handling team
    assignment, character selection, spawning, and many edge cases the engine normally handles

L4D2Direct_AddSurvivorBot calls the engine's own CDirector::AddSurvivorBot — the same function used by
the sb_add console command — providing synchronous execution with proper character selection through
the game's native code path.

API

/**
 * Adds a survivor bot to the game
 *
 * @param characterType			See SurvivorCharacter_* enum values:
 *								0-3 = Map's survivor set characters (set-dependent, see enum)
 *								4-7 = L4D1 characters (Bill, Zoey, Francis, Louis — always)
 *								8   = Random (0-3, guaranteed to create)
 *
 * @remarks Indices 0-3 resolve to different characters depending on the map's survivor set
 *          (L4D2 maps: Nick/Rochelle/Coach/Ellis, L4D1 maps: Bill/Zoey/Louis/Francis).
 * @remarks Characters 4-7: engine checks for duplicates, silently does nothing if taken.
 * @remarks Characters 0-3: engine does NOT check for duplicates, will create a second bot with same character.
 *
 * @return					0
 */
native int L4D2Direct_AddSurvivorBot(int characterType = 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments