Difference between revisions of "Manual:Zone Manual/The NPC Section/NPC macros"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the current code (wiki review 2026-11-15))
 
Line 1: Line 1:
−
=== NPC macros ===
+
== NPC macros ==
−
==== The attack and armour macro ====
 
  
−
The natural attack and armour fields allow you to set the NPC to
+
Several NPC fields are hard to set by hand: the abilities and skills must add up
−
do damage like a certain type of weapons and to defend like a certain
+
to 100, and the natural attack and armour belong together. The macros on this
−
type of armour respectively. Lets say you had a metal cougar it would
+
page set them in one line. They, and the monster templates built from them, come
−
have an attack type of claw and an armour type of plate while a normal
+
with <code>#include &lt;macros.h&gt;</code>, which every zone starts with; you don't
−
dog would have an armour type of leather and an attack type of bite.
+
include anything else. The macros are in <code>vme/include/wmacros.h</code> and
−
The 'NATURAL_DEF' macro is what allows you to set these fields. This
+
<code>bottom.h</code>, the templates in the other headers listed
−
macro is defined in ''wmacros.h'' and looks like
+
[[#Monster templates|below]]. If you want to see what a macro turns into, run
−
this.
+
<code>vmc -p</code> on your zone: it prints the zone after the preprocessor.
−
<nowiki>
+
 
−
#define NATURAL_DEF(weapon_category, armour_category) \
+
Macros overwrite fields set before them, so put a template or macro first and
−
  armour armour_category \
+
the fields you want to change after it.
−
  attack weapon_category</nowiki>
+
 
−
The word natural can sometimes be a little confusing since you can
+
=== Natural attack and armour: NATURAL_DEF ===
−
set any of the weapons types you like on the NPC.  It doesn't exactly
+
 
−
make sense to have a dog that attacks as if it uses a long sword but if
+
The natural attack is how the NPC hits when it has no weapon; the natural armour
−
you wish it you can do it.  The following is a short list of just the
+
is how well its body protects it when it wears no armour. A metal cat claws and
−
natural weapon types but you can find a full list in
+
is as hard as plate; a dog bites and has a leather-like hide. From
−
(Link to app-d) or in the ''values.h'' of your mud
+
<code>wmacros.h</code>:
−
just in case you have added some weapon types.
+
<pre>
−
<nowiki>
+
#define NATURAL_DEF(weapon_category, armour_category) \
−
#define WPN_FIST         34
+
  armour armour_category \
−
#define WPN_KICK         35
+
  attack weapon_category
−
#define WPN_BITE        36
+
</pre>
−
#define WPN_STING        37
+
 
−
#define WPN_CLAW         38
+
The natural attacks are in <code>values.h</code>. Humanoids have
−
#define WPN_CRUSH        39</nowiki>
+
<code>WPN_FIST</code> (the default), <code>WPN_KICK</code>,
−
Again you don't have to use leather for dogs as we have already
+
<code>WPN_KNEE</code>, <code>WPN_ELBOW</code> and <code>WPN_CLAW</code>.
−
mentioned with our metal cat idea you could make a cloth dragon if you
+
Creatures have bites, stings, claws, crushes and kicks in five sizes; a larger
−
really want but its up to you to keep some sanity on your VME.  The
+
size hits harder (the damage tables are in <code>vme/etc/weapons.def</code>):
−
following is the list of armour types that can be set. You will see
+
<pre>
−
that the list is exactly the same as the list you will find later when
+
WPN_BITE_TINY  WPN_BITE_SMALL  WPN_BITE_MEDIUM  WPN_BITE_LARGE  WPN_BITE_HUGE
−
making armour.
+
WPN_STING_TINY WPN_STING_SMALL  WPN_STING_MEDIUM WPN_STING_LARGE WPN_STING_HUGE
−
  <nowiki>
+
WPN_CLAW_TINY  WPN_CLAW_SMALL  WPN_CLAW_MEDIUM  WPN_CLAW_LARGE  WPN_CLAW_HUGE
−
#define ARM_CLOTHES 0 /*Same as a Human in jeans and a T-shirt*/
+
WPN_CRUSH_TINY WPN_CRUSH_SMALL WPN_CRUSH_MEDIUM
−
#define ARM_LEATHER 1 /* A soft flexible leather base armour   */
+
WPN_KICK_TINY  WPN_KICK_SMALL  WPN_KICK_MEDIUM  WPN_KICK_LARGE   WPN_KICK_HUGE
−
#define ARM_HLEATHER 2  /* A hard un flexible leather base armour */
+
</pre>
−
#define ARM_CHAIN    3  /* A flexible armour composed of interlocking rings */
+
<code>WPN_BITE</code>, <code>WPN_STING</code> and <code>WPN_CRUSH</code> are the
−
#define ARM_PLATE    4  /* An un flexible plate armour. */</nowiki>
+
medium sizes; <code>WPN_CLAW</code> and <code>WPN_KICK</code> are the small ones
−
Now that you have the defines to work with we will return to our
+
(and the humanoid claw and kick).
−
metal cat and normal dog. The definitions for them would look something
+
 
−
like this.
+
Use these natural attacks only. <code>vmc</code> accepts an attack type only if
−
<nowiki>
+
its number is from <code>WPN_FIST</code> (34) to 124, and stops with "Illegal
−
//Metal Cat
+
hand attack type" otherwise. That rejects most weapon types (a long sword is 17)
−
NATURAL_DEF(WPN_CLAW, ARM_PLATE)
+
and also <code>WPN_CRUSH_LARGE</code> and <code>WPN_CRUSH_HUGE</code> (125 and
 +
126). The numbers are in
 +
[[Manual:Zone Manual/Appendices/weapon definitions in values.h|weapon definitions in values.h]].
 +
 
 +
The NPC's weight also counts. A natural attack does less damage the lighter the
 +
attacker is; the hit is scaled before it is looked up in the damage table:
  
−
//normal dog
 
−
NATURAL_DEF(WPN_BITE, ARM_LEATHER)</nowiki>
 
−
You  should  know  that the weight of the monster  determines  the
 
−
maximum  amount of damage it can give when using a natural attack.
 
−
The weight is categorized as follows:
 
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Weight size chart
+
|+Weight and natural attacks
 
|-
 
|-
−
!LBS
+
!Weight (pounds)
 
!Size
 
!Size
 +
!Hit counts for
 
|-
 
|-
−
|0 - 5
+
|0–5
−
|Tiny
+
|tiny
 +
|50%
 
|-
 
|-
−
|6 - 40
+
|6–40
−
|Small
+
|small
 +
|60%
 
|-
 
|-
−
|41 - 160
+
|41–160
−
|Medium
+
|medium
 +
|70%
 
|-
 
|-
−
|161 - 500
+
|161–500
−
|Large
+
|large
 +
|80%
 
|-
 
|-
−
|500 and up
+
|over 500
−
|Huge
+
|huge
 +
|100%
 
|}
 
|}
−
By default monsters are medium.  So make sure you take this into
+
An NPC without <code>weight</code> weighs 120 pounds, so it is medium. A
−
account when you are creating your NPC.
+
dragon needs a dragon's weight to hit like one. The weight doesn't matter when
−
==== The defense and offense bonus macro ====
+
the NPC wields a weapon.
 +
 
 +
The armour types, from <code>vme.h</code>, are the same as for armour objects:
 +
<pre>
 +
#define ARM_CLOTHES  0 /* Naked / clothes is only protection    */
 +
#define ARM_LEATHER 1 /* A soft flexible leather base armour  */
 +
#define ARM_HLEATHER 2 /* A hard unflexible leather base armour */
 +
#define ARM_CHAIN    3 /* A flexible armour composed of interlocking rings */
 +
#define ARM_PLATE    4 /* An unflexible plate armour. */
 +
</pre>
 +
An NPC without <code>armour</code> has <code>ARM_HLEATHER</code>.
 +
<pre>
 +
// a metal cat
 +
NATURAL_DEF(WPN_CLAW_MEDIUM, ARM_PLATE)
  
−
There comes a time when you may want to make your NPC super
+
// an ordinary dog
−
naturally powerful.  It is for those times that the offense and defense
+
NATURAL_DEF(WPN_BITE_SMALL, ARM_LEATHER)
−
fields are available for you to set.  Normally they default to 0 but you
+
</pre>
−
can set them from 0 to 5000.  The higher you set the offense number the
 
−
harder you will hit people you a re in combat with.  The higher you set
 
−
the defense the harder it will be for people to hit your NPC.  The
 
−
following macro allows you to set both the offense and defense.
 
−
<nowiki>
 
−
#define ATTACK_DEFENSE(attack, defense) \
 
−
offensive attack \
 
−
defensive defense</nowiki>
 
−
Using this macro is rather easy you just put the value you want
 
−
for each and your all done
 
−
<nowiki>
 
−
//a really hard hitting hard to kill NPC
 
−
ATTACK_DEFENSE( 1000, 1000)</nowiki>
 
−
==== The NPc abilities macro ====
 
  
−
All  abilities are in the range [1..200]. Players usually  have  a
+
=== Offensive and defensive bonus: ATTACK_DEFENSE ===
−
maximum of 150, modified by magic... 200 is considered divine.
 
−
When  creating a monster you can not directly specify the size  of
 
−
the  abilities,  instead you specify a percentage distribution  of
 
−
points.  The amount of points are then distributed by the computer
 
−
according  to  the  specified level.  The  'MSET_ABILITY'  macro  is
 
−
available for this purpose, and is defined as:
 
−
<nowiki>
 
−
#define MSET_ABILITY(str,dex,con,hpp,bra,cha,mag,div)  \
 
−
ability[ABIL_STR]  str  \
 
−
  ability[ABIL_DEX]  dex  \
 
−
  ability[ABIL_CON]  con  \
 
−
  ability[ABIL_HP]  hpp  \
 
−
  ability[ABIL_BRA]  bra  \
 
−
  ability[ABIL_MAG]  mag  \
 
−
  ability[ABIL_DIV]  div  \
 
−
  ability[ABIL_CHA]  cha</nowiki>
 
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">
 
−
Note the sum of the ability values must be 100%. This is thus
 
−
an example of an ability distribution:
 
−
<nowiki>
 
−
    MSET_ABILITY(25,15,10,15,10,5,10,0)  /* Sum is 100% */</nowiki>
 
−
</blockquote>
 
  
−
The  amount of points distributed depends directly upon the  level
+
Sometimes an NPC should be stronger than its level and skills make it. The
−
of the monster and the percentage. If the percentage is too high and the
+
offensive bonus is added to its attack rolls, the defensive bonus to its
−
level is also set High some ability points may be lost since a NPC gets
+
defence rolls. Both default to 0 and may be -1000..1000; the higher the
−
all abilities over 255 cut off. For example a level 199 monster with an  ability
+
offensive bonus, the harder it hits, and the higher the defensive bonus, the
−
percentage  a  bit above 20% will make an ability  above  the 255
+
harder it is to hit. The dragon templates use +100 for both.
−
points maximum.  In the current combat system in the VME 2.0 it is not
+
<pre>
−
necessary to spend points on both 'mag' and 'div' on the NPC since only
+
#define ATTACK_DEFENSE(attack, defense) \
−
one or the other is ever used depending on which is higher.
+
  offensive attack \
−
==== The NPc weapon and spell macros ====
+
  defensive defense
 +
</pre>
 +
<pre>
 +
// hits hard and is hard to hit
 +
ATTACK_DEFENSE(200, 200)
 +
</pre>
  
−
NPCs know about weapons and spells but not at the same detailed
+
=== Abilities: MSET_ABILITY ===
−
level as the player.  For NPCs the spell and weapon group are used.
+
 
−
Thus the Axe hammer category defines all defence and all attack for all
+
You don't give an NPC's abilities as numbers. You give the share, in per cent,
−
kinds of axes and hammers, whereas the player would have to train
+
that each ability gets of the points an NPC of its level has, and
−
individually in each axe and hammer type. The same is true for spells.
+
<code>vmc</code> works out the numbers. The eight shares must add up to 100:
−
Thus if a monster has 25 points in the weapon sword category it will
+
<pre>
−
fight (and defend) with all sword-like weapons at skill 25. When you
+
#define MSET_ABILITY(str,dex,con,hpp,bra,cha,mag,div)  \
−
define weapon and spell skills (monsters have no skill skills) you also
+
    ability[ABIL_STR]  str  \
−
define these as percentages, and the program automatically distributes
+
    ability[ABIL_DEX] dex  \
−
the points. Use the pre-defined macros:
+
    ability[ABIL_CON]  con  \
−
<nowiki>
+
    ability[ABIL_HP]  hpp  \
−
#define MSET_WEAPON(axe_ham, sword, club_mace, pole, unarmed, special)  \
+
    ability[ABIL_BRA]  bra  \
−
weapon[WPN_AXE_HAM]    axe_ham  \
+
    ability[ABIL_MAG]  mag  \
−
weapon[WPN_SWORD]      sword      \
+
    ability[ABIL_DIV]  div  \
−
weapon[WPN_CLUB_MACE]  club_mace  \
+
    ability[ABIL_CHA]  cha
−
weapon[WPN_POLEARM]    pole \
+
</pre>
−
weapon[WPN_UNARMED]    unarmed    \
+
The arguments are strength, dexterity, constitution, hit points, brain,
−
weapon[WPN_SPECIAL]    special</nowiki>
+
charisma, magic and divine power, in that order. What each ability does is
 +
described in [[Manual:Game Mechanics/Abilities|Abilities]]. The HP ability gives
 +
the NPC its hit points: 10 + 3 for each point.
 +
<pre>
 +
MSET_ABILITY(25,15,10,15,10,5,20,0)  // 25+15+10+15+10+5+20+0 = 100
 +
</pre>
 +
An NPC without <code>MSET_ABILITY</code> gets STR 40, DEX 30, CON 10, HP 15,
 +
BRA 3, CHA 2.
 +
 
 +
The number of points grows with the level. <code>vmc -v</code> prints what each
 +
NPC got. For seven NPCs with the line above, named after their levels, it
 +
shows (the HIT column is the hit points):
 +
<pre>
 +
                      STR  DEX  CON  HIT  BRA  CHA  MAG  DIV
 +
 
 +
lvl1                    2    1    0  13    0    0    1    0
 +
lvl10                  17  12    9  46    9    4  15    0
 +
lvl25                  43  31  24  103  24  12  37    0
 +
lvl50                  85  61  48  193  48  24  73    0
 +
lvl100                170  122  96  376  96  48  146    0
 +
lvl150                255  183  144  559  144  72  219    0
 +
lvl199                338  243  191  739  191  95  291    0
 +
</pre>
 +
No ability or skill can be higher than 500. A share that would give more is cut
 +
to 500, and <code>vmc</code> warns. For the NPCs above it printed
 +
"lvl150 - A weapon skill exceeds 662 points." and the same for level 199: they
 +
have the default 100% in one weapon group. At high levels, spread the shares
 +
more evenly.
 +
 
 +
=== Weapon and spell skills: MSET_WEAPON and MSET_SPELL ===
 +
 
 +
NPCs know weapons and spells by group, not one by one as players do. An NPC with
 +
skill 25 in the sword group fights, and defends, with every sword-like weapon at
 +
skill 25. Spell groups work the same way: they are the NPC's skill when it
 +
casts a spell of that group, and its resistance when such a spell is cast at
 +
it. NPCs have no other skills. As with abilities, you give shares in per cent,
 +
and <code>vmc</code> works out the points from the level.
 +
 
 +
The weapon shares and the spell shares together must add up to 100. An NPC
 +
without these macros has 100 in the unarmed group and nothing else.
 +
<pre>
 +
#define MSET_WEAPON(axe_ham, sword, club_mace, pole, unarmed, special)  \
 +
    weapon[WPN_AXE_HAM]    axe_ham  \
 +
    weapon[WPN_SWORD]      sword      \
 +
    weapon[WPN_CLUB_MACE]  club_mace  \
 +
    weapon[WPN_POLEARM]    pole \
 +
    weapon[WPN_UNARMED]    unarmed    \
 +
    weapon[WPN_SPECIAL]    special
 +
</pre>
 
{| class="wikitable"
 
{| class="wikitable"
 
|+MSET_WEAPON arguments
 
|+MSET_WEAPON arguments
 
|-
 
|-
 
!Argument
 
!Argument
−
!Description
+
!Group
 
|-
 
|-
 
|axe_ham
 
|axe_ham
−
|any hammer or axe
+
|axes and hammers
 
|-
 
|-
 
|sword
 
|sword
−
|any sword like weapon, including dagger and rapier, etc.
+
|swords, daggers, rapiers and the like
 
|-
 
|-
 
|club_mace
 
|club_mace
−
|any club or mace like weapon, flails, morning star, etc.
+
|clubs, maces, flails, morning stars
 
|-
 
|-
−
|polearm
+
|pole
−
|any spear or pole like weapon:  spear, trident, sickle, scythe etc.
+
|quarterstaffs, spears, halberds, tridents, scythes and other pole weapons
 
|-
 
|-
 
|unarmed
 
|unarmed
−
|Is any bite, claw, sting or other natural attack.
+
|fists, kicks, bites, claws, stings, crushes: the natural attacks
 
|-
 
|-
 
|special
 
|special
−
|any very peculiar weapon, currently only whip.
+
|whips, bows, crossbows and slings
 
|}
 
|}
−
<nowiki>
+
<pre>
−
#define MSET_SPELL(div, pro, det, sum, cre, min, hea, col, cel, int, ext)  \
+
#define MSET_SPELL(div, pro, det, sum, cre, min, hea, col, cel, int, ext)  \
−
spell[SPL_DIVINE]      div  \
+
    spell[SPL_DIVINE]      div  \
−
spell[SPL_PROTECTION]  pro  \
+
    spell[SPL_PROTECTION]  pro  \
−
spell[SPL_DETECTION]  det  \
+
    spell[SPL_DETECTION]  det  \
−
spell[SPL_SUMMONING]  sum  \
+
    spell[SPL_SUMMONING]  sum  \
−
spell[SPL_CREATION]    cre  \
+
    spell[SPL_CREATION]    cre  \
−
spell[SPL_MIND]        min  \
+
    spell[SPL_MIND]        min  \
−
spell[SPL_HEAT]        hea  \
+
    spell[SPL_HEAT]        hea  \
−
spell[SPL_COLD]        col  \
+
    spell[SPL_COLD]        col  \
−
spell[SPL_CELL]        cel  \
+
    spell[SPL_CELL]        cel  \
−
spell[SPL_INTERNAL]    int  \
+
    spell[SPL_INTERNAL]    int  \
−
spell[SPL_EXTERNAL]    ext</nowiki>
+
    spell[SPL_EXTERNAL]    ext
 +
</pre>
 
{| class="wikitable"
 
{| class="wikitable"
 
|+MSET_SPELL arguments
 
|+MSET_SPELL arguments
 
|-
 
|-
 
!Argument
 
!Argument
−
!Description
+
!Group
 
|-
 
|-
 
|div
 
|div
−
|Covers all divine sphere spell.
+
|divine
 
|-
 
|-
 
|pro
 
|pro
−
|Covers all protection sphere spells.
+
|protection
 
|-
 
|-
 
|det
 
|det
−
|Covers all detection sphere spells.
+
|detection
 
|-
 
|-
 
|sum
 
|sum
−
|Covers all summoning spells.
+
|summoning
 
|-
 
|-
−
|Cre
+
|cre
−
|Covers all creation spells.
+
|creation
 
|-
 
|-
 
|min
 
|min
−
|Covers all mind spells.
+
|mind
 
|-
 
|-
 
|hea
 
|hea
−
|Covers all heat spells (fireball, etc.)
+
|heat (fire)
 
|-
 
|-
 
|col
 
|col
−
|Covers all cold spells (frostball, etc.)
+
|cold (frost)
 
|-
 
|-
 
|cel
 
|cel
−
|Covers all cell (electricity) spells (lightning bolt, etc.)
+
|cell (electricity)
 
|-
 
|-
 
|int
 
|int
−
|Covers all internal (poison) spells (toxicate, etc.)
+
|internal (poison)
 
|-
 
|-
 
|ext
 
|ext
−
|Covers all external (acid) spells (acid ball etc).
+
|external (acid)
 +
|}
 +
Which group a weapon or spell belongs to is its <code>sphere</code> in
 +
<code>vme/etc/weapons.def</code> and <code>vme/etc/spells.def</code>; see also
 +
[[Manual:Zone Manual/Appendices/Spell definitions in values.h|Spell definitions in values.h]].
 +
 
 +
A legal setting, 75% weapons and 25% spells:
 +
<pre>
 +
// 75% in all, club and mace first
 +
MSET_WEAPON(10,10,25,5,20,5)
 +
 
 +
// 25% in all, fire first
 +
MSET_SPELL(3,0,0,3,0,3,7,3,2,2,2)
 +
</pre>
 +
Remember that the groups are defence as well as attack. An orc with 0% in the
 +
club and mace group has no weapon skill to defend itself against a flail, and
 +
an NPC with 0% in the fire group has no resistance to fire spells.
 +
 
 +
=== Height and weight by level: SETHEIGHT and SETWEIGHT ===
 +
 
 +
The templates make a higher-level creature bigger. From <code>bottom.h</code>:
 +
<pre>
 +
#define SETHEIGHT(MLVL,minh,maxh) \
 +
height (((((maxh-minh)+1)*((MLVL*100)/199))/100)+minh)
 +
 
 +
#define SETWEIGHT(MLVL,minw,maxw) \
 +
weight (((((maxw-minw)+1)*((MLVL*100)/199))/100)+minw)
 +
</pre>
 +
At level 0 the NPC gets the minimum, at level 199 the maximum, and in between a
 +
share by level. Height is in centimetres, weight in pounds.
 +
<pre>
 +
SETHEIGHT(40, 150, 200)  // a level 40 humanoid of 150 to 200 cm: 160 cm
 +
</pre>
 +
 
 +
=== Monster templates ===
 +
 
 +
The template headers contain over two thousand ready-made NPCs. A template sets
 +
race, level, sex, size, natural attack and armour, abilities, weapon and spell
 +
skills, alignment and often experience and flags, and some add DIL programs
 +
(aggression, combat magic). You add the names and descriptions and whatever you
 +
want different.
 +
<pre>
 +
bldragon
 +
M_DRAGON_BLACK_MEDIUM(70, SEX_MALE)
 +
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"}
 +
alignment -900
 +
end
 +
</pre>
 +
Because macros overwrite the fields before them, the template comes first:
 +
<code>alignment -900</code> after it replaces the template's -750. Flags are
 +
the exception; a <code>romflags</code> or <code>flags</code> line adds to the
 +
template's. An <code>MSET_WEAPON</code> or <code>MSET_SPELL</code> after a
 +
template replaces only that group, so it must keep the template's split:
 +
<code>M_HUMAN_WARRIOR_SWORD</code> puts 85% in weapons and 15% in spells, so a
 +
new <code>MSET_WEAPON</code> after it must add up to 85.
 +
 
 +
{| class="wikitable"
 +
|-
 +
!Header
 +
!Templates
 +
|-
 +
|<code>mhumanoid.h</code>
 +
|People. <code>M_AVG_&lt;RACE&gt;(level, sex)</code>;
 +
<code>M_&lt;RACE&gt;_WARRIOR_&lt;AXE, SWORD, CLUB, POLE, NATURAL or SPECIAL&gt;(level, sex)</code>;
 +
<code>M_&lt;RACE&gt;_THIEF_&lt;weapon&gt;(level, sex)</code>;
 +
<code>M_&lt;RACE&gt;_MAGE_&lt;FIRE, FROST, ACID, ELECTRICITY, MIND or GAS&gt;(level, sex, "attack spell")</code>;
 +
<code>M_&lt;RACE&gt;_CLERIC_&lt;HAMMER, CLUB, STAFF or SWORD&gt;(level, sex, "attack spell", "defence spell")</code>;
 +
<code>M_SHOP_KEEPER(level, sex, race)</code>.
 +
|-
 +
|<code>chumanoid.h</code>
 +
|The same people as children: <code>C_AVG_&lt;RACE&gt;</code>, <code>C_&lt;RACE&gt;_WARRIOR_...</code> and so on.
 +
|-
 +
|<code>monster.h</code>
 +
|Animals: <code>M_BEAR_&lt;SIZE&gt;(level, sex)</code>, <code>M_RAT_&lt;SIZE&gt;</code>, ...
 +
|-
 +
|<code>fantasy.h</code>
 +
|Fantasy creatures: dragons, demons, undead, ...
 +
|-
 +
|<code>plant.h</code>
 +
|Plants.
 +
|-
 +
|<code>aquatic.h</code>
 +
|Sea creatures.
 
|}
 
|}
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">If your not sure what your weapon or spell is categorized as you can look in the ''weapons.def'' or the ''spells.def'' for that you are using for your VME server.</blockquote>
+
For creatures the size in the name goes with a range of levels (from the comment
−
The sum of all spell and weapon
+
in <code>macros.h</code>): <code>TINY</code> 1–25, <code>SMALL</code> 26–50,
−
skills must be 100%. For example, the following would be a legal
+
<code>MEDIUM</code> 51–75, <code>LARGE</code> 76–100, <code>XLARGE</code>
−
setting of weapons and spells.
+
101–125, <code>GODLY</code> 125–199. A <code>_MAD</code> template is aggressive
−
<nowiki>
+
and often poisonous.
−
// 75%  Total, Club/Mace  is primary
 
−
      MSET_WEAPON(10,10,20,5,15,5)
 
  
−
//  25%  Total, Fire  is primary
+
The arguments differ from template to template, so grep the header for the
−
      MSET_SPELL(8,0,0,3,0,3,2,3,3,3,3)</nowiki>
+
exact name before you use one; the comment at the top of <code>macros.h</code>
−
Remember that the groups define both attack and defence. Thus  if
+
explains the argument names. A few dozen templates that no zone uses don't
−
you  make  an Orc which has 0% in the flail group it can only  use
+
compile: the abilities of <code>M_KOBOLD_THIEF_*</code> and
−
its  dexterity to defend itself. Likewise with spell  groups.  For
+
<code>M_IVY_*</code> don't add up to 100, and <code>M_SPRITE_MEDIUM</code> has a
−
this  reason  the groups are both "resistance" as well  as  attack
+
syntax error, for example.
−
groups.
 
−
==== Using the composed.h ====
 
  
−
The  file composed.h contains many standard monsters. It is a good
+
If you make a general monster that others could use, write it as a template in
−
idea  to  study these definitions, as they form the basis of  many
+
the right header, built from the macros on this page, and offer it to the
−
different  monsters. Note that the definitions  by  no  means  are
+
project.
−
perfect,  but  we  are hoping to make a more  or  less  complete
 
−
monster compendium.  If  you create certain  (general)  monsters,
 
−
please design it as a macro so it can be incorporated in the
 
−
file. The more monsters created by using these macros the easier it will
 
−
be for your builders to create NPCs.  If you think you have a really
 
−
all inclusive Composed.h and want to share it with the rest of the VME
 
−
servers running out there on the internet.  Feel free to submit it to
 
−
the VME staff and we will put it in the contribution directories on our
 
−
release site.
 
  
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">For more information on how to use the composed.h when building your NPC see (Link to npcbasic).</blockquote>
+
For an NPC built from these macros step by step, see
 +
[[Manual:Zone Manual/The NPC Section/Building your first NPC|Building your first NPC]].
  
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section|Previous: The NPC Section]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section|Previous: The NPC Section]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section/Building_your_first_NPC|Next: Building your first NPC]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section/Building_your_first_NPC|Next: Building your first NPC]]</div>

Latest revision as of 06:20, 15 November 2026

NPC macros

Several NPC fields are hard to set by hand: the abilities and skills must add up to 100, and the natural attack and armour belong together. The macros on this page set them in one line. They, and the monster templates built from them, come with #include <macros.h>, which every zone starts with; you don't include anything else. The macros are in vme/include/wmacros.h and bottom.h, the templates in the other headers listed below. If you want to see what a macro turns into, run vmc -p on your zone: it prints the zone after the preprocessor.

Macros overwrite fields set before them, so put a template or macro first and the fields you want to change after it.

Natural attack and armour: NATURAL_DEF

The natural attack is how the NPC hits when it has no weapon; the natural armour is how well its body protects it when it wears no armour. A metal cat claws and is as hard as plate; a dog bites and has a leather-like hide. From wmacros.h:

#define NATURAL_DEF(weapon_category, armour_category) \
   armour armour_category \
   attack weapon_category

The natural attacks are in values.h. Humanoids have WPN_FIST (the default), WPN_KICK, WPN_KNEE, WPN_ELBOW and WPN_CLAW. Creatures have bites, stings, claws, crushes and kicks in five sizes; a larger size hits harder (the damage tables are in vme/etc/weapons.def):

WPN_BITE_TINY   WPN_BITE_SMALL   WPN_BITE_MEDIUM   WPN_BITE_LARGE   WPN_BITE_HUGE
WPN_STING_TINY  WPN_STING_SMALL  WPN_STING_MEDIUM  WPN_STING_LARGE  WPN_STING_HUGE
WPN_CLAW_TINY   WPN_CLAW_SMALL   WPN_CLAW_MEDIUM   WPN_CLAW_LARGE   WPN_CLAW_HUGE
WPN_CRUSH_TINY  WPN_CRUSH_SMALL  WPN_CRUSH_MEDIUM
WPN_KICK_TINY   WPN_KICK_SMALL   WPN_KICK_MEDIUM   WPN_KICK_LARGE   WPN_KICK_HUGE

WPN_BITE, WPN_STING and WPN_CRUSH are the medium sizes; WPN_CLAW and WPN_KICK are the small ones (and the humanoid claw and kick).

Use these natural attacks only. vmc accepts an attack type only if its number is from WPN_FIST (34) to 124, and stops with "Illegal hand attack type" otherwise. That rejects most weapon types (a long sword is 17) and also WPN_CRUSH_LARGE and WPN_CRUSH_HUGE (125 and 126). The numbers are in weapon definitions in values.h.

The NPC's weight also counts. A natural attack does less damage the lighter the attacker is; the hit is scaled before it is looked up in the damage table:

Weight and natural attacks
Weight (pounds) Size Hit counts for
0–5 tiny 50%
6–40 small 60%
41–160 medium 70%
161–500 large 80%
over 500 huge 100%

An NPC without weight weighs 120 pounds, so it is medium. A dragon needs a dragon's weight to hit like one. The weight doesn't matter when the NPC wields a weapon.

The armour types, from vme.h, are the same as for armour objects:

#define ARM_CLOTHES  0		/* Naked / clothes is only protection    */
#define ARM_LEATHER  1		/* A soft flexible leather base armour   */
#define ARM_HLEATHER 2		/* A hard unflexible leather base armour */
#define ARM_CHAIN    3		/* A flexible armour composed of interlocking rings */
#define ARM_PLATE    4		/* An unflexible plate armour. */

An NPC without armour has ARM_HLEATHER.

// a metal cat
NATURAL_DEF(WPN_CLAW_MEDIUM, ARM_PLATE)

// an ordinary dog
NATURAL_DEF(WPN_BITE_SMALL, ARM_LEATHER)

Offensive and defensive bonus: ATTACK_DEFENSE

Sometimes an NPC should be stronger than its level and skills make it. The offensive bonus is added to its attack rolls, the defensive bonus to its defence rolls. Both default to 0 and may be -1000..1000; the higher the offensive bonus, the harder it hits, and the higher the defensive bonus, the harder it is to hit. The dragon templates use +100 for both.

#define ATTACK_DEFENSE(attack, defense) \
   offensive attack \
   defensive defense
// hits hard and is hard to hit
ATTACK_DEFENSE(200, 200)

Abilities: MSET_ABILITY

You don't give an NPC's abilities as numbers. You give the share, in per cent, that each ability gets of the points an NPC of its level has, and vmc works out the numbers. The eight shares must add up to 100:

#define MSET_ABILITY(str,dex,con,hpp,bra,cha,mag,div)   \
    ability[ABIL_STR]  str   \
    ability[ABIL_DEX]  dex   \
    ability[ABIL_CON]  con   \
    ability[ABIL_HP]   hpp   \
    ability[ABIL_BRA]  bra   \
    ability[ABIL_MAG]  mag   \
    ability[ABIL_DIV]  div   \
    ability[ABIL_CHA]  cha

The arguments are strength, dexterity, constitution, hit points, brain, charisma, magic and divine power, in that order. What each ability does is described in Abilities. The HP ability gives the NPC its hit points: 10 + 3 for each point.

MSET_ABILITY(25,15,10,15,10,5,20,0)   // 25+15+10+15+10+5+20+0 = 100

An NPC without MSET_ABILITY gets STR 40, DEX 30, CON 10, HP 15, BRA 3, CHA 2.

The number of points grows with the level. vmc -v prints what each NPC got. For seven NPCs with the line above, named after their levels, it shows (the HIT column is the hit points):

                      STR  DEX  CON  HIT  BRA  CHA  MAG  DIV

lvl1                    2    1    0   13    0    0    1    0
lvl10                  17   12    9   46    9    4   15    0
lvl25                  43   31   24  103   24   12   37    0
lvl50                  85   61   48  193   48   24   73    0
lvl100                170  122   96  376   96   48  146    0
lvl150                255  183  144  559  144   72  219    0
lvl199                338  243  191  739  191   95  291    0

No ability or skill can be higher than 500. A share that would give more is cut to 500, and vmc warns. For the NPCs above it printed "lvl150 - A weapon skill exceeds 662 points." and the same for level 199: they have the default 100% in one weapon group. At high levels, spread the shares more evenly.

Weapon and spell skills: MSET_WEAPON and MSET_SPELL

NPCs know weapons and spells by group, not one by one as players do. An NPC with skill 25 in the sword group fights, and defends, with every sword-like weapon at skill 25. Spell groups work the same way: they are the NPC's skill when it casts a spell of that group, and its resistance when such a spell is cast at it. NPCs have no other skills. As with abilities, you give shares in per cent, and vmc works out the points from the level.

The weapon shares and the spell shares together must add up to 100. An NPC without these macros has 100 in the unarmed group and nothing else.

#define MSET_WEAPON(axe_ham, sword, club_mace, pole, unarmed, special)  \
    weapon[WPN_AXE_HAM]    axe_ham   \
    weapon[WPN_SWORD]      sword      \
    weapon[WPN_CLUB_MACE]  club_mace  \
    weapon[WPN_POLEARM]    pole \
    weapon[WPN_UNARMED]    unarmed    \
    weapon[WPN_SPECIAL]    special
MSET_WEAPON arguments
Argument Group
axe_ham axes and hammers
sword swords, daggers, rapiers and the like
club_mace clubs, maces, flails, morning stars
pole quarterstaffs, spears, halberds, tridents, scythes and other pole weapons
unarmed fists, kicks, bites, claws, stings, crushes: the natural attacks
special whips, bows, crossbows and slings
#define MSET_SPELL(div, pro, det, sum, cre, min, hea, col, cel, int, ext)  \
    spell[SPL_DIVINE]      div  \
    spell[SPL_PROTECTION]  pro  \
    spell[SPL_DETECTION]   det  \
    spell[SPL_SUMMONING]   sum  \
    spell[SPL_CREATION]    cre  \
    spell[SPL_MIND]        min  \
    spell[SPL_HEAT]        hea  \
    spell[SPL_COLD]        col  \
    spell[SPL_CELL]        cel  \
    spell[SPL_INTERNAL]    int  \
    spell[SPL_EXTERNAL]    ext
MSET_SPELL arguments
Argument Group
div divine
pro protection
det detection
sum summoning
cre creation
min mind
hea heat (fire)
col cold (frost)
cel cell (electricity)
int internal (poison)
ext external (acid)

Which group a weapon or spell belongs to is its sphere in vme/etc/weapons.def and vme/etc/spells.def; see also Spell definitions in values.h.

A legal setting, 75% weapons and 25% spells:

// 75% in all, club and mace first
MSET_WEAPON(10,10,25,5,20,5)

// 25% in all, fire first
MSET_SPELL(3,0,0,3,0,3,7,3,2,2,2)

Remember that the groups are defence as well as attack. An orc with 0% in the club and mace group has no weapon skill to defend itself against a flail, and an NPC with 0% in the fire group has no resistance to fire spells.

Height and weight by level: SETHEIGHT and SETWEIGHT

The templates make a higher-level creature bigger. From bottom.h:

#define SETHEIGHT(MLVL,minh,maxh) \
height (((((maxh-minh)+1)*((MLVL*100)/199))/100)+minh)

#define SETWEIGHT(MLVL,minw,maxw) \
weight (((((maxw-minw)+1)*((MLVL*100)/199))/100)+minw)

At level 0 the NPC gets the minimum, at level 199 the maximum, and in between a share by level. Height is in centimetres, weight in pounds.

SETHEIGHT(40, 150, 200)   // a level 40 humanoid of 150 to 200 cm: 160 cm

Monster templates

The template headers contain over two thousand ready-made NPCs. A template sets race, level, sex, size, natural attack and armour, abilities, weapon and spell skills, alignment and often experience and flags, and some add DIL programs (aggression, combat magic). You add the names and descriptions and whatever you want different.

bldragon
M_DRAGON_BLACK_MEDIUM(70, SEX_MALE)
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"}
alignment -900
end

Because macros overwrite the fields before them, the template comes first: alignment -900 after it replaces the template's -750. Flags are the exception; a romflags or flags line adds to the template's. An MSET_WEAPON or MSET_SPELL after a template replaces only that group, so it must keep the template's split: M_HUMAN_WARRIOR_SWORD puts 85% in weapons and 15% in spells, so a new MSET_WEAPON after it must add up to 85.

Header Templates
mhumanoid.h People. M_AVG_<RACE>(level, sex);

M_<RACE>_WARRIOR_<AXE, SWORD, CLUB, POLE, NATURAL or SPECIAL>(level, sex); M_<RACE>_THIEF_<weapon>(level, sex); M_<RACE>_MAGE_<FIRE, FROST, ACID, ELECTRICITY, MIND or GAS>(level, sex, "attack spell"); M_<RACE>_CLERIC_<HAMMER, CLUB, STAFF or SWORD>(level, sex, "attack spell", "defence spell"); M_SHOP_KEEPER(level, sex, race).

chumanoid.h The same people as children: C_AVG_<RACE>, C_<RACE>_WARRIOR_... and so on.
monster.h Animals: M_BEAR_<SIZE>(level, sex), M_RAT_<SIZE>, ...
fantasy.h Fantasy creatures: dragons, demons, undead, ...
plant.h Plants.
aquatic.h Sea creatures.

For creatures the size in the name goes with a range of levels (from the comment in macros.h): TINY 1–25, SMALL 26–50, MEDIUM 51–75, LARGE 76–100, XLARGE 101–125, GODLY 125–199. A _MAD template is aggressive and often poisonous.

The arguments differ from template to template, so grep the header for the exact name before you use one; the comment at the top of macros.h explains the argument names. A few dozen templates that no zone uses don't compile: the abilities of M_KOBOLD_THIEF_* and M_IVY_* don't add up to 100, and M_SPRITE_MEDIUM has a syntax error, for example.

If you make a general monster that others could use, write it as a template in the right header, built from the macros on this page, and offer it to the project.

For an NPC built from these macros step by step, see Building your first NPC.

Previous: The NPC Section
Next: Building your first NPC