Making AI Run, Hide, and Chase Intelligently

L

Liksus2x

Guest
Hey all, I'm very new to the mod community and have a question about the AI.

What I want to happen is that there is a certain npc that is armed. Let's call him badguy.

The player and a bunch of other npc are unarmed and have to run and hide from badguy or else they get shot and die.

I made a custom indoors map and am now running into some problems.

First of all, I know I need to set ai_relationships for everyone appropriately to fear and hate.

How do I get the unarmed npcs to run away smoothly from badguy? And how do I make the badguy chase and look for the other npcs, including the player?

I put a few info_nodes around doorways and down halls, and info_hint_nodes about narrow doorways, but it seems the npcs only jerkily run away and rather stupidly.

Do I have to script every npc's actions or is there a way to let it think for itself where it should run to?
Also, how do I pick and choose attributes for the badguy? For example, I want it to have the combine_s class's continuous advance but keep the model and sound files from an npc_civilian type downtrodden AND only carry a certain weapon (pistol).

Thanks in advance.
 
It's been a while since I messed with this but I think i remember some.

The HL2 AI is indeed clever although sometimes it feels as though it is almost to clever and therefore does not do what it is told, because it makes desicions of it's own. So expect to spend a LOT of time tuning this.

But here are some pointers on how to get it to work properly, or close anyway :)

ai_relationship is used to set relationships between AI objects. This can be used for entire classes, such as npc_citizen, or only specific names. in your case I would set this up so that badguy hates all npc_citizens. Have the relationship start active and be mirrored. The value of hate is irrelevant as of now, since this only decides which enemy an npc would attack first. This will cause all npc_citizens to hate badguy. And badguy to hate pretty much everyone. (As a matter of fact badguy will also hate himself, but luckily the AI has no emo-code so he will not shoot himself.)

Another relationship will be needed to make badguy hate player. Just have that one target "player". Hammer will report it as an error, although it will work ingame.

NOTE! Even though badguy hates you Gordon is coded not to harm npc_citizens and this cant really be overriden in a good looking way (it can be faked - badly). This means that even if you get hold of some weapons then badguy will still be your nemesis- you can't hurt him!

info_node and info_node_air and all the info_node_whatever are used to tell the AI where it can walk. Nothing else. This means that while you have a nodemesh the AI has no desires. Once badguy sees someone he will attempt to kill them and they will move since they DO have a desire not to get shot. badguy however has no desire to follow.

So, how do we create those? Werrl, there is several ways, all allowing various stages of reality. The simplest for is to use an ai_scriptedschedule (i think thats the name). A schedule needs a target npc (to give orders to) and a target point (to order the npc to move to). The target should preferrably be a info_target although it can be other things also.

The scedule is then started with a StartSchedule input wich forces the npc to start running. An interuptability can be given also. Default interruptability is "General" which more or less means that if npc is shot or used by player then it snaps out of the schedule. A schedule can be invoked several times.

This might not sound like much but I forced HL2 to run in thirdperson where you controlled npcs once, and this was what everything revolved around.

However, npc's wont be clever even now. They will just run.

An other option (which i reccomend for badguy) is the assault. It is mainly used for combine soldiers but works fine everywhere. it consists of several entities such as ai_assaultpoint and ai_goal_rally and can be complex. However there is a prefab which spawns 4 soldiers doing exactly this, that comes with the sdk! Look at that one to learn, and possibly alter it to include only one npc_citizen... Then just add more assault points and your npc will follow them! If you connect them in an loop then the npc will assault forever or until dead. Npc will stop at each point to make sure that the area is clear, so dont expect a fast rush. As I said it is meant for a combine tactical attack, where several slodiers work in pairs and toss grenades and stuff...

for your other npcs though i recommend an ai_battle_line. This entity (shown as a pigeon in hammer :S) creates a line which all affected npcs will attempt to push to. This is usually the entitiy that produces the most "intelligent" battles since npc's now take cover a lot and work in teams to move forward to a given point. Their efficiency can be set here too, which gives you the option to decide whether they should push slowly (safety first) or fast (Oshitwearegoingtodiesokillthesebastardsandrunforyourlives).
It also offers the sligthly difficult flag "player battleline" (or something"). This means that the player is the battle line. So if you push they try to follow, if you retreat they sometimes retreat or sometimes just stay plain confused. Note that efficiency is still of the essence. Even if you run in like mad then npcs will move slowly and take cover a lot if efficiency is low.

There si more to AI but this should get you started :)

Happy mapping!

//Unarmed
 
Back
Top