Well, I've done this before (actually several times), and here's
the way I think was best:
--(snip)--
struct obj_data *obj, *bag;
obj_num r_num;
int i, j;
/* In the following table:
* vnum = Virtual number of object to give to them
* number = Amount of objects to give to them
* wear = -2 to put in bag, -1 to inventory, otherwise it's a WEAR_xxx
*
* Fill in your own numbers; { -1, 0, 0 } must be last, though
* AND the first entry MUST be the bag object if you wish to use
* -2 in the wear slot
*/
int eq[][3] = {
{ vnum, number, wear },
.
.
.
{ -1, 0, 0 }
};
for (i = 0; eq[i][0] != -1; i++) {
if ((r_num = real_object(eq[i][0])) < 0)
continue;
obj = read_object(r_num, REAL);
if (i == 0) { /* bag object */
bag = obj;
obj_to_char(bag, ch);
continue;
}
for (j = 0; j < eq[i][1]; j++)
if (eq[i][3] == -2 && bag)
obj_to_obj(obj, bag);
else if (eq[i][3] == -1)
obj_to_char(obj, ch);
else if (eq[i][3] > 0 && eq[i][3] < NUM_WEARS)
equip_char(ch, obj, eq[i][3]);
}
--(end snip)--
Anyway, this is off the top of my head done in my mailer, but it's
essentially the way I way I did it. It worked nicely: checked to make sure
the object existed before trying to do anything with it, and it only took
one addition to an array to have a new object load. The only shortcoming
was that it only supports one object that serve as the bag where things
with -2 wear are placed.
Also, it might be nice o do:
#define WEAR_IN_BAG -2
#define WEAR_INVENTORY -1
Before the do_start function or whatever function you decide to
place this in (I gave it it's own function because I have an ACMD function
that calls it [it's a command that allows a player to re-equip themselves
with the weak newbie equipment once in their entire character's life time
(I set a PLR_REPLACE bit when they're created and remove it when they
use the REPLACE command) -- this gives a newbie a bit of a chance to still
succeed if they die]).
Also, if you #define the two suggested above, after the do_start
(or whatever function), do:
#undef WEAR_IN_BAG
#undef WEAR_INVENTORY
Anyway, good luck, have fun... :)
This archive was generated by hypermail 2b30 : 12/18/00 PST