chk_command 1.0 snippet for EmberMUD Install sheet by Rindar (Ron Cole) Code by Raven (Laurie Zenner) Notes: We use this snippet for a number of functions, though the main one is to fix the bugs in the ORDER command. What chk_command does is check to see if it is possible for the mob to do what it has been ordered to do. For instance, ordering a level 1 mob to teleport you some where is now impossible, because at level 1 the mob does not have access to that command (though a charmed level 91 mob would). Note that this function in and of itself does not limit anything - it is simply a tool to be called and used by other functions. Install: Follow the directions below to install the code. 1) You need to add the appropriate line of code into merc.h. It goes into the function prototypes section under the interp.c heading. Below is how it should look within merc.h: /* interp.c */ void interpret args( ( CHAR_DATA *ch, char *argument ) ); bool is_number args( ( char *arg ) ); int number_argument args( ( char *argument, char *arg ) ); char * one_argument args( ( char *argument, char *arg_first ) ); void chk_command args( ( CHAR_DATA *ch, char *argument ) ); 2) Open interp.c and add the new function. 3) Recompile. You are done. If you have any improvements that you would like to share, feel free to send them to me via e-mail. This goes for known bugs with it as well. Finally, you may use this piece of code freely as long as you keep the author's name at the top of the function. The code is provided as-is, with no guarantees or promises made. The author is not responsible for any losses caused by using or attempting to install this code. -= Rindar (clogar@concentric.net) ** Note: This function is provided "as is" and may be used so long as 1) The author's name is kept at the top of the function (if requested) and 2) all other previous licensing aggreements are abided by. The author assumes no responsibility for problems that occur through use or install- ation, including lost wages, bugs, deletions, downtimes, etc... Use at your own risk. All new code is copyrighted by its author. The chk_command function: /* chk_command function coded by Laurie Zenner. */ void chk_command( CHAR_DATA *ch, char *argument ) { char workstr[MAX_INPUT_LENGTH]; char command[MAX_INPUT_LENGTH]; char arg[MAX_INPUT_LENGTH]; CHAR_DATA *victim; int pos; int var; int cmd; int trust; bool found; strcpy( workstr, argument ); argument[0] = '\0'; /* * Strip leading spaces. */ pos = 0; while ( isspace(workstr[pos]) ) pos++; if ( workstr[pos] == '\0' ) return; /* * Implement freeze command. */ if ( !IS_NPC(ch) && IS_SET(ch->act, PLR_FREEZE) ) return; /* * Grab the command word. * Special parsing so ' can be a command, * also no spaces needed after punctuation. */ if ( !isalpha(workstr[pos]) && !isdigit(workstr[pos]) ) { command[0] = workstr[pos]; command[1] = '\0'; while ( isspace(workstr[pos]) ) pos++; } else { var = 0; while (!isspace(workstr[pos])) { if (workstr[pos] == '\0') break; command[var] = workstr[pos]; var++; pos++; } command[pos] = '\0'; while (isspace(workstr[pos])) pos++; } /* * Look for command in command table. */ found = FALSE; trust = get_trust( ch ); for ( cmd = 0; cmd_table[cmd].name[0] != '\0'; cmd++ ) { if ( command[0] == cmd_table[cmd].name[0] && !str_prefix( command, cmd_table[cmd].name ) && cmd_table[cmd].level <= trust ) { found = TRUE; sprintf( argument, "%s", cmd_table[cmd].name ); break; } } if (found) { if ( ch->position < cmd_table[cmd].position ) found = FALSE; /* Character not in position for command */ } else { /* Look for command in social table */ for ( cmd = 0; social_table[cmd].name[0] != '\0'; cmd++ ) { if ( (command[0] == social_table[cmd].name[0]) && (!str_prefix( command, social_table[cmd].name)) ) { found = TRUE; sprintf( argument, "%s", social_table[cmd].name ); break; } } if (found) { if ( !IS_NPC(ch) && IS_SET(ch->comm, COMM_NOEMOTE) ) found = FALSE; else { switch ( ch->position ) { case POS_DEAD: case POS_INCAP: case POS_MORTAL: case POS_STUNNED: found = FALSE; break; case POS_SLEEPING: if ( str_cmp( social_table[cmd].name, "snore" ) ) found = FALSE; break; } } } if (found) { var = 0; while (!isspace( workstr[pos] )) { if (workstr[pos] == '\0') exit; arg[var] = workstr[pos]; pos++; var++; } arg[var] = '\0'; victim = NULL; if ( arg[0] != '\0' ) { victim = get_char_room( ch, arg ); if ( victim == NULL ) found = FALSE; } } } if (!found) argument[0] = '\0'; return; } ============================================================================= / ______ _______ ____ _____ ___ __ _ ______ ____ ____ _____ / \ | ____|__ __| _ \ / ____\ / _ \| \ / | ____| / __ \| _ \ / ____\ \ / | |__ | | | |_| | | | |_| | |\/| | |___ | | | | |_| | | / / | ___| | | | ___/| | __| _ | | | | ____| | | | | __/| | ___ \ \ | | | | | | | |___| | | | | | | | |____ | |__| | |\ \| |___| | / / |_| |_| |_| o \_____/|_| |_|_| |_|______|o \____/|_| \_|\_____/ \ \ / ============================================================================ ------------------------------------------------------------------------------ ftp://ftp.game.org/pub/mud FTP.GAME.ORG http://www.game.org/ftpsite/ ------------------------------------------------------------------------------ This file came from FTP.GAME.ORG, the ultimate source for MUD resources. ------------------------------------------------------------------------------