How do I make a battle start when you bump into an NPC?

Jump to navigation Jump to search

Creating an NPC which starts a battle when you bump into it is nearly the same as the procedure described in How do I make a battle start after talking to an NPC?

For every enemy on the map create an NPC with Activation: Touch and Usable only once so that it will disappear permanently after the battle. If you were to place this enemy multiple times on the map then all the copies would disappear after running into any of them, so you'll instead need multiple identical NPCs with different IDs.


Old games like Monterey Penguin didn't have plotscripting available, so instead used textboxes to trigger battles. Each type of enemy would have a textbox containing something like "The killer banana lunges at you." with the correct battle formation in the conditions, and this textbox linked from the NPC (with Display Text).


To skip the textbox, you need a script. You can either write one script per enemy type with the formation number hardwired (not recommended):

plotscript, killer banana, begin
  fight formation (15)

And set Run script: killer banana on the NPC. Notice that 'fight formation' takes a formation number, not a formation set number.

...or write a generic script that triggers a formation supplied as script argument:

plotscript, formation, formation, begin
  fight formation (formation)

A script linked to an NPC receives two arguments when run (which happens when the NPC is triggered): the first is the Script Argument and the second is the NPC reference number. So you would set Run script: formation on the NPC and set Script Argument: 15.

Deleting the NPC after the battle[edit]

Further, if you want the NPC to disappear after being defeated you can use the following script. (fightformation returns true if the player won the battle, rather than losing, running, or the battle being ended by an 'escape' attack.)

plotscript, formation, formation, npcref, begin
  if (fight formation (formation)) then (
    delete npc(npcref)

Note that unlike setting a "one time usable" tag on an NPC (which will cause all copies of the NPC on the map to disappear), the effect of deletenpc is temporary. The NPC will be recreated when the map is reloaded. You can choose to save NPC data in the map settings menu, which prevents the NPCs from being reloaded when you leave and reenter the map, but maps always reload when you load a saved game (maps aren't stored in saved games).

Formation Sets[edit]

Alternatively instead of specific formations, you can also use formation sets just like a foemap, so that a random formation is chosen:

plotscript, formation set, dummy, formation set, begin
  fight formation (random formation (formation set))

See Also[edit]