Sorry, forgot something, change this block:
if (food->objIndexData->vnum == OBJ_VNUM_FOOD) {
obj_from_char(food);
extract_obj(food);
}
To this:
if (food->objIndexData->vnum == OBJ_VNUM_FOOD && count > 0) {
obj_from_char(food);
extract_obj(food);
count--;
}
Richard Lindsey.
-----Original Message-----
From: Richard Lindsey
Sent: Wednesday, March 08, 2006 1:55 PM
To: [EMAIL PROTECTED]; [email protected]
Subject: RE: Extracting a certain number of objects from a char
You'd most likely want to do something like declaring an OBJ_VNUM_FOOD
and an OBJ_VNUM_PACK in your merc.h file, then substituting
get_obj_index(OBJ_VNUM_PACK) for get_obj_index(41) in your code, so that
you can simply change that vnum in the header file instead of at random
places in your code... then you need to change the "obj = create_object"
line to say "pack = create_object" instead, since you don't have "obj"
declared anywhere, and then ship pack to the character instead of obj in
the next line... after that... here, let me actually just post some
revised code for you :) That might make it easier, and you can compare
it to your original post and see the changes...
OBJ_DATA *food;
OBJ_DATA *pack;
OBJ_DATA *food_next;
int count = 0, num_packs = 0;
char buf[MAX_STRING_LENGTH];
/* First loop through this to see if they have enough food to combine,
otherwise they could have like 3, get stripped of all of them, and then
the code finds out that's not enough for a pack */
for (food = ch->carrying; food != NULL; food = food->next_item) {
if (food->objIndexData->vnum == OBJ_VNUM_FOOD) {
count++;
}
}
num_packs = count / 6; /* Count the number of packs we can make */
count = num_packs * 6; /* Redefine count to the exact number of food
items we want to extract */
if (num_packs > 0) {
/* First we extract all of the relevant food items */
for (food = ch->carrying; food != NULL; food = food_next) {
food_next = food->next_time;
if (food->objIndexData->vnum == OBJ_VNUM_FOOD) {
obj_from_char(food);
extract_obj(food);
}
}
/* Then we give them the food packs in place of them */
for (x = 0; x < num_packs; x++) {
pack = create_object(get_obj_index(OBJ_VNUM_PACK));
obj_to_char(pack,ch);
}
/* Output a message to the user */
sprintf(buf, "You have converted %d food items into %d food
packs!\n\r", count, num_packs);
send_to_char(buf, ch);
} else {
/* Not enough food items, output a message */
send_to_char("You don't have enough food items to convert into
packs.\n\r", ch);
}
Richard Lindsey.
p.s. I'm w/ Valnir, plus my email client doesn't space replies out w/ >
characters, so it would've been hard to tell the original post from my
own anyway.
--
ROM mailing list
[email protected]
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom
--
ROM mailing list
[email protected]
Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom