5. Creating NPCs

UNDER CONSTRUCTION

5.1. Modules

The LIMA mudlib consists of more than 60 modules located in /std/modules. These modules all got shorthand names found in /include/mudlib.h like many other things. The modules try to be independent and modular, but some still depend on others.

Ideally, the modules provides functionality that you can add to your code as needed. Need another feature? Inherit another module. Here is the top most lines from ^std/monster/robert.c:

inherit LIVING;
inherit M_NPCSCRIPT;
inherit M_TRIGGERS;
inherit M_SMARTMOVE;

As you can see “Bob” inherits LIVING (a non combat monster), but also M_NPCSCRIPT that gives Bob ability to use NPC scripts (more on those later). If you open the M_NPCSCRIPT file you will see:

...
inherit M_ACTIONS;

So M_NPCSCRIPT requires M_ACTIONS, a module that is requires for NPCs to take actions in the world (get, give, speak, etc.), but M_NPCSCRIPT can also do triggers, meaning wait for events in the MUD and act upon them. This only works if M_TRIGGERS is also inherited. Finally, M_SMARTMOVE provides the ability for Bob to move.

All these abilities could be inherited always into M_NPCSCRIPT, but this way gives you, as a programmer, the option to extend the capabilities of Bob as you see fit, or reduce them to less. In general, we do not want out MUD objects to inherit more things than what is needed - it is all about keeping the memory and CPU usage down to what is needed - the reverse is sometimes referred to as “bloat”, “bloated code”, or “bloated objects”.

A short list of modules typically used for monsters is shown here:

  • m_accountant - for NPCs running bank departments

  • m_actions - for NPCs that need to be able to take actions

  • m_aggressive - for NPCs that should attack on sight

  • m_assistance - for NPCs that call for assistance

  • m_blockexits - for NPCs that should block exits

  • m_boss - for boss monsters

  • m_companion - for companions monsters that can be trained by the players and follow them around

  • m_conversation - for interactive menus that allow players to talk to the NPCs in a RPG style chat, where one option can add or remove new options and give quests based on stats and skills.

  • m_follow - for monsters that should follow if the player leaves.

  • m_npcscript - for scripting sequences of steps for NPCs

  • m_smartmove - for monsters that should be able to move

  • m_trainer - for NPCs that should be able to train skills or stats

  • m_vendor - for NPCs that sell and buy stuff (shopkeepers, e.g.)

  • m_wander - for monsters that should wander around randomly

5.2. Banking NPCs

 1 /* Do not remove the headers from this file! see /USAGE for more info. */
 2
 3inherit ADVERSARY;
 4inherit M_ACCOUNTANT;
 5
 6void setup()
 7{
 8   set_name("Samuel");
 9   add_id("accountant", "sam");
10   set_gender(1);
11   set_proper_name("Samuel the Bank Accountant");
12   set_in_room_desc("Samuel the Bank Accountant stands behind the counter.");
13   set_long("Samuel is a boring looking balding man. Perfectly clothed of "
14            "course.");
15   set_bank_id("Bean");
16   set_bank_name("The Imperial Bank of the Bean");
17   set_currency_type("gold");
18   set_exchange_fee(5);
19}