Garry's Mod
Garry's Mod

NPC Combat and AI Behavior — Garry's Mod Guide

Master Garry's Mod NPC combat AI. Learn to spawn NPCs, enhance their behavior with SNPCs and Nextbots, and use Lua scripting for advanced tactics.

NPC Combat and AI Behavior — Garry's Mod Guide

NPCs (Non-Player Characters) in Garry's Mod can range from simple ragdolls to complex AI-driven combatants. Mastering their combat and AI behavior is key to creating challenging encounters, engaging scenarios, and dynamic worlds. This involves understanding how to spawn them, configure their actions, and leverage their artificial intelligence.

The default NPC tool allows you to spawn various types of NPCs, from standard Combine soldiers to more exotic creatures. However, their default behavior can often be predictable. By using advanced AI addons or custom Lua scripting, you can imbue them with more sophisticated combat tactics, making them formidable opponents or helpful allies.

Key Aspects of NPC Combat and AI:

  • Spawning NPCs: Use the NPC tool (default key F3) to select and place NPCs in the world. You can choose from various factions and types.
  • Basic AI Behaviors: Default NPCs often have basic behaviors like pathfinding, shooting, and taking cover.
  • Combat Tactics: Advanced AI can include flanking, suppressing fire, using grenades, retreating, and coordinating attacks.
  • Perception: How NPCs detect players or other threats (line of sight, sound).
  • Decision Making: The logic that dictates an NPC's actions based on its current situation and goals.
  • NPC Addons: Many Steam Workshop addons provide enhanced AI, new NPC types, or tools for customizing NPC behavior. Examples include advanced SNPCs (Scripted NPCs) and Nextbots.

Enhancing NPC AI:

  1. SNPC Addons: Search the Workshop for 'SNPC' or 'advanced NPC'. These often come with pre-programmed behaviors and customizable parameters.
  2. Nextbots: These are AI entities that use pathfinding and can be programmed with complex behaviors, often used in horror or chase scenarios.
  3. Lua Scripting: For ultimate control, you can write custom Lua scripts to define NPC behaviors from scratch. This involves using functions like `NPC.SetEnemy`, `NPC.SetSchedule`, and manipulating their AI goals.
  4. NPC Properties: Many NPCs have configurable properties like health, damage, accuracy, and reaction times, accessible through their spawn menu or console commands.
  5. Environment Interaction: Program NPCs to utilize cover, open doors, or interact with other map elements to create more dynamic combat.

By understanding and manipulating NPC AI, you can create more challenging and immersive combat experiences in Garry's Mod.