Hey! I'm new to the forum.. i found it through another thread about NPCs in single player, and I saw a lot of questions on this forum and elsewhere regarding using NPCs in DM.. so here's a small tutorial detailing what I've found in the last couple of days:
WORKING WITH NPCs IN DM v1.0
FIGHTING
Yes, you CAN spawn NPCs in DM, and they CAN fight!! A lot of the players are buggy.. and I've yet to get humanoid players to fight... but basically to get an NPC to fight you have to do a few things:
Step 1: Set up that particular NPCs variables (I guess you'd call them global variables??)... most of these are called sk_NPCname_other stuff.. you can just go into console, type "sk_" and scroll through the list of variables.. for an antlion, here are the things that you can set:
sk_antlion_health - the amount of health that antlions will have when you spawn them
sk_antlion_jump_damage - the amount of health that the antlion will take away when they jump on you
sk_antlion_swipe_damage - the amount of health that the antlion will take away when they swipe attack you
These three variables should be set before spawning any antlions, any antlions that you spawned prior to setting this up will not have the values that you set. I have seen people asking about how to set the health of NPCs.. and they have been answered with "ent_fire [npc name] sethealth [amount of health]" but I haven't gotten that to work.. every NPC has a health variable, just look for it.. but anyway, the way you'd set these would be to go to console and type the variable a space and the value, so to set the health of antlions, you would enter "sk_antlion_health 100" to give them 100 hp when they spawn.
NOTE: NPCs can have more than 100 health.. so if you wanted to make antlions that are really difficult to kill, you could give them 300hp.
For an awesome list of console commands, including all of the sk_ commands, see: http://www.h l 2 w o r l d .com/wiki/index.php/Half_Life_2_Client_Console_Commands
Step 2: Spawn the NPCs.. this is pretty easy.. I believe that every humanoid and animal NPC can be spawned with the npc_create command, except for strider (use the give command for him), so to spawn an antlion you'd point your crosshair wherever you want to spawn the antlion and then enter "npc_create npc_antlion" in console. You can keep doing this until you have the desired amount of antlions, but just note that if you spawn a lot of NPCs in one area, the game can get quite laggy. Also, to make things easier, I usually bind the create command, so if I wanted to make a bunch of antlions, I'd enter bind 8 "npc_create npc_antlion" in console, and then just point and hit the 8 key wherever I want an antlion...
For a list of NPCs, search this forum or google it.. there are many many different lists!
Step 3: Now that you've spawned your NPCs, you need to tell them who to attack. This is done by setting a relationship between the NPCs and whatever you want them to attack.. so if you wanted all of the antlions to attack all of the human players, you would enter [ent_fire npc_antlion setrelationship "player D_HT 99"] in console.. I'll talk a little more about the ent_fire command later. Let's take a look at this command, because there's a lot that you can do with it..
npc_antlion: this is the entity that you are instructing to attack other things, we wanted to instruct ALL antlions to kill the human players, if we wanted just one particular antlion to do this, we'd have to name it by setting our crosshair on it and entering [ent_setname newname] in console, where newname would be some unique name for the antlion, like Bob. Then instead of npc_antlion, we'd use Bob, so the command only applies to that one antlion.
player: this is the entity that you want the NPC to attack, player is the name of all human players.. again, if you wanted to instruct it to attack only one human player, you'd have to set your crosshair on that player and use ent_setname, then replace "player" with whatever you named the player. You can also instruct the NPC to attack other NPCs.. so if you also spawned some zombies, you could replace "player" with "npc_zombie", or again, use ent_setname on a particular zombie, and use that name so the antlions only attack that one zombie.
D_HT: This tells the NPC(s) that you want to create a hate relationship, which means that the NPC will attack whoever you specify.. you can also create "like" relationships by replacing D_HT with D_LK, but I haven't player around with this too much. If it does something really cool, I'll update this tutorial.
99: This is a level of hate (or a level of like, if you used D_LK), I usually use 99, because I don't really know what it does and haven't experimented with it too much. I'd assume that if you created a relationship that told antlions to attack players and used 99, and created another relationship between antlions and zombies but used 20, the antlions would try to attack players before they attack zombies.. that's just a guess, though.
That's pretty much it.. if you followed those three steps, as soon as you hit enter on the ent_fire command, the NPCs will begin searching/attacking whatever you told them to.
ENT_FIRE
I was going to end the tutorial here, but I decided that I have learned so much about ent_fire in the last few days, that it warranted a section in this tiny tutorial.. so here it goes:
Entities are anything that exist and can interact with players in the game.. this includes animals, robots, and anything that you can pick up with the grav gun. Entities have inputs and outputs... which are both used by the game, but in a far more complicated way than we are going to be using them. We don't care about outputs, because I've yet to find a cool use for them, but if you do, please post it!
ent_fire is a command used by developers to use one input on an entity.. it is used in console like this:
ent_fire [name of entity] [command]
I'm sure you've seen people posting how to burn stuff all over the web.. "ignite" is an input that all entities have (but not all entities use), so if you wanted to set every player on fire, you could enter "ent_fire player ignite" in console. This is a lot of fun if nobody has seen it before.. but if you keep doing it, you'll definitely just piss everyone off I like to bind the following command, which burns whatever is under your crosshair:
bind b "ent_setname burn;ent_fire burn ignite"
That command sets the entity that you have under your cross hair's name to "burn" then uses ent_fire to trigger the "ignite" input on the "burn" entity. Just be careful, because once you name something, it is called that until the map changes, the server is restarted, or the entity is destroyed.. I'm still looking for a command that unnames an entity.. the effect of this is that if you burn a player, that player will be called "burn," so later when you decide to burn an ammo box, the command sets the ammo box's name to "burn", then tells the game to trigger the ignite input on all entities named "burn," which are the ammo box and the player that you had burned earlier. Thus, that poor player will be burned every single time However, this does not happen with entities that respawn, for instance, if you burn an exploding barrel, it will eventually explode, but when it respawns, it will not be called "burn" anymore. It seems that the only entities that keeps their names even after being respawned are players.
For a complete list of inputs and outputs, use the ent_info command. It is used as follows:
ent_info [class name]
Where [class name] is the class name of the entity that you are interested in.. so to get a list of inputs and outputs for our beloved antlion, we'd issue the following command in console:
ent_info npc_antlion
...and a nice list of things you can do with the antlion is spit out in the console. Some of the inputs require a parameter, some don't.. I haven't really played around with complicated inputs that require parameters. An example of a really cool thing that you can do with inputs would be to bind the burrow and unburrow inputs for the antlions:
bind uparrow "ent_fire npc_antlion unburrow"
bind downarrow "ent_fire npc_antlion burrow"
Now, whenever you hit the down arrow, all of the npc_antlions that you spawed will burrow into the ground, and will unburrow when you hit the up arrow!
Look around for cool commands.. I was able to get the helicopter to drop bombs (but wasn't able to get it to chase me) and I was almost able to get the npc_dog to play catch by playing around with inputs, if anyone figures out how to do that, please let me know!
TIPS AND IDEAS
Tip #1: When placing a lot of npcs around a map, I find it easier to turn on noclip by entering "noclip" in console. This allows you to "fly" around the map, and get a good idea of how many npcs are in a particular room. Plus, you can move around a lot faster, so you don't waste too much time setting the map up. Just make sure that your crosshair is pointing at the floor when you spawn the NPC, otherwise it won't spawn (to see those errors, developer mode has to be set to 2). To turn noclip mode off, just enter "noclip" in console, again.
Tip #2: If you want to place everyone on the same team very quickly, the player entity has a setteam input. To use it, enter the following command in console:
ent_fire player setteam #
Replace # with one of the following numbers:
0 - Unassigned
1 - Spectator
2 - Combine
3 - Rebels
I don't think that the model changes when you perform this command, so if you wanted to be a combine super soldier but wanted to be on the rebel team, you could have another player use ent_setname to name your player, and then use that name instead of player so the setteam input only applies to you. For example:
While you are under the other player's crosshair, he'd enter: "ent_setname Jim" in console
And then: "ent_fire Jim setteam 3" to place you on the Rebel team.
I can't remember if this changes your model, but it shouldn't.
Tip #3: For entities that fly, such as npc_combinegunship, npc_helicopter, or npc_combinedropship, to place them above the map, where they should be, use noclip to fly to wherever you want them, and then use "give" instead of "npc_create." For example, after using noclip to position myself wherever I want an npc_helicopter, i'd enter the following command in console:
give npc_helicopter
To avoid getting stuck in the NPC and to avoid damage from falling, fly back down to the ground before turning off noclip. The give command places the entity above you, whereas the npc_create command places the entity on the map wherever your crosshair is pointed at.
Tip #4: To make sure that the NPCs are doing what I want them to do, I often set developer mode to 2 and use the ent_show_response_criteria command. This command displays detailed info about the entity that is under your crosshair, most notably: the health of the entity. This is great if you want to make sure that your antlions are spawning with a bazillion health points and that the zombies are losing hp whenever antlionguards charge them :cheese:. Usually, I bind this command, so I don't have to keep switching to console, since this info is both spit out in console and in the upper left corner of the screen.. so the sequence of commands that I'd enter to set this up would be:
developer 2
bind c "ent_show_response_criteria"
Obviously, you can bind it to whatever key you want.. but when you're done, it's usually a good idea to set developer mode back to 0, because NPCs can sometimes spit out a lot of info in console, and that will start to annoy you.
Another great use for ent_show_response_criteria is to find out the names of entities that you didn't spawn, for example, if you spawn a helicopter and make it drop a bomb using ent_fire, you might be interested in spawning those cool bombs without going through the hassle of spawning a helicopter.. so you could simply set your crosshair over the bomb and issue the ent_show_response_criteria command to find out that the bomb is called "grenade_helicopter." Now, you can simply use "npc_create grenade_helicopter" to spawn those nifty bombs!!
Idea #1: For those of you who have never played the BrainBread mod for HL1, it is an awesome mod that is just like Dawn of the Dead.. there are basically a bunch of zombies, and you have to kill them all. All of the players are on a single "human" team, and players can be infected by zombies, and are then placed on the "Zombie" team, and must kill a couple of humans before they can respawn as a human again. There is supposed to be a brainbread mod for HL2 coming out, but until then, we can somewhat mimmick the mod by placing a bunch of npc_zombies around a map (I like lockdown). Then you just have to put everyone on one team, use the setrelationship input that I discussed before to tell the zombies to attack players, and let the fun begin! You can control the difficulty of the game by increasing/decreasing the health of the zombies and the damage that they cause. Unfortunately, we can't get infected by them, for that we'll have to wait for the real mod! Variations of this game are also a lot of fun, try using antlions, they're awesome!
Idea #2: When you kill an npc_zombie, if you don't shoot it in the head, the headcrab remains alive. Unfortunately, it is not considered an npc_headcrab until the npc_zombie is dead, so you can't use set a relationship between the headcrabs and the players until the zombie is killed. I'm sure that there's a way to set up a trigger sort of thing, so when an npc_zombie is killed, the "ent_fire npc_headcrab setrelationship..." command is executed. Until then, you could always wait until the zombies are dead, then set up the relationship, and clean up the remaining headcrabs.
Idea #3: Use ent_setname to name the players on the opposite team in team deathmatch (you don't have to use unique names, you could just call them all combine if the are on the combine team, or rebel if they are on the rebel team), then spawn a few "npc_vortigaunt"s or "npc_turret_floor"s and set up a hate relationship between those NPCs and whatever you called the players. I'd consider binding the ent_setname command, so you can quickly name the other players, because it would be difficult to go into console and enter the command every time, since the players are usually moving. The commands would look something like this:
bind n "ent_setname combine"
..You'd name the players on the opposite team by placing them under your crosshair and hitting "n"
Spawn some npcs (I suggested vortigaunt and turret_floor because they don't move, they just attack whatever's near them, so they're ideal for holding up a certain area) using "npc_create npc_whatever"
ent_fire npc_whatever setrelationship "combine D_HT 99"
Well, I think that's about it for this tutorial. Pay attention to the version number, because I might change this tutorial as I learn new things and receive new input. I really hope that this helps everyone, and if you have any further questions/comments/ideas/anythings please post and I'll respond as soon as possible! I'd also like to thank the other post on this board that discussed the use of NPCs in single player, I wish I still had the link, it taught me a lot about NPCs, and allowed me to learn how to use them in DM as well as single player. Thanks!
--Jimbro
WORKING WITH NPCs IN DM v1.0
FIGHTING
Yes, you CAN spawn NPCs in DM, and they CAN fight!! A lot of the players are buggy.. and I've yet to get humanoid players to fight... but basically to get an NPC to fight you have to do a few things:
Step 1: Set up that particular NPCs variables (I guess you'd call them global variables??)... most of these are called sk_NPCname_other stuff.. you can just go into console, type "sk_" and scroll through the list of variables.. for an antlion, here are the things that you can set:
sk_antlion_health - the amount of health that antlions will have when you spawn them
sk_antlion_jump_damage - the amount of health that the antlion will take away when they jump on you
sk_antlion_swipe_damage - the amount of health that the antlion will take away when they swipe attack you
These three variables should be set before spawning any antlions, any antlions that you spawned prior to setting this up will not have the values that you set. I have seen people asking about how to set the health of NPCs.. and they have been answered with "ent_fire [npc name] sethealth [amount of health]" but I haven't gotten that to work.. every NPC has a health variable, just look for it.. but anyway, the way you'd set these would be to go to console and type the variable a space and the value, so to set the health of antlions, you would enter "sk_antlion_health 100" to give them 100 hp when they spawn.
NOTE: NPCs can have more than 100 health.. so if you wanted to make antlions that are really difficult to kill, you could give them 300hp.
For an awesome list of console commands, including all of the sk_ commands, see: http://www.h l 2 w o r l d .com/wiki/index.php/Half_Life_2_Client_Console_Commands
Step 2: Spawn the NPCs.. this is pretty easy.. I believe that every humanoid and animal NPC can be spawned with the npc_create command, except for strider (use the give command for him), so to spawn an antlion you'd point your crosshair wherever you want to spawn the antlion and then enter "npc_create npc_antlion" in console. You can keep doing this until you have the desired amount of antlions, but just note that if you spawn a lot of NPCs in one area, the game can get quite laggy. Also, to make things easier, I usually bind the create command, so if I wanted to make a bunch of antlions, I'd enter bind 8 "npc_create npc_antlion" in console, and then just point and hit the 8 key wherever I want an antlion...
For a list of NPCs, search this forum or google it.. there are many many different lists!
Step 3: Now that you've spawned your NPCs, you need to tell them who to attack. This is done by setting a relationship between the NPCs and whatever you want them to attack.. so if you wanted all of the antlions to attack all of the human players, you would enter [ent_fire npc_antlion setrelationship "player D_HT 99"] in console.. I'll talk a little more about the ent_fire command later. Let's take a look at this command, because there's a lot that you can do with it..
npc_antlion: this is the entity that you are instructing to attack other things, we wanted to instruct ALL antlions to kill the human players, if we wanted just one particular antlion to do this, we'd have to name it by setting our crosshair on it and entering [ent_setname newname] in console, where newname would be some unique name for the antlion, like Bob. Then instead of npc_antlion, we'd use Bob, so the command only applies to that one antlion.
player: this is the entity that you want the NPC to attack, player is the name of all human players.. again, if you wanted to instruct it to attack only one human player, you'd have to set your crosshair on that player and use ent_setname, then replace "player" with whatever you named the player. You can also instruct the NPC to attack other NPCs.. so if you also spawned some zombies, you could replace "player" with "npc_zombie", or again, use ent_setname on a particular zombie, and use that name so the antlions only attack that one zombie.
D_HT: This tells the NPC(s) that you want to create a hate relationship, which means that the NPC will attack whoever you specify.. you can also create "like" relationships by replacing D_HT with D_LK, but I haven't player around with this too much. If it does something really cool, I'll update this tutorial.
99: This is a level of hate (or a level of like, if you used D_LK), I usually use 99, because I don't really know what it does and haven't experimented with it too much. I'd assume that if you created a relationship that told antlions to attack players and used 99, and created another relationship between antlions and zombies but used 20, the antlions would try to attack players before they attack zombies.. that's just a guess, though.
That's pretty much it.. if you followed those three steps, as soon as you hit enter on the ent_fire command, the NPCs will begin searching/attacking whatever you told them to.
ENT_FIRE
I was going to end the tutorial here, but I decided that I have learned so much about ent_fire in the last few days, that it warranted a section in this tiny tutorial.. so here it goes:
Entities are anything that exist and can interact with players in the game.. this includes animals, robots, and anything that you can pick up with the grav gun. Entities have inputs and outputs... which are both used by the game, but in a far more complicated way than we are going to be using them. We don't care about outputs, because I've yet to find a cool use for them, but if you do, please post it!
ent_fire is a command used by developers to use one input on an entity.. it is used in console like this:
ent_fire [name of entity] [command]
I'm sure you've seen people posting how to burn stuff all over the web.. "ignite" is an input that all entities have (but not all entities use), so if you wanted to set every player on fire, you could enter "ent_fire player ignite" in console. This is a lot of fun if nobody has seen it before.. but if you keep doing it, you'll definitely just piss everyone off I like to bind the following command, which burns whatever is under your crosshair:
bind b "ent_setname burn;ent_fire burn ignite"
That command sets the entity that you have under your cross hair's name to "burn" then uses ent_fire to trigger the "ignite" input on the "burn" entity. Just be careful, because once you name something, it is called that until the map changes, the server is restarted, or the entity is destroyed.. I'm still looking for a command that unnames an entity.. the effect of this is that if you burn a player, that player will be called "burn," so later when you decide to burn an ammo box, the command sets the ammo box's name to "burn", then tells the game to trigger the ignite input on all entities named "burn," which are the ammo box and the player that you had burned earlier. Thus, that poor player will be burned every single time However, this does not happen with entities that respawn, for instance, if you burn an exploding barrel, it will eventually explode, but when it respawns, it will not be called "burn" anymore. It seems that the only entities that keeps their names even after being respawned are players.
For a complete list of inputs and outputs, use the ent_info command. It is used as follows:
ent_info [class name]
Where [class name] is the class name of the entity that you are interested in.. so to get a list of inputs and outputs for our beloved antlion, we'd issue the following command in console:
ent_info npc_antlion
...and a nice list of things you can do with the antlion is spit out in the console. Some of the inputs require a parameter, some don't.. I haven't really played around with complicated inputs that require parameters. An example of a really cool thing that you can do with inputs would be to bind the burrow and unburrow inputs for the antlions:
bind uparrow "ent_fire npc_antlion unburrow"
bind downarrow "ent_fire npc_antlion burrow"
Now, whenever you hit the down arrow, all of the npc_antlions that you spawed will burrow into the ground, and will unburrow when you hit the up arrow!
Look around for cool commands.. I was able to get the helicopter to drop bombs (but wasn't able to get it to chase me) and I was almost able to get the npc_dog to play catch by playing around with inputs, if anyone figures out how to do that, please let me know!
TIPS AND IDEAS
Tip #1: When placing a lot of npcs around a map, I find it easier to turn on noclip by entering "noclip" in console. This allows you to "fly" around the map, and get a good idea of how many npcs are in a particular room. Plus, you can move around a lot faster, so you don't waste too much time setting the map up. Just make sure that your crosshair is pointing at the floor when you spawn the NPC, otherwise it won't spawn (to see those errors, developer mode has to be set to 2). To turn noclip mode off, just enter "noclip" in console, again.
Tip #2: If you want to place everyone on the same team very quickly, the player entity has a setteam input. To use it, enter the following command in console:
ent_fire player setteam #
Replace # with one of the following numbers:
0 - Unassigned
1 - Spectator
2 - Combine
3 - Rebels
I don't think that the model changes when you perform this command, so if you wanted to be a combine super soldier but wanted to be on the rebel team, you could have another player use ent_setname to name your player, and then use that name instead of player so the setteam input only applies to you. For example:
While you are under the other player's crosshair, he'd enter: "ent_setname Jim" in console
And then: "ent_fire Jim setteam 3" to place you on the Rebel team.
I can't remember if this changes your model, but it shouldn't.
Tip #3: For entities that fly, such as npc_combinegunship, npc_helicopter, or npc_combinedropship, to place them above the map, where they should be, use noclip to fly to wherever you want them, and then use "give" instead of "npc_create." For example, after using noclip to position myself wherever I want an npc_helicopter, i'd enter the following command in console:
give npc_helicopter
To avoid getting stuck in the NPC and to avoid damage from falling, fly back down to the ground before turning off noclip. The give command places the entity above you, whereas the npc_create command places the entity on the map wherever your crosshair is pointed at.
Tip #4: To make sure that the NPCs are doing what I want them to do, I often set developer mode to 2 and use the ent_show_response_criteria command. This command displays detailed info about the entity that is under your crosshair, most notably: the health of the entity. This is great if you want to make sure that your antlions are spawning with a bazillion health points and that the zombies are losing hp whenever antlionguards charge them :cheese:. Usually, I bind this command, so I don't have to keep switching to console, since this info is both spit out in console and in the upper left corner of the screen.. so the sequence of commands that I'd enter to set this up would be:
developer 2
bind c "ent_show_response_criteria"
Obviously, you can bind it to whatever key you want.. but when you're done, it's usually a good idea to set developer mode back to 0, because NPCs can sometimes spit out a lot of info in console, and that will start to annoy you.
Another great use for ent_show_response_criteria is to find out the names of entities that you didn't spawn, for example, if you spawn a helicopter and make it drop a bomb using ent_fire, you might be interested in spawning those cool bombs without going through the hassle of spawning a helicopter.. so you could simply set your crosshair over the bomb and issue the ent_show_response_criteria command to find out that the bomb is called "grenade_helicopter." Now, you can simply use "npc_create grenade_helicopter" to spawn those nifty bombs!!
Idea #1: For those of you who have never played the BrainBread mod for HL1, it is an awesome mod that is just like Dawn of the Dead.. there are basically a bunch of zombies, and you have to kill them all. All of the players are on a single "human" team, and players can be infected by zombies, and are then placed on the "Zombie" team, and must kill a couple of humans before they can respawn as a human again. There is supposed to be a brainbread mod for HL2 coming out, but until then, we can somewhat mimmick the mod by placing a bunch of npc_zombies around a map (I like lockdown). Then you just have to put everyone on one team, use the setrelationship input that I discussed before to tell the zombies to attack players, and let the fun begin! You can control the difficulty of the game by increasing/decreasing the health of the zombies and the damage that they cause. Unfortunately, we can't get infected by them, for that we'll have to wait for the real mod! Variations of this game are also a lot of fun, try using antlions, they're awesome!
Idea #2: When you kill an npc_zombie, if you don't shoot it in the head, the headcrab remains alive. Unfortunately, it is not considered an npc_headcrab until the npc_zombie is dead, so you can't use set a relationship between the headcrabs and the players until the zombie is killed. I'm sure that there's a way to set up a trigger sort of thing, so when an npc_zombie is killed, the "ent_fire npc_headcrab setrelationship..." command is executed. Until then, you could always wait until the zombies are dead, then set up the relationship, and clean up the remaining headcrabs.
Idea #3: Use ent_setname to name the players on the opposite team in team deathmatch (you don't have to use unique names, you could just call them all combine if the are on the combine team, or rebel if they are on the rebel team), then spawn a few "npc_vortigaunt"s or "npc_turret_floor"s and set up a hate relationship between those NPCs and whatever you called the players. I'd consider binding the ent_setname command, so you can quickly name the other players, because it would be difficult to go into console and enter the command every time, since the players are usually moving. The commands would look something like this:
bind n "ent_setname combine"
..You'd name the players on the opposite team by placing them under your crosshair and hitting "n"
Spawn some npcs (I suggested vortigaunt and turret_floor because they don't move, they just attack whatever's near them, so they're ideal for holding up a certain area) using "npc_create npc_whatever"
ent_fire npc_whatever setrelationship "combine D_HT 99"
Well, I think that's about it for this tutorial. Pay attention to the version number, because I might change this tutorial as I learn new things and receive new input. I really hope that this helps everyone, and if you have any further questions/comments/ideas/anythings please post and I'll respond as soon as possible! I'd also like to thank the other post on this board that discussed the use of NPCs in single player, I wish I still had the link, it taught me a lot about NPCs, and allowed me to learn how to use them in DM as well as single player. Thanks!
--Jimbro