do_findobj().txt
snippets · 1.1 KB · 2010-03-30
do_findobject: finds objects by name in your inventory and containers.
Download « Back to the snippets list
// Function to find objects by name in the inventory (and containers there-in)
void do_findobject(CHAR_DATA *ch, char *argument) {
char *arg = &argument[0];
OBJ_DATA *obj, *obj2;
int i = 1;
for (obj = ch->carrying; obj != NULL; obj = obj->next_content) {
if (obj->wear_loc == WEAR_NONE && can_see_obj (ch, obj)) {
if (strstr(obj->short_descr, arg)) {
printf_to_char(ch, "{w%2d{B) {w%s {Bin{w inventory{B.{x\r\n", i, obj->short_descr);
i++;
}
if (obj->item_type == ITEM_CONTAINER) {
for (obj2 = obj->contains; obj2 != NULL; obj2 = obj2->next_content) {
if (obj2->wear_loc == WEAR_NONE && can_see_obj (ch, obj2)) {
if (strstr(obj2->short_descr, arg)) {
printf_to_char(ch, "{w%2d{B) {w%s {Bin{w %s{B.{x\r\n",i, obj2->short_descr,
obj2->in_obj->short_descr);
++i;
}
}
}
}
}
}
}