Welcome to the Builder Academy

Question The Lazy Find Door

More
09 Jul 2015 03:54 #5418 by WhiskyTest
Have you ever wanted to be able to type 'open north' and it finds the door and opens it without you having to specify the keyword?

No? OK then you aren't lazy like me.

But if you are... here is the find_door() function that will let you do just that.
Also works for close, pick and anything else you might send through find_door.

Attachment lazy_find_door.txt not found



Code:
static int find_door(struct char_data *ch, const char *type, char *dir, const char *cmdname) { int door = -1;; if (!*type) { send_to_char(ch, "What is it you want to %s?\r\n", cmdname); return (-1); } /* check for open/close <direction> */ if ((door = search_block((char *) type, dirs, FALSE)) != -1) { if (EXIT(ch, door)) return (door); } if ((door = search_block((char *) type, autoexits, FALSE)) != -1) { if (EXIT(ch, door)) return (door); } if (*dir) { /* a direction was specified */ if ((door = search_block(dir, dirs, FALSE)) == -1) { /* Partial Match */ if ((door = search_block(dir, autoexits, FALSE)) == -1) { /* Check 'short' dirs too */ send_to_char(ch, "That's not a direction.\r\n"); return (-1); } } if (EXIT(ch, door)) { /* Braces added according to indent. -gg */ if (EXIT(ch, door)->keyword) { if (is_name(type, EXIT(ch, door)->keyword)) return (door); else { send_to_char(ch, "I see no %s there.\r\n", type); return (-1); } } else return (door); } else { send_to_char(ch, "I really don't see how you can %s anything there.\r\n", cmdname); return (-1); } } else { /* try to locate the keyword */ for (door = 0; door < DIR_COUNT; door++) { if (EXIT(ch, door)) { if (EXIT(ch, door)->keyword) { if (isname(type, EXIT(ch, door)->keyword)) { if ((!IS_NPC(ch)) && (!PRF_FLAGGED(ch, PRF_AUTODOOR))) return door; else if (is_abbrev(cmdname, "open")) { if (IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED)) return door; else if (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED)) return door; } else if ((is_abbrev(cmdname, "close")) && (!(IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))) ) return door; else if ((is_abbrev(cmdname, "lock")) && (!(IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED))) ) return door; else if ((is_abbrev(cmdname, "unlock")) && (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED)) ) return door; else if ((is_abbrev(cmdname, "pick")) && (IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED)) ) return door; } } } } if ((!IS_NPC(ch)) && (!PRF_FLAGGED(ch, PRF_AUTODOOR))) send_to_char(ch, "There doesn't seem to be %s %s here.\r\n", AN(type), type); else if (is_abbrev(cmdname, "open")) send_to_char(ch, "There doesn't seem to be %s %s that can be opened.\r\n", AN(type), type); else if (is_abbrev(cmdname, "close")) send_to_char(ch, "There doesn't seem to be %s %s that can be closed.\r\n", AN(type), type); else if (is_abbrev(cmdname, "lock")) send_to_char(ch, "There doesn't seem to be %s %s that can be locked.\r\n", AN(type), type); else if (is_abbrev(cmdname, "unlock")) send_to_char(ch, "There doesn't seem to be %s %s that can be unlocked.\r\n", AN(type), type); else send_to_char(ch, "There doesn't seem to be %s %s that can be picked.\r\n", AN(type), type); return (-1); } }
Attachments:
The following user(s) said Thank You: Parnassus

Please Log in or Create an account to join the conversation.

More
11 Jul 2015 13:47 #5420 by Parnassus
Replied by Parnassus on topic The Lazy Find Door
I often name doors something like "gate north", just because I'm too lazy to check the keywords. Of course, this only works on doors I build or edit so I like your fix much better :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.219 seconds