Creating a New Command

Posted by Kris on Sun 13 May 2001 11:14 PM — 4 posts, 19,173 views.

USA #0
I noticed that there's a 'homepage' command, which you can use to set your homepage, but there isn't an 'email' command, where you can set your email. Therefore, I decided to create one. I found all references to the homepage command (i.e. function calls\declarations, variable declarations, etc) and copied them, replacing the word 'homepage' with the word 'email'. I then created the 'do_email' function, which was literally a copy-and-paste of the 'do_homepage' function, except I once again changed 'homepage' to 'email'; i.e. 'ch->pcdata->homepage' to 'ch->pcdata->email' and so-on. I then did the same thing in the 'commands.dat' file. After that, I deleted all the object files, and recompiled the server. There were no compile errors, and no run-time errors that I could find. When I type 'commands', the email command is listed among them. However, whenever I type 'email', the mud returns 'Huh?'. I cannot figure out why this is. Is there something I missed? I did remember to update mud.h as well. What else should I do to get it to perform the email command?
Australia Forum Administrator #1
In tables.c there are two references to do_homepage - did you duplicate those for email as well?

These convert to and from the string to the function name.



case 'h':

...

if ( !str_cmp( name, "do_homepage" ))
  return do_homepage;


if ( skill == do_homepage )
  return "do_homepage";



Also, in the first one, it would need to be placed under case 'e', not case 'h'.


USA #2
Ok, I got it to work just fine and all. It saves it to my player file and everything. It also shows up on my revamped 'whois' just as it should. However, if I quit-out, and re-enter, my email shows up as unlisted again. It still remains in the player file, but for some reason the server isn't reading it from the player file when the character is loaded up. I duplicated the 'homepage' command as precisely as I could, save the changes you mentioned. The homepage info loads up just fine, but I can't figure out why it's loading up but email is not. Do you have any idea how I can fix this? Thanks :)
Australia Forum Administrator #3
In save.c, it reads in character data, in function fread_char.

A little way in, you will find:


case 'H':


followed by:


KEY( "Homepage", ch->pcdata->homepage, fread_string_nohash( fp ) );


You need to duplicate that functionality, changing "homepage" to "email", which you have probably done, but it needs to be under the 'E' section (E for Email) not the 'H' section (H for Homepage).

So, find the 'E' section, which include this line:


KEY( "Exp", ch->exp, fread_number( fp ) );


and put your email line there. :)