Come code with us
Come code with us
The adventure begins

Merentha Website
About LPC Coding
Header Files
The Problem Sets

Normal Rooms
Monster Rooms
Search Rooms
Exit Rooms
Door Rooms

Normal Monster
Random/Emote Monster
Patrol/Talking Monster
Skills/Interactive Monster

A Vest
A Ring
Cursed Armour

Normal Staff
Two Handed Sword
Special Attack Weapon
Cursed Weapon
Talkin Weapon

A Match
A Torch
A Lantern

A Normal Bag
A Backpack (wearable)
An Expanding Bag

Misc Objects
A Leaf
A Sea Shell
A Key
A Snowball

OK, lets add items to the room!

So you have a few rooms now and you want to add a monster to the room. This is really quite simple and you will use the same code in many places.

In reality all you want to do is add one item into another. In LPC everything is an Object and inherits the Object.c file. One of these in a container.c object. This type of object can 'hold' other objects. This container object is inherited by living things (players and monsters) rooms and bags. That is to say each one of those, players, monsters, rooms and bags can hold other items.

So if we want to add a monster to a room it is really quite simple.

void reset() {
  if (!present("elf")) new("/realms/your_name/elf.c")->move(this_object());
Ok, lets take a look at this. First thing to note is that now we are actully writing code, simple code but actual code. Up until now the code you've writen doesn't really do much but set a bunch of variable names, now you are programming some functionality. The previous code is a typical reset() function used in rooms.

First this code will not work unless you have a file called elf.c in your home directory. It would help as well if that file was a file of an elf too. You should be able to copy one of the monster examples into your directory and name it elf.c. Update the file to make sure it loads correctly before proceeding.

Now, this code is best added at the end of your file, so in the editor zoom down to the bottom (either with z or I or $. Personally I like the I option as it will indent your work while taking you to the bottom of the file as well. Then use the a command to add more to the file.

You will be adding code to the end of the file, after the create() function has been closed with a }. So you will now create a new function called reset(). This is a special function which automaticlly gets called in all objects every 30 minutes.

The next line ::reset() calls the inheritable object's reset which is sometimes desireable. You should always include this line. The 3rd line though does all the tricky work.

  if(!present("elf")) new("/realms/your_name/elf.c")->move(this_object());
This line is comprised of a conditional and the action to take if the conditional is true. The conditional is if(!present("elf")) This translates into "If the elf is NOT present in this object" the ! means NOT. The action then is as follows: new("/realms/your_name/elf.c")->move(this_object()); Which means make a new object from the file names and move it to this_object() which is really the file in question, the room file.

So what we have is a statement which checks to see if the monster is in the room and if not, create the monster.

Ok, so we can now do the same with any other items. We can add any object to a room the same way. We always want to check if the item is already in the room though because otherwise we will add a new object all the time which isn't good, you can end up with 50 monsters in teh same room where all you wanted was 1.

Adding objects to monsters is just as easy. Using the same code you can add inventory to monsters, just add the code to the monster file. You would usually not add this in a reset() function but instead put it right in the create() function. You can find better examples of this within the builder port. Remember you have access to nearly all of Whitestorm and Cabeiri on the builder port and can look at any file in there.

It's your creation
Merentha Entertainment
© Copyright 1998-2002
Merentha Entertainment
All rights reserved.