Creating a command, you’ll
often times need to find a char with the input string. This is easy enough. Say you wish to create a glory transfer
command (It was the first command I ever made J with a syntax of glorytransfer <victim>
<amount> so You’ll have to get the second argument as the ‘victim’. All the SMAUG code using the victim as the
target of the code, so it’s probably best to keep that consistent. So first you’ll need to parse the string
into two variables.
char arg[MAX_INPUT_LENGTH];
argument =
one_argument(argument, arg);
Now you have arg, being the
name of the victim, and argument being the amount in a string. Now for clarity, you might make an arg2 or
something and have that be the amount (have a second one_argument call), but
you don’t need too. Now there are two
functions that you can use here, get_char_world and get_char_room, I think
their names make them obvious of how to use them. They both have the same parameters as well and both return the
resulting CHAR_DATA pointer, if a victim is found. So let’s add some more code:
if(((victim = get_char_room(ch, arg)) = =
NULL) {
send_to_char(“That character is not in this room.\n\r”,
ch);
return;
}
and there we have it, now
victim is pointing to the correct player and you can use it however you
like. You’d probably make another int,
and assign it atoi(argument) then add the glory and take away the glory from
the ch. Also these functions work for
mobs and PC’s alike.
For objects, it’s very
similar, here are the function prototypes, you should be able to understand
what they mean. They use the exact same
parameters as the get_char functions, (except they return type OBJ_DATA *)
OBJ_DATA *
get_obj_carry args( ( CHAR_DATA *ch,
char *argument ) );
OBJ_DATA * get_obj_wear args( ( CHAR_DATA *ch, char *argument ) );
OBJ_DATA * get_obj_here args( ( CHAR_DATA *ch, char *argument ) );
OBJ_DATA *
get_obj_world args( ( CHAR_DATA *ch,
char *argument ) );
The one exception is
OBJ_DATA * get_obj_vnum args( ( CHAR_DATA *ch, int vnum ) );
which obviously you have to
pass the vnum in an integer, instead of searching for it by name.