CONCEPT
vitems
(additional support for P_NODROP, P_DRINK, P_FOOD, PV_ITEM_LOCATION,
P_AMOUNT, P_MAX_AMOUNT by Magictcs April 98)
SYNOPSIS
#include <vitems.h>
#include <properties.h>
varargs string AddVItem( mapping props, string parentid );
void RemoveVItem( string id );
mixed VSet( string id, string prop, mixed val );
mixed VQuery( string id, string prop );
varargs mixed GetVItem( string str, mixed prop );
DESCRIPTION
string AddVItem( mapping props )
string AddVItem( mapping props, string parentid );
Add a virtual item to the current object with the given properties.
The property mapping gives a list of properties for the virtual
item. Currently supported are P_ADS, P_IDS, P_PREPS, P_LONG,
P_SMELL, P_NOISE, P_READ_MSG, P_NODROP, P_DRINK, P_FOOD,
PV_ITEM_LOCATION, P_AMOUNT, P_MAX_AMOUNT, P_PREP_REQUIRED,
P_LAST_ID, P_LAST_ADS and P_LAST_PREPS (the last three should
only be queried).
AddVItems return a (string)id for the vitem which is needed to add
vitems to vitems, i.e. sub-vitems and for VSet/VQuery.
To add a 'sub-vitem', AddVItem needs to be called with the id of the
'parent'-vitem as second parameter.
void RemoveVItem( string id )
Remove the vitem that maches to the given id, might either be an
virtual item id returned by GetVItem or AddVItem or a match string,
which needs to hold all ads + the first id.
varargs mixed GetVItem( string str, mixed prop )
Get the value for the vitem 'str'
The optional arg 'prop' defines which property you want to query,
if omited, P_LONG will be used. If set to an integer, special
things are done.
Currently defined for intp(prop):
1 : the function will return 1 if the vitem exists and 0 if not.
2 : the function will return the vitem mapping id.
mixed VSet( string id, string prop, mixed val )
Set the property prop for the vitem with the vitem id 'id' to val.
mixed VQuery( string id, string prop );
Query the property prop for the vitem with the vitem id 'id.
SUPPORTED PROPERTIES
P_NOGET: int | string | string *
non builtint property of vitems, if it is set to:
P_NOGET: 1 (or non zero) -> mark the vitem as non-getable
this isn't the same as an vitems without this property
set, even if both vitems are not getable (the failure
messages are different !)
P_NOGET: string
if someone tries to get it, output the string to all
livings in the room
P_NOGET: ({string1})
if someone tries to get it, send string1 to the
interactive player only (usefull for silent msgs!)
P_NOGET: ({string1,string2})
if someone tries to get it, send string 1 to the
interactive livings, string to all other livings
(who can see in this room!)
livings who cannot see will not get any messages
string1,string2 may be closures to function that return a string:
example:
P_NOGET: ({#'get_the_string_for_the_interactive_player,
#'get_the_string_for_all_other_players})
PV_ITEM_LOCATION: string | closure
non builtint property of vitems, if it is set to:
PV_ITEM_LOCATION: "filename_to_clone"
simplest form, will allow to clone the item one
time in a reset (counting and reset is handled automatically,
but detail handling has to be checked manually - see examples
get1,get2,get3)
PV_ITEM_LOCATION: #'closure_to_return_the_cloned_item
with this you can add additional checks, if the
player is allowed to get the vitem
NOTE: the closure has to return only the cloned
object (or 0 if failure or not allowed to get it),
all other things are done by the room, except the
detail handling
NOTE: if no P_AMOUNT is specified, there is always one item available
during a reset time, you can set P_MAX_AMOUNT to -1 (using:
P_MAX_AMOUNT: -1) to enable unlimited items to get (like
leaves or branches inside a wood) - the cloned item should be
a unit in this case to prevent getting of unlimited items!
P_DRINK: mapping | closure
non builtint property of vitems, if it is set to:
P_DRINK: mapping
a std/food object is cloned, then the given property mapping
is attached to the objects, and then the item is moved into
the living and the living is forced to drink it. If the
drinking fails, the object is destructed afterwards.
P_DRINK: #'closure_to_clone_a_drink_to_drink
the closure have to return a drink, that is a
clone of /std/food, that a player can drink
NOTE: don't clone std/drink - this object is used for drinks
with vessels!
NOTE: as long as the std/food isn't working correctly with
SetProperties() - only the closure part of the code is working
correctly!!!
P_FOOD: mapping | closure
this property works in the same way as P_DRINK above, see
examples food1, food2
NOTE: as long as the std/food isn't working correctly with
SetProperties() - only the closure part of the code is
working correctly!!!
NOTE: drinks and food - if no P_AMOUNT is specified - the drink/food
is unlimited, you can eat/drink as often as you want
(like berry from bush, water from river,...)
P_AMOUNT: int
set the maximum of available objects (get/take) or
the number how often you can drink/eat there.
the next reset will reset this value to the initial
value (if no P_MAX_AMOUNT is set too!)
Limitation of drinks/food/items is possible with
using these property
P_MAX_AMOUNT: int
if it is set - the reset of the room will set the
P_AMOUNT property back to this value
if this property is set to -1 --> enable unlimited
drinks/foods/items to drink/eat/get/take
TODO
Improve this doc, P_PREP_REQUIRED needs to be explained, more examples
EXAMPLES
Add a simple vitem:
AddVItem( ([
P_IDS : ({ "box", "chest" }),
P_ADS : ({ "small", "black" }),
P_LONG : "This is a small black box.\n"
]) );
Add a vitem with a sub-vitem:
string v_id;
v_id = AddVItem( ([
P_IDS : ({ "box", "chest" }),
P_ADS : ({ "small", "black" }),
P_PREPS : ({ "on" }), // subvitems are checked for 'on'
P_LONG : "This is a small black box with an inscription.\n"
]) );
AddVItem( ([
P_IDS : ({ "inscription" }),
P_LONG : "It is written in an ancient language, but "
"maybe you can read it.\n",
P_READ_MSG : "Hehe, imagine what you read now.\n"
]), v_id ); // we give the parent-id here
additional examples for the new mentioned properties see:
directory: /p/school/examples/vitems/
files: get1..get7, drink1, drink2, food1, food2,
AVAILABILITY
std/room(/vitems)
SEE ALSO
properties(C)