14 Jul, 2010, ralgith wrote in the 1st comment:
Votes: 0
On today's agenda: keys. On several MUDs I have been on there has been a serious problem with people hoarding keys, especially ones that wont load again if they're in game. This is how I've solved this issue. Also, I would note that I have no idea if the tbaMUD codebase has already implemented something to solve this issue, however I feel my solution is far more elegant than other solutions I've seen… such as dissolving the key on use which is annoying if you need the same key for multiple things. Feedback appreciated, but pointless criticism isn't.

in db.c reset_zone():
In variable declarations add:
struct obj_data *key; /* For key purging */


Now, below the variable declarations add:
/* Purge all keys for this zone that are on a player or in a room */
for (key = object_list; key; key = key->next) {
if (GET_OBJ_TYPE(key) == ITEM_KEY && GET_OBJ_VNUM(key) >= zone_table[zone].bot && GET_OBJ_VNUM(key) <= zone_table[zone].top) {
if (key->in_room && !key->carried_by && !key->worn_by && !key->in_obj) /* Purge a key from a room */
act("$P dissolves into nothingness.", TRUE, NULL, key, NULL, TO_ROOM);
if (key->carried_by && !IS_NPC(key->carried_by)) /* Purge a carried key */
act("$p dissolves into nothingness.", TRUE, key->carried_by, key, NULL, TO_CHAR);
if (key->worn_by && !IS_NPC(key->worn_by)) /* Purge a worn key */
act("$p dissolves into nothingness.", TRUE, key->worn_by, key, NULL, TO_CHAR);
if (key->in_obj) { /* Purge a key from inside another obj */
for (obj = key->in_obj; obj->in_obj == NULL; obj = obj->in_obj) {} /* Get to the top of the container tree… */
if (obj->in_room)
act("$p dissolves into nothingness.", TRUE, NULL, key, NULL, TO_ROOM);
if (obj->carried_by && !IS_NPC(obj->carried_by))
act("$p dissolves into nothingness.", TRUE, obj->carried_by, key, NULL, TO_CHAR);
if (obj->worn_by && !IS_NPC(obj->worn_by))
act("$p dissolves into nothingness.", TRUE, obj->worn_by, key, NULL, TO_CHAR);
}
extract_obj(key);
}
}
0.0/1