Crashcourse - Part 02

[previous part] [Table of contents] [next part]

In part two of this crashcourse, you will learn more about programming objects for a mud world. You will find examples for a weapon, an armour, a drink and some food.

First of all, a lot of functions you will come across, will have several different types of parameters. For instance, a function may accept an integer or a string. The mudlib will see which one you're using and act accordingly. A lot of functions uses a string for a parameter. Let's take a look at add_id(). You can send a single string inside it, but you can also send an array of strings inside it. And often, an array is preferable. For example, in the case of the ruby, you could do:

add_id(({"ruby","red ruby","beautiful ruby","shining red ruby"}));
As you can see the syntax for an array is: ({item 1, item2, ...})

Okay, it's time to look at the examples and see if we can learn anything from them. Let's first look at the weapon example:

FILENAME: longsword.c

If you take a look at the file, there's not much new to say about it. As you can see it's not that much different from the ruby. The only three new functions are special functions for weapons. set_class() tells the mudlib how good the weapon is. It can be an integer from 1 to 20, where 20 is the best and 1 is the worst. set_damage_type() sets the type of damage a weapon does, and can use a number of different damage types, but it must fit the type of weapon. Swords usually do "slash" damage, daggers do "pierce", axe do "chop" and staffs do "blunt", which is also the default damage type done by weapons. A more detailed list can be found in the manual page 'damage'.

The balance between weight and class is important to know about. The mudlib alters it automatocally, but still keep it in mind. There is a 1:5 ratio between the weight and the class, meaning that for every 5 class, there must be 1 weight. So a weapon with weight 2 may have a max class of 10. This is to prevent coders from making too good weapons. There are ways to go around this, of course. And we will, in a later course, be making a powerful weapon.

We also divide weapons into different weapon classes, like sword, axe, dagger, stick, net, etc. To get a complete list have a look at 'man weapon.list'. The weapon type is set using

But, since sword is the default weapontype, we don't need to use set_weapon_type ("sword") for the longsword. We have, however, used it in this example to show how it is used.

FILENAME: ringmail.c

This is a small example of an armour, in this case a ringmail. Again, the differences are small from the previous examples. If you read through the example, you will however notice two new functions. set_ac() and set_type(). The first one sets the armour class(ac) of the armour. The ac may have a value of 0 to 4 for bodyarmour (ringmail, platemail, jackets, etc), while the rest(helmets, boots, etc) can only use ac of 0 and 1. An armour with ac of 0 gives no protection at all, while an armour of ac 4 will give very good protection. The function called set_type() sets the kind of armour it is.

You can choose among the following types:

Armour types
type worn at
Left Hand (no weapon in left hand)

You can only wear one of each at any time.

FILENAME: dragonbreath.c

As you can see from the example, there's not too many new functions to learn. set_heal() sets how many spell points(sp) and hit points(hp) that shall be healed when this drink is drunk. set_heal(5) will make the drink heal you 5 hp + 5 sp when you drink it. If you want to heal only hp or only sp, there are two more functions to learn:

set_hp_heal()  // sets how many hitpoints the drink shall heal the player.
set_sp_heal()  // sets how many spellpoints the drink shall heal the player.

The next two functions, set_strength() and set_soft_strength() sets how much the drink shall influence the player. set_strength() will make the player intoxicated (drunk), while set_soft_strength() will make the player soaked.

The last two functions, set_drinker_mess() and set_drinking_mess() sets messages that will be written when the player drinks the drink. set_drinker_mess() is sent to the player, while set_drinking_mess() is sent to everyone else in the same room, if any. The name of the player drinking is prepended to the drinking mess before it's written to the room.

If you want to make a huge bottle, or a potion of some sort, the drink may be drunk in sips, instead of it all at once. Using the function set_full() you may set how many sips you may take before the drink is gone. In this case, set_heal()/set_sp_heal()/set_hp_heal() will set the amount healed in each sip.

FILENAME: pizza.c

Food is even easier to make. The only new functions are set_eater_mess() and set_eating_mess() and they work just as set_drinker_mess() and set_drinking_mess() for drinks. The difference between foods and drinks is that you can only set the strength in food. The amount of healing is set automatically according to the strength.

Properties are a very important part of the objects in the mud world. They tell the mudlib how to treat the objects. For instance, a drink is automatically given the property 'fragile'. The mudlib sees this property and if the drink is dropped, the mudlib destroys the drink as it hits the ground. But, properties are not just texts set in different objects. You can set the properties to contain almost any different type of variables. For instance, there is a property called 'worn_out' in all items. This property tells the mudlib how worn out an item really is and contains an integer of 1-100. When this property reaches 100, the item breaks. You can also add two properties to weapons called 'broken_desc' and 'break_mesg'. Both must be strings. The first one tells the mudlib what kind of description the weapon shall get when it breaks, and the other one tells the mudlib what kind of message shall be written to the player when the weapon breaks.

Most properties are already set in most objects that inherit the correct file from /std, but not all. So, keep the properties in the back of your mind (and look them up from time to time using 'lookupp') and remember to use them in almost all of your items. (There are only a few items that don't need them.)

And we have finally reached the end of this part of the crashcourse. So, go ahead and start coding stuff right now and get used to using all the functions you have learned.

WRITTEN: 30-Sep-1996 - Gunner
LAST UPDATE: 26-May-1998 - Gunner
HTML Version: 31-Jan-2000 - Ghorwin

[previous part] [to the top] [Table of contents] [next part]