Hey guys I need a fresh set of eyes to look at this. I am missing something simple I guess. For some reason my obj_from_char call is having NULL ch a few times in the loop and screwing up my obj_to_obj call numbers. What the intent of this code was, is to bundle up crafted items that players do, so that I can have a player craft 20 odd things for a quest mob, and carry it as 1 object giving a bundle of 20 crafted things to the mob to activate the act_prog.
/* too many damn loops in one command just simplifing it hopefully - Vladaar */
short inventory_total(CHAR_DATA *ch)
{
OBJ_DATA *check;
short total = 0;
for(check = ch->last_carrying; check; check = check->prev_content)
{
total++;
}
return total;
}
/* Allow players to bundle together up to 50 items of same vnum
for ease in carrying - Vladaar */
void do_bundle(CHAR_DATA *ch, char *argument )
{
char arg1[MIL], arg2[MIL];
OBJ_DATA *obj, *check, *bundle;
short number = 0;
char buf[MSL];
if(!ch)
return;
argument = one_argument(argument, arg1);
if(arg1[0] == '\0')
{
send_to_char("Bundle how many what?\r\n", ch);
return;
}
if(is_number(arg1))
{
number = atoi(arg1);
if(number < 2)
{
send_to_char("There must be at least 2 items to bundle.\r\n", ch);
return;
}
}
else
{
send_to_char("Bundle how many what?\r\n", ch);
return;
}
int jackpot = 0;
argument = one_argument(argument, arg2);
if((obj = get_obj_carry(ch, arg2)) == NULL)
{
send_to_char("You don't have any of those to bundle.\r\n", ch );
return;
}
jackpot = obj->pIndexData->vnum;
short count = 0;
// Check to see if player has correct number to bundle
for(check = ch->last_carrying; check; check = check->prev_content)
{
if ( check->pIndexData->vnum == jackpot && count != number )
{
count++;
bug( "%s: %d count %d number of %s with vnum %d found", __FUNCTION__, count, number, check->name, jackpot );
}
}
if ( count < number )
{
bug( "%s: %d count less than %d number", __FUNCTION__, count, number );
send_to_char("You don't have enough to bundle.\r\n", ch );
return;
}
bundle = create_object(get_obj_index(OBJ_VNUM_SHOPPING_BAG), 0);
snprintf(buf, MSL, "bundle %s", obj->name);
STRFREE(bundle->name);
bundle->name = STRALLOC(buf);
snprintf(buf, MSL, "a bundle of %d %s", number, obj->name);
STRFREE(bundle->short_descr);
bundle->short_descr = STRALLOC(buf);
snprintf(buf, MSL, "A bundle of %d %s has been left here.", number, obj->name);
STRFREE(bundle->description);
bundle->description = STRALLOC(buf);
bundle->value[0] = bundle->weight + (obj->weight * number);
short count2 = 0;
count2 = inventory_total(ch);
bug( "%s: inventory_total %d count2", __FUNCTION__, count2 );
count = 0;
while ( count2 != -1 && count != number )
{
for(check = ch->last_carrying; check; check = check->prev_content)
{
if ( check->pIndexData->vnum == jackpot && count <= number )
{
if ( ch )
count++;
separate_obj(check);
obj_from_char(check);
obj_to_obj( check, bundle );
}
}
count2--;
}
bug( "%s: %d count2 when %d number", __FUNCTION__, count2, number );
obj_to_char(bundle, ch);
xREMOVE_BIT(bundle->extra_flags, ITEM_GROUNDROT);
act(AT_ACTION, "You bundle up the $p wih leather lashings.", ch, obj, NULL, TO_CHAR);
act(AT_ACTION, "$n bundles up $p together with leather lashings.", ch, obj, NULL, TO_ROOM);
return;
}
Current Results of the code are
You are carrying:
[35548] a dragonic saddle bag
[41002] (Sharp) a pair of talons, legendary produced from meteor (11)
Vladaar::[30000/30000hp 2990/2990m 7411/7411mv] bundle 8 talons
Log: [*****] BUG: do_bundle: 1 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 2 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 3 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 4 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 5 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 6 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 7 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: 8 count 8 number of talons with vnum 41002 found
Log: [*****] BUG: do_bundle: inventory_total 11 count2
Log: [*****] BUG: obj_from_char null ch for object a pair of talons, legendary produced from meteor.
Log: [*****] BUG: obj_from_char null ch for object a pair of talons, legendary produced from meteor.
Log: [*****] BUG: obj_from_char null ch for object a pair of talons, legendary produced from meteor.
Log: [*****] BUG: obj_from_char null ch for object a pair of talons, legendary produced from meteor.
Log: [*****] BUG: do_bundle: -1 count2 when 8 number
You bundle up the a pair of talons, legendary produced from meteor wih leather lashings.
Vladaar::[30000/30000hp 2990/2990m 7411/7411mv] i
You are carrying:
[35548] a dragonic saddle bag
[41002] (Sharp) a pair of talons, legendary produced from meteor (6)
[25] a bundle of 8 talons
Vladaar::[30000/30000hp 2990/2990m 7411/7411mv] l in bundle
A bundle of 8 talons contains:
[41002] (Sharp) a pair of talons, legendary produced from meteor (5)