Void() Mathieu De Coster

Half-Life 2: Deathmatch, with zombies

My friends and I have been playing Half-Life 2: Deathmatch on and off for over a decade. Recently, we decided we wanted to make things more interesting by adding zombies and antlions into the mix. After a couple of hours of wading through the Valve Developer Wiki, I found enough information to create a small script that will spawn zombies that are aggressive towards the player at the press of a button.

Note: this works on any map, but requires sv_cheats 1, so you will only be able to do it on your own server or on a server where you have rcon access.

NPCs in Half-Life 2: Deathmatch!

Spawning zombies

The console command for spawning an NPC is npc_create npc_name. This will create the given NPC where you’re aiming. The problem is that this NPC will have

  • zero health
  • zero damage
  • zero aggression towards any other living object

To fix the first, we must set the console variable sk_zombie_health. The damage is set by sk_zombie_dmg_one_slash (due to a bug, sk_zombie_dmg_two_slash does nothing).

The aggression is however a bit more complicated. The goal is to bind all of these actions to a single keypress. Binding keys is done with the following console command: bind "key" "command". Setting the agression towards other NPCs is done using this command: ent_fire npc_zombie setrelationship "player d_ht 100". Unfortunately, in Source, we cannot use quotes within quotes, not even if we escape them.

Config files to the rescue

However, we can use config files! By binding exec spawn_zombie.cfg and creating a config file called spawn_zombie.cfg, located in SteamApps/common/Half-Life 2 Deathmatch/hl2mp/cfg, we can execute a list of commands in this config file at the press of a button. The contents of the config file are self-explanatory:

sk_zombie_health 50
sk_zombie_dmg_one_slash 5
npc_create npc_zombie
ent_fire npc_zombie setrelationship "player d_ht 100"

We can spawn a zombie that will attack the player by executing the following command once: bind "n" "exec spawn_zombie.cfg" and then pressing “n” in a server with cheats enabled.

Note that the commands beginning with sk_ are server variables: if you are on a remote or dedicated server, you will need to use rcon, e.g. rcon sk_zombie_health 50.

Spawning antlions

We can now also spawn antlions with the same method, using a different key and config file. Here is an example config file for antlions:

sk_antlion_health 50
sk_antlion_jump_damage 5
sk_antlion_swipe_damage 5
sk_antlion_air_attack_damage 10
npc_create npc_antlion
ent_fire npc_antlion setrelationship "npc_zombie d_ht 100"
ent_fire npc_antlion setrelationship "player d_ht 50"

The cool thing is that here, the antlions will first prioritise the zombies and then the players. You can even create NPCs that fear or like the player by replacing d_ht with d_li for like and d_fr for fear!


Try spawning an antlion guard with 500 hit points and massive charge damage and take it down with some friends. This can lead to a surprising amount of fun!

Without cheats

Of course, it would be more interesting to do this without having to enable cheats (and without having to press buttons), for this, I will look into creating a SourceMod plugin soon.

More information

You can find more information on other NPC types on the Valve Developer Community Wiki. Just search for e.g. “npc_zombie”.