Garrys Mod Wiki
Advertisement
Nuvola apps important new

Caution: Enemy NPCs will attack you immediately once spawned and are active even while the game menu is open. If you spawn an Antlion or Antlion Guard, it will attack and if your health is reduced enough, kill you - immediately - if it can reach you, even though you haven't released the game menu. However, to prevent this, you can disable the AI, or select the "Ignore Player" check box at the bottom of the Menu.

An NPC is a non-player controlled character. NPCs in GMod are semi-controlled by a basic friend-or-foe AI. This decides which NPCs will shoot at each other and players. GMod supports an NPC object, which is derived from the Entity object and therefore shares all Entity functions.

In the Game Menu, the NPC tab brings up a selection of all the Non-Player Characters (NPCs) which you can create. Friend or enemy NPCs can be created from this menu. Click on one and it is immediately created at the place where the crosshair was when the Game Menu was opened.

For now, the remeinder of this article will just contain a few examples on how NPCs can be manipulated using Lua.

You can download more NPCs in http://www.garrysmod.org.

Or, at the Steam Workshop

Movement

NPCs can be instructed to try and move to a new Vector position in the world. If they cannot directly reach this position, they will not try and find a path to it, thus remaining standing still.

The following code would tell an NPC to try and move to vector. Note: a full listing of SCHED_ enumerations can be found at the end of this article.


<lua> NPC:SetLastPosition( vector ) NPC:SetSchedule( SCHED_FORCED_GO_RUN ) </lua>

Schedule Enumerators

Use these enumerations with NPC.SetSchedule to instruct the NPC to follow a specific order.

SCHED_NONE =			0
SCHED_IDLE_STAND =		1
SCHED_IDLE_WALK	=	 	2
SCHED_IDLE_WANDER=		3
SCHED_WAKE_ANGRY=		4
SCHED_ALERT_FACE =		5
SCHED_ALERT_FACE_BESTSOUND =	6
SCHED_ALERT_SCAN=		7
SCHED_ALERT_STAND =		8
SCHED_ALERT_WALK=		9
SCHED_INVESTIGATE_SOUND =	10
SCHED_COMBAT_FACE=		11
SCHED_COMBAT_SWEEP =		12
SCHED_FEAR_FACE =		13
SCHED_COMBAT_STAND =		14
SCHED_COMBAT_WALK =		15
SCHED_CHASE_ENEMY=		16
SCHED_CHASE_ENEMY_FAILED =	17
SCHED_VICTORY_DANCE =		18
SCHED_TARGET_FACE =		19
SCHED_TARGET_CHASE =		20
SCHED_SMALL_FLINCH =		21
SCHED_BIG_FLINCH =		22
SCHED_BACK_AWAY_FROM_ENEMY =	23
SCHED_BACK_AWAY_FROM_SAVE_POSITION =	24
SCHED_TAKE_COVER_FROM_ENEMY =	25
SCHED_TAKE_COVER_FROM_BEST_SOUND =	26
SCHED_FLEE_FROM_BEST_SOUND =	27
SCHED_TAKE_COVER_FROM_ORIGIN =	28
SCHED_FAIL_TAKE_COVER =		29
SCHED_RUN_FROM_ENEMY =		30
SCHED_RUN_FROM_ENEMY_FALLBACK =	31
SCHED_MOVE_TO_WEAPON_RANGE =	32
SCHED_ESTABLISH_LINE_OF_FIRE =	33
SCHED_SHOOT_ENEMY_COVER=	37
SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK =	34
SCHED_PRE_FAIL_ESTABLISH_LINE_OF_FIRE =	35
SCHED_FAIL_ESTABLISH_LINE_OF_FIRE =	36
SCHED_COWER =			38
SCHED_MELEE_ATTACK1 =		39
SCHED_MELEE_ATTACK2 =		40
SCHED_RANGE_ATTACK1 =		41
SCHED_RANGE_ATTACK2 =		42
SCHED_SPECIAL_ATTACK1 =		43
SCHED_SPECIAL_ATTACK2 =		44
SCHED_STANDOFF =		45
SCHED_ARM_WEAPON =		46
SCHED_DISARM_WEAPON =		47
SCHED_HIDE_AND_RELOAD =		48
SCHED_RELOAD =			49
SCHED_AMBUSH =			50
SCHED_DIE =			51
SCHED_DIE_RAGDOLL =		52
SCHED_WAIT_FOR_SCRIPT =		53
SCHED_AISCRIPT =		54
SCHED_SCRIPTED_WALK =		55
SCHED_SCRIPTED_RUN =		56
SCHED_SCRIPTED_CUSTOM_MOVE =	57
SCHED_SCRIPTED_WAIT =		58
SCHED_SCRIPTED_FACE =		59
SCHED_SCENE_GENERIC =		60
SCHED_NEW_WEAPON =		61
SCHED_NEW_WEAPON_CHEAT =	62
SCHED_GET_HEALTHKIT =		63
SCHED_GIVE_WAY=			65
SCHED_MOVE_AWAY=		66
SCHED_MOVE_AWAY_FAIL =		67
SCHED_MOVE_AWAY_END =		68
SCHED_WAIT_FOR_SPEAK_FINISH =	64
SCHED_FORCED_GO =		70
SCHED_FORCED_GO_RUN =		71
SCHED_PATROL_WALK =		72
SCHED_COMBAT_PATROL =		73
SCHED_PATROL_RUN =		74
SCHED_RUN_RANDOM =		75
SCHED_FAIL =			79
SCHED_FALL_TO_GROUND =		76
SCHED_DROPSHIP_DUSTOFF =	77
SCHED_NPC_FREEZE =		71
SCHED_FLINCH_PHYSICS =		78
SCHED_CROW_IDLE_WALK =		80
SCHED_CROW_IDLE_FLY =		81
SCHED_CROW_WALK_AWAY =		82
SCHED_CROW_RUN_AWAY =		83
SCHED_CROW_HOP_AWAY =		84
SCHED_CROW_FLY_AWAY =		85
SCHED_CROW_FLY =		86
SCHED_CROW_FLY_FAIL =		87

A list of NPCs

Animals

  • Crow
  • Pigeon
  • Seagull
  • Father Grigori

Combine

  • City Scanner
  • Claw Scanner
  • Combine Elite
  • Combine (Shotgun) Soldier
  • Metro Police
  • Prison (Shotgun) Guard
  • Strider
  • Stalker

Human and Resistance

  • Citizens
  • Alyx Vance
  • Dog
  • Dr.Isaac Kleiner
  • Odessa Cubbage
  • Refugee
  • Wallace Breen
  • Barney Ca
  • Vortigaunt Slave
  • Vortigaunt
  • Eli Vance
  • Dr.Judith Mossman

Zombies + Enemy Aliens

  • Antlion
  • Fast Zombie
  • Fast Zombie Torso
  • Headcrab
  • Headcrab Black
  • Headcrab Fast
  • Poison Zombie
  • Zombie
  • Zombie Torso
  • Barnacle

Half Life: Source

  • Barney Calhoun
  • Headcrab
  • Zombie
  • Bull Chicken (Bull Squid)
  • Snark
  • Scientist
  • Grunt
  • Baby Crab
  • Big Momma (Gonarch)
  • Alien Slave
  • Alien Grunt
  • Assassin
  • Controller
  • Gargantua
  • Nihilanth
  • Cockroach

Half-Life 2: Episode 2

  • Dr.Arne Magnusson
  • Antlion Worker
  • Antlion Guardian
  • Zombine
  • Hunter

NPCs Available Through Console (or Addon)

In Garry's Mod, there are NPCs that are available, but the developers never added them to the spawnmenu. These NPCs can be spawned through the console, with the command "npc_create *entityname*". The entity names are listed in parenthesis. Some addons make these NPCs available through spawnmenu.

NPCs like monster_apache, monster_osprey, monster_sentry, monster_turret, and monster_miniturret were never ported to Garry's Mod and are unspawnable.

NPCs like npc_advisor, monster_generic, or cycler have no model and must be given one in order to appear as the specified NPC. These NPCs will also have the model in there parenthesis.

Half-Life 2

  • Advisor (npc_advisor, "models/advisor.mdl")
  • Crab Synth (monster_generic, "models/synth.mdl")
  • Mortar Synth (cycler, "models/mortarsynth.mdl")
  • Ichthyosaur (npc_ichthyosaur)
  • Overwatch Sniper (npc_sniper)
  • Combine Vent Turret (npc_turret_ground, not spawnable, as it needs a brush to work properly)

Half-Life 2: Episode 2

  • Advisor Pod (cycler, "models/advisorpod.mdl")

Half-Life: Source

  • Barnacle (monster_barnacle)
  • Boid (monster_flyer)
  • Leech (monster_leech, it's model is overridden with the Half-Life 2 model, so it doesn't work properly)
  • Ichthyosaur (monster_ichthyosaur)
  • Brown Boid (monster_flyer, "models/aflock.mdl")
  • Flocking Floater (monster_bloater)
  • Government Man (monster_gman)
  • Sitting Scientist (monster_sitting_scientist)
Advertisement