Collects are objects that are grouped together, such as gold, sand, and liquids.
cCollection - Collection objects
The cCollection class lets you create objects that are
groups of objects, such as gold, water, sand, and a deck of
cards. The collection object allows you to combine collections
(such as two piles of gold), split collections (one pile
of gold into two), and it displays a quantity in front of
the object (such as "52 gold pieces" or "5 liters of water").
If you haven't read the tutorial on cObject - Basic
objects then you should do that now because
cCollection objects are based off cDoor objects.
Creating a collection object
Here's how you create a collection object:
-
Just as described in the "cObject" tutorial, create
a new object, but instead of deriving
your room off cObject, derive it from cCollection.
(cCollection is a subclass of cObject, so by deriving from cCollection
you are also deriving from cObject.)
-
Make sure the Automatically create as an object button
is checked. (Note: If you are going to have more than one pile
of gold, you may want to make a cCollectionGold class, and then
derive each individual pile from that. This tutorial assumes
you only have one pile of gold though.)
-
Underneath the checkbox, select the room that
the collection will be in.
-
In the object's properties tab, you'll find a
number of properties that were automatically added when
you selected the "cCollection" class. You'll need to fill these in.
-
Set the pVisual property, of course.
-
pNLPParseName and pNLPNounName will
need to be filled in. See How command parsing
works and Noun cases and noun-verb agreement.
Generally, pNLPParseName will be something like "[(pile|piece|pieces) [of]] gold [piece|pieces]",
and pNLPNounName "gold piece". Unless you change pNLPNounQuantity,
a number will always be displayed in front of "gold piece".
-
Fill pQuantityUnits in with a character indicating
what type of units are associated with the collection.
Use 'm' if the object is grouped in meters (like a rope),
'2' if it's square meters (like cloth), 'l' if it's in liters
(liquids), 'f' if it's a fractional unit (like modern currency),
or 'i' if it's an integer unit (like pieces of gold).
-
If you have any type of units (besides the integer units) then
set pQuantityMin to indicate the smallest size
the object can be divided into. If you don't, some user
will divide 100 liters of water into 100,000 objects, each
with 1 ml.
-
Set pQuantity to the number of such units.
In the case of gold, it will be the number of gold coins.
-
Set pCollectionType to a string that uniquely
identifies the class of object that this collection holds.
In this case, it would be "goldpieces". If you had
a water object you'd use "water". If you have healing potion
it would be "healingpotion". This string is necessary to make
sure that only collections of the same type can be merged
together.
That's it. If you play with your new object you'll notice the
following feature:
-
The name always displays the quantity in front of it.
-
You can split the object into smaller parts, using
a command like "divide gold into 3 parts".
-
You can combine piles of gold togehter with
a command, "combine all gold", or "combine 3 gold pieces with
5 gold pieces" (assuming you have one pile with 3 gold peices,
and another with 5 gold pieces).
07 cContainer – Container objects
Describes how to make containers, like backpacks and chests.
cContainer - Container objects
The cContainer object lets you easily make containers, such
as bags, backpacks, chests, hat racks, book cases, etc.
If you haven't read the tutorial on cObject - Basic
objects then you should do that now since
containers are based off basic objects.
Here's how you create a container:
-
Just as described in the "cObject" tutorial, create
a new object, but instead of deriving
your room off cObject, derive it from cContainer.
(cContinaer is a subclass of cObject, so by deriving from cContainer
you are also deriving from cObject.)
-
Make sure the Automatically create as an object button
is checked. (Note: If you are going to have more than one container
of the same type, you may want to make a cContainerBackpack class, and then
derive each individual backpack that. This tutorial assumes
you only have one backpack though.)
-
Underneath the checkbox, select the room or object that
the container will be in.
-
In the object's properties tab, you'll find a
number of properties that were automatically added when
you selected the "cContainer" class. You'll need to fill these in.
-
Set the pVisual property, of course.
-
pNLPParseName and pNLPNounName will
need to be filled in. See How command parsing
works and Noun cases and noun-verb agreement.
-
Fill pContainerVolumeMax with the maximum volume
that the container can hold, in liters.
The pContainerVolumeScale should be filled in with
a number from 0 to 1, indicating how much larger the container
gets when you shove more objects in it. For example: A canvas
bag will use 1.0, since the volume of the bag is dependent upon
its contents. A chest would be 0.0 since shoving more stuff
into a chest does not increase its volume.
-
Fill pContainerWeightMax with the maximum weight
the container can hold; a canvas bag cannot hold as much
weight as a chest. You can add
the pContainerWeightScale property to turn
the container into a magic item; the default scale is 1.0,
which means that if the container holds 10 kg of weight, it's
10 kg heavier. However, if the scale is reduced, to 0.5, then
the 10 kg of contents will only add 5 kg to the weight
of the container.
-
Set pVolumeSelf and pWeightSelf for
the volume and weight of the container, without contents.
-
If you wish your container to be openable,
set pOpen to FALSE, causing the
container to initially be closed. It can be set
to TRUE if you wish it to start out opened.
That's it. You now have a container that you can put stuff in.
To create a locked container:
-
In the container's property tab, add the pLock property.
Set it to TRUE. This defaults to the container being
locked... which makes sense from a game point-of-view.
-
Also add the pLockShape tab, and type in
a string the identifies the shape of key that will
open the container, such as "SkeletonKey12". Some
keys may fit to several shapes, allowing them to open
several types of locks, just as master keys do. Conversely,
you can have a container accept several key shapes by
setting pLockShape to a list, like ["SkeletonKey12",
"SkeletonKey54"].
-
If you want your container to automatically lock itself after
it has been unlocked, set pLockAutoLock to
the number of seconds delay before it locks. This feature
is extremely handy for multi-user interactive fiction,
causing a container puzzle to reset. If you use automatic
locking you may also wish to set pOpenAutoClose to
have the container automatically close itself... a locked
container does not good if it's left open.
-
You'll need to create a key object that
supports pKeyShape with "SkeletonKey12".
See the tutorial, cObject - Generic objects for
information on general-purpose objects.
That's it. Now, players (and NPCs) will have to unlock the
container before accessing its contents.
Other properties and methods
Containers support some other properties and methods, such
as ways to make the containers
see-through, using pCanSeeContents. For more information
see the documentation.
Share with your friends: |