Manual:Zone Manual/The NPC Section/A more complex set of NPCs
Contents
A more complex set of NPCs
In the last sections you learned the NPC fields and how to make a basic NPC. In this section we use them, together with the DIL functions from DIL functions for NPCs, to make some more interesting NPCs for the dragon station. At the end there are three NPCs that are built differently: a teacher, a guild master and a banker.
All the examples on this page start with #include <macros.h> in the zone file; that one header brings in the constants and all the NPC templates (see NPC macros).
A magic-casting dragon
A dragon that you can fight without being toasted by its breath is a bit boring. The combat_mag function described in DIL functions for NPCs makes an NPC cast spells while it fights. A black dragon breathes acid, so we use the spell acid breath. Spell names are the ones a player types after cast; the full list is in vme/etc/spells.def.
Here is the black dragon with every field written out, and the combat magic added:
bldragon
title "a black dragon"
descr "A big ugly black dragon is clawing the ground here."
names {"big ugly black dragon", "ugly black dragon", "big black dragon",
"black dragon", "dragon"}
extra {}
"The black dragon's scales glitter like black granite that has been
polished by water for years. He has a long neck and huge bat-like
wings. His eyes watch you as you stand before him. One claw is tapping
slightly on the ground, as if the dragon is waiting for something."
extra {"eyes", "eye"}
"The dragon's eyes seem to follow you wherever you go in the room.
Nothing seems to escape the dragon's attention."
extra {"claws", "claw"}
"The claws are big, black and very deadly. The dragon has two sets of
four large claws and two sets of four smaller ones; the small ones are
the size of short swords, the large ones the size of long swords."
extra {"scales", "scale"}
"It's a scale! Haven't you ever seen a dragon before?"
extra {"bat wings", "wings"}
"The dragon sees you looking and flaps his wings, creating one heck of
a wind blast."
race RACE_DRAGON_BLACK
sex SEX_MALE
height 625
weight 1250
level 70
NATURAL_DEF(WPN_CLAW_LARGE, ARM_PLATE)
alignment -900
MSET_ABILITY(20,12,12,12,12,12,20,0)
MSET_WEAPON(10,10,10,5,30,5)
MSET_SPELL(0,0,0,0,0,0,0,0,0,0,30)
// Combat magic added
dilcopy combat_mag@function("acid breath", "", 25, 2);
end
The abilities add up to 100, and the weapon and spell groups together add up to 100 (70 + 30), as vmc requires.
You don't have to write all of that yourself. macros.h has a template for black dragons of each size: M_DRAGON_BLACK_TINY, _SMALL, _MEDIUM, _LARGE, _XLARGE and _GODLY, each taking the level and the sex. The comments in vme/include/fantasy.h give the levels each size is meant for; level 70 is a medium dragon. With the template the dragon is:
bldragon
title "a black dragon"
descr "A big ugly black dragon is clawing the ground here."
names {"big ugly black dragon", "ugly black dragon", "big black dragon",
"black dragon", "dragon"}
extra {}
"The black dragon's scales glitter like black granite that has been
polished by water for years. He has a long neck and huge bat-like
wings. His eyes watch you as you stand before him. One claw is tapping
slightly on the ground, as if the dragon is waiting for something."
extra {"eyes", "eye"}
"The dragon's eyes seem to follow you wherever you go in the room.
Nothing seems to escape the dragon's attention."
extra {"claws", "claw"}
"The claws are big, black and very deadly. The dragon has two sets of
four large claws and two sets of four smaller ones; the small ones are
the size of short swords, the large ones the size of long swords."
extra {"scales", "scale"}
"It's a scale! Haven't you ever seen a dragon before?"
extra {"bat wings", "wings"}
"The dragon sees you looking and flaps his wings, creating one heck of
a wind blast."
M_DRAGON_BLACK_MEDIUM(70, SEX_MALE)
end
The template doesn't give exactly the same dragon: it sets its own abilities, height, weight (both grow with the level) and alignment (-750). It also does more: it adds combat_mag with acid breath, makes the dragon aggressive with aggressive@function, lets it see invisible and stops players from backstabbing it. Grep BASE_DRAGON in vme/include/fantasy.h to see everything it sets. Fields you write after the template override what it set.
A wandering janitor
A space station needs a janitor. Dragons are too proud for the job, so we give it to a hobgoblin. Written out, he looks like this:
janitor
names {"ugly janitor", "janitor", "hobgoblin"}
title "an ugly janitor"
descr "An ugly janitor is walking around, cleaning up."
extra {}
"This ugly green thing looks more goblin than hobgoblin, but he seems
intent on cleaning everything around him."
race RACE_HOBGOBLIN
level 6
sex SEX_MALE
height 130 // cm
weight 120 // pounds
// he is sort of good for cleaning so much
alignment 900
NATURAL_DEF(WPN_FIST, ARM_LEATHER)
MSET_ABILITY(10,10,10,23,15,22,10,0)
MSET_WEAPON(10,10,10,10,10,10) // average in everything
MSET_SPELL(4,2,2,2,2,2,2,6,6,6,6) // resistances
// give him some money
money 5 IRON_PIECE
dilcopy janitors@midgaard(15);
// he only cleans the station, and doesn't unlock doors
dilcopy wander_zones@function("dragonst", 20, 1, 0);
end
Two DIL functions work together here. janitors@midgaard makes him pick up and bury what lies around, every 15 seconds; it lives in midgaard.zon, not in function.zon. It doesn't move him, so wander_zones@function walks him around the zone dragonst every 20 seconds, opening closed doors (the 1) but not locked ones (the 0), so that he doesn't open the secret door in the office.
With the hobgoblin template from macros.h the same janitor is shorter:
janitor
names {"ugly janitor", "janitor", "hobgoblin"}
title "an ugly janitor"
descr "An ugly janitor is walking around, cleaning up."
extra {}
"This ugly green thing looks more goblin than hobgoblin, but he seems
intent on cleaning everything around him."
M_AVG_HOBGOBLIN(6, SEX_MALE)
// he is sort of good for cleaning so much
alignment 900
// give him some money
money 5 IRON_PIECE
dilcopy janitors@midgaard(15);
// he only cleans the station, and doesn't unlock doors
dilcopy wander_zones@function("dragonst", 20, 1, 0);
end
M_AVG_HOBGOBLIN sets the race, level, sex, a height and weight that grow with the level, the natural attack and armour, and the ability, weapon and spell sets.
Special functions
Nearly everything an NPC does is DIL. A few things are still built into the server and are put on an NPC with the special field instead of dilcopy: teachers, bankers and some older functions. The field is:
special <SFUN_ constant> ["<data>"]
The constants are in vme/include/vme.h. The ones a zone builder uses are SFUN_TEACH_INIT and SFUN_BANK. The others there are internal, or no longer do anything: SFUN_GUILD_BASIS, SFUN_GUILD_MASTER, SFUN_GUILD_TITLES, SFUN_MEMBERS_ONLY and SFUN_GUILD_GUARD_WAY still compile, but when one is first triggered the server logs "Unit ... had undefined special routine." and removes it. Guild masters are DIL now (see below).
Creating a teacher
A teacher is an NPC with special SFUN_TEACH_INIT and a string that says what it teaches. Players use info to see what it offers and practice to train. One teacher teaches one kind of thing: abilities, spells, skills or weapons. The public zones have many teachers to copy from; the guild teachers are in vme/include/guilddef.h.
The string has three parts, each field ending with a semicolon (;). Spaces and line breaks around a field don't matter.
1. The header: three fields.
abilities;fighter;Udgaard Fighter;
- What it teaches:
abilities,spells,skillsorweapons. - A profession, or nothing. With a profession (the names are in
vme/etc/professions.def:fighter,knight,paladin,ranger,thief,assassin,priest,druid,necromancer,mage,sorcerer,barbarian...) the teacher teaches everything that profession can learn, with maximums and prices worked out from the profession, and the lines you add change that list. Empty, the teacher teaches only your lines. - A guild name, or nothing. With a guild, the level column below is the player's level in that guild, so a player who isn't a member can practise only level-0 entries. Empty, it is the player's own level.
2. Seven messages, in this order, each ending with ;. In them, $1n is the teacher (see act()).
- The player asked for something that doesn't exist.
- The player asked for something this teacher doesn't teach.
- The player can't pay.
%sbecomes the price. - The player hasn't got enough practice points.
%dbecomes the number of points. - The player has reached this teacher's maximum.
- The player is under a spell that changes abilities or skills (bless, curse, berserk...) or wears an item that raises them.
- No longer shown, but it must be there.
3. One line per thing taught, with these fields:
0; 90; consider ; 4; 4000; 5; 10; 0;
- The guild level (or player level, see the header) needed to practise it, 0 to 250.
- The highest percentage the teacher trains it to, 1 to 150. A player can't go past their own limit, which depends on race and profession, whatever the teacher allows.
- The name, as in
vme/etc/abilities.def,spells.deforweapons.def; skills are incommands.def. Upper or lower case doesn't matter. A category, such as a group of spells, is added by itself when you list something in it. - The price of one practice at 0%, in money units (see the table below). Must be more than 0.
- The price at the teacher's maximum; the price rises evenly in between. Must be more than the previous field. Players up to level 25 practise for free.
- One or more practice point costs. These are no longer used: the points it costs come from the player's profession and race. Old teachers have one or two numbers here; one is enough.
0, which ends the line.
The spaces in the line above only make the columns line up; 0;90;consider;4;4000;5;10;0; is the same.
The prices are in the server's money unit. The constants in vme/include/vme.h give each coin's worth:
| Units | Coin | Constant |
|---|---|---|
| 10 | 1 iron piece | IRON_MULT
|
| 80 | 1 copper piece | COPPER_MULT
|
| 640 | 1 silver piece | SILVER_MULT
|
| 5120 | 1 gold piece | GOLD_MULT
|
| 40960 | 1 platinum piece | PLATINUM_MULT
|
Here is a complete ability teacher for the Udgaard Fighters' guild. TrainMemberChk@guilds stops players who aren't members of the guild from practising; its second argument is a command for the teacher to do when it refuses, and "" gives the default ("say You're not a member of our guild, go speak with the guild master.").
jones
names {"blacksmith", "smith", "Jones"}
title "Jones the blacksmith"
descr "The venerable Jones Blacksmith is here."
extra {}
"The smith is old but his arms still retain the strength of his youth.
He looks as if he has retired, but he can still put you through the
drills of physical training."
flags {UNIT_FL_NO_TELEPORT}
romflags {CHAR_PROTECTED}
M_HUMAN_WARRIOR_AXE(80, SEX_MALE)
// negative exp to discourage killing the teacher
exp -100
// only members of the guild may practise here
dilcopy TrainMemberChk@guilds("Udgaard Fighter", "");
special SFUN_TEACH_INIT
"abilities;;Udgaard Fighter;
$1n tells you, 'I have never heard of such an ability.';
$1n tells you, 'I do not know how to teach this ability.';
$1n tells you, 'You haven't got %s for me.';
$1n tells you, 'You haven't got %d ability points.';
$1n tells you, 'I can not teach you any more.';
$1n tells you, 'You must be unaffected by magic, otherwise I can't teach you.';
$1n tells you, 'Remove all equipment, please.';
0; 100; Strength ; 4; 4000; 8; 0;
0; 90; Dexterity ; 14; 14000; 12; 0;
0; 90; Constitution ; 14; 14000; 9; 0;
0; 100; Hitpoints ; 4; 4000; 11; 0;
2; 60; Brain ; 23; 23000; 14; 0;
4; 80; Charisma ; 18; 18000; 14; 0;
"
end
vmc doesn't read the teacher string. A mistake in it (an unknown name, a maximum price below the minimum) is logged in vme.log and in the zone's .err file when the teacher starts up after boot, and that line is skipped.
To let only players who finished a quest practise, use teach_q_block@function instead of TrainMemberChk (see DIL functions for NPCs).
Guild masters
A guild master lets players join the guild, leave it and get guild titles. This used to be the specials SFUN_GUILD_BASIS, SFUN_GUILD_MASTER and SFUN_GUILD_TITLES; they are gone, and the DIL functions in guilds.zon replace them:
MasterJoin@guilds:joinmakes the player a member, andinsult <master>makes a member leave. Its arguments are the guild name, a string list of guilds whose members may not join, the quest the player must have finished first (the master checks for "<quest> Complete"), and five lists of commands the master does: when the player is banished from the guild, is already a member, is in an excluded guild, hasn't done the quest, and when they join. In those commands$1Nis the player.SetTitles@guilds:titlegives the player a title for their guild level. The list holds a male and a female title for every five guild levels, the first pair from level 5; the player becomes "the <race> <title>".MurderBanish@guilds: every player fighting the master when he dies is banished from the guild.
The guild names, such as GUILD_UDG_FIGHTER ("Udgaard Fighter"), and the lists of excluded guilds, such as GUILD_UDG_FIGHTER_EXCL, are macros in vme/include/values.h. Here is a master for the Fighters' guild:
arthur
names {"guild master", "master", "sir arthur", "arthur"}
title "Sir Arthur"
descr "Sir Arthur the guild master is standing here."
extra {}
"A seasoned fighter, now placed in charge of the Fighters' Guild."
flags {UNIT_FL_NO_TELEPORT}
romflags {CHAR_PROTECTED}
M_HUMAN_WARRIOR_AXE(90, SEX_MALE)
exp -100
alignment 1000
// anyone who helps kill him is banished from the guild
dilcopy MurderBanish@guilds(GUILD_UDG_FIGHTER);
// 'title': male and female title for every 5 guild levels
dilcopy SetTitles@guilds(GUILD_UDG_FIGHTER, {"Swordpupil", "Swordpupil",
"Recruit", "Recruit", "Sentry", "Sentress", "Fighter", "Fighter",
"Soldier", "Soldier", "Warrior", "Warrior", "Veteran", "Veteran",
"Swordsman", "Swordswoman", "Fencer", "Fenceress", "Combatant",
"Combatess", "Hero", "Heroine", "Myrmidon", "Myrmidon", "Swashbuckler",
"Swashbuckleress", "Mercenary", "Mercenaress", "Swordmaster",
"Swordmistress", "Lieutenant", "Lieutenant", "Champion",
"Lady Champion", "Dragoon", "Lady Dragoon", "Cavalier", "Cavalier",
"Knight", "Lady Knight"});
// 'join' and 'insult'
dilcopy MasterJoin@guilds(GUILD_UDG_FIGHTER, GUILD_UDG_FIGHTER_EXCL,
"Fighters Guild Entry",
{"say You have been banned from our guild, you can't rejoin."},
{"say You're already a member of our guild, $1N."},
{"say Your other guilds prevent you from joining ours, $1N."},
{"say To join, $1N, you must first complete the Fighters' Guild quest."},
{"handshake $1N", "say Welcome to the Fighters' Guild, $1N."});
end
A guild is more than its master: its name and exclusions in values.h, its training defaults in guilds.zon, a joining quest, teachers. The Fighters' guild in vme/zone/fightersguild.zon is a complete example. The players' side is in Help: Guilds.
An NPC banker
The banker is the easiest special. special SFUN_BANK on an NPC makes it a banker: players in its room can use balance, deposit, withdraw and exchange (see Help: Bank). It needs no data. A complete banker:
bob
names {"Bob", "banker"}
title "Bob"
descr "Bob the Banker is here, sitting behind the counter."
extra {}
"He has a very serious look on his face."
M_SHOP_KEEPER(4, SEX_MALE, RACE_HUMAN)
// discourage people from killing the banker
exp -500
flags {UNIT_FL_NO_TELEPORT}
special SFUN_BANK
end
The banker only serves players he can see, and only while he is awake and not fighting.