Welcome to the Builder Academy

Question Survey/Scout - Great for Rangers/Warriors

More
22 Jan 2022 05:17 - 22 Jan 2022 22:18 #9982 by jandulio
do_survey will look at all adjacent rooms to the player and report back who is in them.  Great for scouting around to see where to go next.  This is based on the "spy" skill that is on the tbaMUD google drive.

If you see any room for improvement lmk!
Code:
// Usage: survey // Looks into all adjecent rooms from the player // and shows all pcs/npcs in them ACMD(do_survey) {     // check if they even know the skill     if (IS_NPC(ch) || !GET_SKILL(ch, SKILL_SURVEY))     {         send_to_char(ch, "You have no idea how to do that.\r\n");         return;     }     if (AFF_FLAGGED(ch, AFF_BLIND) && GET_LEVEL(ch) < LVL_IMMORT)     {         send_to_char(ch, "You can't see a thing, you're blind!\r\n");         return;     }     else if (IS_DARK(IN_ROOM(ch)) && !CAN_SEE_IN_DARK(ch))     {         send_to_char(ch, "It is pitch black...\r\n");         return;     }     // survey is like the "spy" skill, but it looks in all rooms around you     for (int i = 0; i < NUM_OF_DIRS; i++)     {         char cur_dir[MAX_INPUT_LENGTH];         // temp direction so it can be capitalized         sprintf(cur_dir, "%s", dirs[i]);         // look for the direction they typed within the dirs array         int look_type = search_block(cur_dir, dirs, FALSE);         // check for invalid direction         if (look_type == -1)         {             send_to_char(ch, "Look where???\r\n");             return;         }         // invalid direction or no room?         if (look_type >= 0 && EXIT(ch, look_type) && !(EXIT(ch, look_type)->to_room == NOWHERE))         {             char temp_string[MAX_INPUT_LENGTH];             // direction with capital first letter             strcpy(temp_string, dirs[look_type]);             temp_string[0] -= 32;             send_to_char(ch, "%s", CCNRM(ch, C_NRM));        // color for dir             send_to_char(ch, "%s:\r\n", temp_string);        // dir             if (IS_SET(EXIT(ch, look_type)->exit_info, EX_CLOSED) && EXIT(ch, look_type)->keyword) {                 send_to_char(ch, "%s", CCYEL(ch, C_NRM));                 send_to_char(ch, "The %s is closed.\r\n", fname(EXIT(ch, look_type)->keyword));             }             else {                 // list of chars in room looking in, if none found tell player                 // NOTE: list_char_to_char actually lists the characters                 if ((list_char_to_char(world[world[IN_ROOM(ch)].dir_option[look_type]->to_room].people, ch) == 0))                 {                     send_to_char(ch, "%s", CCYEL(ch, C_NRM));                     send_to_char(ch, "No one.\r\n");                 }             }         }     } }
[/i]
Last edit: 22 Jan 2022 22:18 by thomas. Reason: added [code-block]

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

More
22 Jan 2022 22:33 #9985 by thomas
There are a couple of things to improve, code-style:
Code:
// Usage: survey // Looks into all adjecent rooms from the player // and shows all pcs/npcs in them ACMD(do_survey) {     // check if they even know the skill     if (IS_NPC(ch) || !GET_SKILL(ch, SKILL_SURVEY))     {         send_to_char(ch, "You have no idea how to do that.\r\n");         return;     }     if (AFF_FLAGGED(ch, AFF_BLIND) && GET_LEVEL(ch) < LVL_IMMORT)     {         send_to_char(ch, "You can't see a thing, you're blind!\r\n");         return;     } -    else if (IS_DARK(IN_ROOM(ch)) && !CAN_SEE_IN_DARK(ch)) +    if (IS_DARK(IN_ROOM(ch)) && !CAN_SEE_IN_DARK(ch)) // no need for "else" when you end the previous with a return.     {         send_to_char(ch, "It is pitch black...\r\n");         return;     }     // survey is like the "spy" skill, but it looks in all rooms around you     for (int i = 0; i < NUM_OF_DIRS; i++)     {         char cur_dir[MAX_INPUT_LENGTH];         // temp direction so it can be capitalized         sprintf(cur_dir, "%s", dirs[i]); // this next bit is not needed. You already _know_ that the cur_dir is in dirs. -        // look for the direction they typed within the dirs array -        int look_type = search_block(cur_dir, dirs, FALSE); - -        // check for invalid direction -        if (look_type == -1) -        { -            send_to_char(ch, "Look where???\r\n"); -            return; -        }         // invalid direction or no room? -        if (look_type >= 0 && EXIT(ch, look_type) && !(EXIT(ch, look_type)->to_room == NOWHERE)) +        if (EXIT(ch, i) && !(EXIT(ch, i)->to_room == NOWHERE))         { // this bit reinvents the CAP function in utils.c. -            char temp_string[MAX_INPUT_LENGTH]; - -            // direction with capital first letter -            strcpy(temp_string, dirs[look_type]); -            temp_string[0] -= 32; -            send_to_char(ch, "%s", CCNRM(ch, C_NRM));        // color for dir -            send_to_char(ch, "%s:\r\n", temp_string);        // dir +            send_to_char(ch, "%s%s:\r\n", CCNRM(ch, C_NRM), CAP(cur_dir)); // can send several at once -            if (IS_SET(EXIT(ch, look_type)->exit_info, EX_CLOSED) && EXIT(ch, look_type)->keyword) { +            if (IS_SET(EXIT(ch, i)->exit_info, EX_CLOSED) && EXIT(ch, i)->keyword) { -                send_to_char(ch, "%s", CCYEL(ch, C_NRM)); -                send_to_char(ch, "The %s is closed.\r\n", fname(EXIT(ch, look_type)->keyword)); +                send_to_char(ch, "%sThe %s is closed.\r\n", CCYEL(ch, C_NRM), fname(EXIT(ch, i)->keyword));             }             else {                 // list of chars in room looking in, if none found tell player                 // NOTE: list_char_to_char actually lists the characters -                if ((list_char_to_char(world[world[IN_ROOM(ch)].dir_option[look_type]->to_room].people, ch) == 0)) +                if ((list_char_to_char(world[world[IN_ROOM(ch)].dir_option[i]->to_room].people, ch) == 0))                 { -                    send_to_char(ch, "%s", CCYEL(ch, C_NRM)); -                    send_to_char(ch, "No one.\r\n"); +                    send_to_char(ch, "%sNo one.\r\n", CCYEL(ch, C_NRM));                 }             }         }     } }
[/i][/i]
This might look like a scathing takedown, but a lot of it was ok. There was just a little extra, unneeded, work going on,
 

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

More
22 Jan 2022 22:54 #9986 by jandulio
Fantastic, thanks so much! I'm learning as I go, so any bit of information helps!

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

Time to create page: 0.169 seconds