How to Add StopSchedule

Aiscripted_schedule is a useful entity in Half-Life 2 mapping for instructing NPCs to walk or run to a point.  Although scripted_schedules are more foolproof, given that they can constantly remind the NPC of their task if they should get stuck, aiscripted_schedule works in most cases.  You simply give the schedule a path or entity to go to, how you want the NPC to do it and send a StartSchedule input when you want it to happen.

But what if we need to abort the script?  Sure, you can adjust the Interruptability setting, but maybe you have your own criteria.  Perhaps the player moved elsewhere and you need the NPC to break out of their scripting immediately.

You look at the various inputs aiscripted_schedule takes and realize there’s nothing for StopSchedule.  “That’s weird,” you say to yourself, “it seems like an obvious thing to have.”

The truth is: StopSchedule exists and it does work.  It’s just missing in the FGD file.  Let’s add it.

The FGD is a definition file, a profile of sorts.  When Hammer starts, it loads an FGD for a game which tells it all about the different entities.  Whenever you look at the Inputs for an object, you’re looking at a list from the FGD, not the game.

Let’s open halflife2.fgd in a text editor like Notepad.  You can find it in Steam/steamapps/common/Half-Life 2/bin, the same place as Hammer.exe.  Do a search for “StartSchedule.”  This should take you to the Inputs section of aiscripted_schedule.  Right under this, and before the ] bracket, add an entry for StopSchedule in the same style as StartSchedule above it, such as:

input StopSchedule(void) : “Stop the scripted schedule. This will first locate an NPC that ” +
“matches the given target, then tell the NPC to stop the specified schedule.”

Save this file and re-open Hammer.  Now, when you try to do I/O on an aiscripted_schedule, you will have StopSchedule as an option.  Again, because Hammer isn’t getting these commands from the game itself, you don’t need to do anything else.  The game already knows what StopSchedule does (you can find it in the Valve Github).  All we did was make it so Hammer thinks it is a valid command.

I’ve tested this with an npc_hunter and it does appear to work without issues.  It’s possible that your mileage may vary, but I haven’t seen any complaints in-game about using it (such as in the console) and the NPC does abort its scripting and resume its normal behaviors as you would expect.  There could be a reason why it was omitted from the FGD, or it could have been an oversight.  Either way, have fun messing around with it.  It’s quite useful.