void respond_give(string func, mixed *to_match);
To use this function, you must do a couple things:
1) inherit "/std/basic/respond_give";
This is done in ADDITION to whatever else you're inheriting.
2) add: give_init(); to your void init() { }
Now you're ready to use respond_give()! The function call goes in setup().
And it must have a function to call.
There are 8 possible ways to call this function. They are:
respond_give("<give_func>");
respond_give("<give_func>","<string>");
respond_give("<give_func>",({"name","<string>"}));
respond_give("<give_func>",({"property",<prop>}));
respond_give("<give_func>",({"property",<prop>,<val>}));
respond_give("<give_func>",({"money",<amt>}));
respond_give("<give_func>",({"money","<type>",<amt>,...}));
respond_give("<give_func>",({"unconditional"}));
A breakdown of the options comes later.
**********************************************************************
First, let's look at the simplest case:
---------------------------------------
respond_give("my_give_func");
In addition, you would have to define my_give_func():
void my_give_func(object player, object *items) {
spiffy_stuff;
}
where the following is true:
player is the person giving <something> to the npc or object
and
object *items is an array of the items matched.
In the above example items will not be passed.
Also note that my_give_func() gets called AFTER the give, so we're
checking on what the npcs now HAS, not on what the player was trying
to give.
**********************************************************************
Now for the cases:
------------------
1)
respond_give("<give_func>");
Unconditional. If the npc receives an item from a player, this
gets called. Do the checking on whether it's the RIGHT item in
<give_func>().
An example of when this would be used is if you wanted an NPC to
say "Thanks bud" everytime anyone gave anything to him.
2)
respond_give("<give_func>","<string>");
Match by <string>. This uses find_match(), so it should match by name,
short, aliases, or plurals. 'items' in <give_func>() will hold an
array of matches.
An example of when this would be used is if you had an NPC that does
something when he receives only a CERTAIN item.
For example, Fred really wants a dagger:
Hamlet gives a dagger to Fred.
Fred gives Hamlet a beer.
BUT if:
Hamlet gives a long sword to Fred.
[Fred does nothing at all.]
3)
respond_give("<give_func>",({"name","<string>"}));
Match by <string>. Identical to the previous case.
See above example.
4)
respond_give("<give_func>",({"property",<prop>}));
Match by the <prop> property on the items. If the property is
nonzero, it matches. 'items' will hold the list.
An example of when this would be used is if you had an NPC that
responds only to an item that has been tagged with a property
as being *the* item. Zillions of daggers out there, but only
the one that has the property "my_spiffy_quest" is the right
one to give to Fred.
5)
respond_give("<give_func>",({"property",<prop>,<val>}));
Match by the <prop> property on the items. If the property's value
is <val>, it matches. 'items' will hold the list.
An example of this is: Hamlet has the dagger. It has the
"my_spiffy_quest" property on it. but the property value
is only 97. 97 is the count of how many guards Hamlet has
killed with the dagger. So, Hamlet goes to give the dagger
to Fred (he *really* wants that beer), but Fred for some
reason only wants a dagger that has killed a 100 guards.
So... [Fred does nothing at all.]
6)
respond_give("<give_func>",({"money",<amt>}));
Match by <amt> of money. This is in copper coins. Obviously the
players can still give the money in platinum or whatever. If they
give insufficient money, <give_func>() will not be called, but this
money will be counted toward subsequent gives. 'items' will be
an array holding the money object.
An example of this is if you wanted to allow Fred to receive money
and have him do something in return for the player (saying thanks
counts).
Fred wants 10 platinum coins.
Hamlet gives 5 platinum coins to Fred.
[Fred does nothing at all.]
Hamlet frowns.
Hamlet gives 25 gold coins to Fred.
Fred gives Hamlet a daisy.
Hamlet frowns.
Hamlet says: Where's my beer?
[Fred does nothing at all.]
7)
respond_give("<give_func>",({"money","<type>",<amt>,...}));
Match by money. Any amount of "<type>", <amt> pairs may be entered.
Their value will be calculated and then this works the same as the
above case.
example: respond_give("give_func",({"money","platinum",50}));
See above example.
8)
respond_give("<give_func>",({"unconditional"}));
<give_func>() gets called truly unconditionally. This one
should only be used if there is no other way to get the
effect you need. Note that if your npc is called Harry and
someone types: "give frog to joe", <give_func>() will STILL
be called. So make sure the npcs has received something new.
'items' will be null in this case.
This one is BAD... DON'T use this unless you have to...
Talk to Hamlet if you need to use it (bring a beer, I
think he is still pissed).
*********************************************************************
Note that multiple respond_give()s are allowed in one object. The only
odd case is if you want to respond to two different money amounts. For
example, say giving a merchant 5 platinum will get you a cloak, but giving
him 10 platinum will get you a shield. In this case, put the respond_give()
with the HIGHER monetary value first. This should make it work properly.
It is not difficult to use these options to make an npc that only responds
when he receives TWO (or more) items and/or money. See
respond_give.example for an example of this.
** Examples supplied by Cadogan