One of the most basic things
you can do with a mud, coding wise, is create a new command. So what we’re going to do is to create a
simple command that will send the character some output. So open up a file, (recremmended file:
player.c) and go to the end of it, or In between some functions that make sense
and type this line:
void do_showstats(CHAR_DATA
*ch, char *argument)
{
ch_printf(ch, “Str: %d\tDex: %d\tWis: %d\tInt: %d\n\r”,
get_curr_str(ch), get_curr_dex(ch),
get_curr_wis(ch), get_curr_int(ch));
ch_printf(ch, “Cha: %d\tCon: %d\tLck: %d\n\r”,
get_curr_cha(ch), get_curr_con(ch),
get_curr_lck(ch));
return;
}
ch is a pointer to the
CHAR_DATA of the user who typed the command, and argument is a pointer to the
string that was typed after the command, and before the user hit enter. We’ll get into how to parse the argument
pointer later.
The ch_printf function,
prints the text to the character.
similar to fprintf and printf, excelt it requires a CHAR_DATA pointer as
the first parameter. The functions
get_curr_str, and the others, are functions that can be found in
handler.c. They return the current
strength, and other attributes of the player.
So a player with all attributes at 18, would have the following
displayed if he entered the command.
Str: 18 Dex: 18 Wis:
18 Int: 18
Cha: 18 Con: 18 Lck: 18
If you wish to spice things
up a bit (add color) use the ch_printf_color function instead, it has the same
parameters as ch_printf.
Now then, we must make 3
more additions to the code base, before we recompile. The first is to mud.h. Do
a search for do_showrace and you’ll see a line like this:
DECLARE_DO_FUN(do_showrace); As you’ve
probably guessed, we need to add a line like that, ECLARE_DO_FUN(do_showstats);
Now edit tables.c and again
search for do_show race, and again make a new line similar to the last
if ( !str_cmp( name,
"do_showstats" )) return
do_showstats;
Then further down the file
(do another search) make another addition
if ( skill == do_showstats
) return "do_showstats";
Now, make clean and
recompile, there shouldn’t be any problems, and reboot the mud. Now the command is in the code base, but
SMAUG doesn’t know that yet, so you have to tell it where to look for it, so
you have to give the following commands
cedit showstats create
do_showstats
cedit save cmdtable
There are other commands you
can give, like the level, but you’ll have to look them up on your own. Now then, type the command showstats and you
should see two lines that list your stats.
And there you have it your first command.