The keyfind command is a small utility which locates containers and room directions which correspond to a specified key vnum. If you've ever been frustrated by trying to determine what a particular key opens, this command is for you. I didn't bother to page_string() the output, so if you feel the need for that you'll have to add it yourself. I am running bpl 17 with corresponding global buffers. No warranty express or implied; if you don't know how to add a command to your mud, don't try to use this. Thanks. Bugs/comments to meersan@earthlink.net /* in addition to arg/argument/buf, */ /* keyfind uses the following global vars: */ extern struct room_data *world; extern room_rnum top_of_world; extern struct obj_data *obj_proto; extern obj_rnum top_of_objt; extern const char *dirs[]; ACMD(do_keyfind) { obj_vnum key_vnum = 0; obj_rnum key_rnum = 0; int i = 0, j = 0, found = 0; one_argument(argument, arg); if ((!*arg) || !isdigit(*arg)) { send_to_char("Usage: keyfind <keyvnum>\r\n", ch); return; } if ((key_vnum = atoi(arg)) < 0) { send_to_char("A NEGATIVE number??\r\n", ch); return; } if ((key_rnum = real_object(key_vnum)) < 0) { send_to_char("There is no object with that number.\r\n", ch); return; } if (GET_OBJ_TYPE(&obj_proto[key_rnum]) != ITEM_KEY) { send_to_char("That's not even a key!\r\n", ch); return; } /* we now have a valid object vnum of type ITEM_KEY to search for */ /* rooms first... */ sprintf(buf, "Key %d opens the following doors:\r\n", key_vnum); send_to_char(buf, ch); /* for all rooms in the world, */ for (found = 0, i = 0; i < top_of_world; i++) { /* for all directions in this room */ for (j = 0; j < NUM_OF_DIRS; j++) { /* if the direction does not exist, skip it */ if (!world[i].dir_option[j]) { continue; /* otherwise check if the key matches */ } else if (world[i].dir_option[j]->key == key_vnum) { found = 1; sprintf(buf, "%5d - %-9.9s - %s&+0\r\n", world[i].number, dirs[j], world[i].name); send_to_char(buf, ch); } } } if (!found) { send_to_char(" None.\r\n\r\n", ch); } else { send_to_char("\r\n", ch); } /* now find any container objects our keyvnum opens */ sprintf(buf, "Key %d opens the following containers:\r\n", key_vnum); send_to_char(buf, ch); for (found = 0, i = 0; i < top_of_objt; i++) { if ((GET_OBJ_TYPE(&obj_proto[i]) == ITEM_CONTAINER) && (GET_OBJ_VAL(&obj_proto[i], 2) == key_vnum)) { found = 1; sprintf(buf, "%5d - %s&+0\r\n", GET_OBJ_VNUM(&obj_proto[i]), obj_proto[i].short_description ? obj_proto[i].short_description : "Unnamed"); send_to_char(buf, ch); } } if (!found) { send_to_char(" None.\r\n", ch); } } -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/06/01 PST