[Home] [Downloads] [Search] [Help/forum]

SMAUG server FAQ

Frequently Asked Questions (FAQ) about SMAUG server.

Summary How to add more questions to the SMAUG login sequence
Question I want to add a "roll stats" to the original character creation. I have found a couple of snippets but none of them work even after following their instructions. I have written a C++ program that generates random numbers but when I try to "plug it in" to your code I get several errors. One problem I know of, is "#include <iostream.h>" ... for some reason it's acting like it doesn't see this at all, my cout, cin, << etc. do not work at all. Any insight you could offer would be greatly appreciated.

Well, for one thing the files are .C files and not .CPP which means they are C and not C++. Thus things like cout, and << will not work.

Second, using "cout" is wrong anyway because all that would do is display something on the screen of the server which is hardly what you want - you want the stats to go to the player.

What you need to do to change the login sequence, is to change the way "nanny" works in comm.c.

Remember, the server is handling multiple players doing things all the time, so it is not a simple matter of asking a question and expecting an answer. eg.

printf ("What is your name ...");
gets   (name);

This would fail for a number of reasons, for one thing, printf would only go to the terminal of the server, and the gets would hang the server until you reply, which means all the other players would have a "dead" server.

Each player has a descriptor, which stores its state, and in that is a thing called "connected" which is how far they have got through the connection sequence.

This is a "switch" that checks the state, like this:

    switch ( d->connected )
         case CON_GET_NAME:
            /* process getting their name */

         case CON_GET_OLD_PASSWORD:
            /* get their password */

         case CON_CONFIRM_NEW_NAME:
            /* confirm their name */

/* and so on */

      }	/* end of switch */

To send a message to the player you use "write_to_buffer" like this:

	    write_to_buffer( d, "Please type Yes or No. ", 0 );

Here are the states, from mud.h:

 * Connected state for a channel.
typedef enum
} connection_types;

You would need to:

  1. Add a new state to the above enum
  2. Decide whereabouts in the login sequence the new question was to go
  3. Change the existing sequence to add your new state, eg.


    	write_to_buffer( d, "\n\rWhat is your sex (M/F/N)? ", 0 );
    	d->connected = CON_GET_NEW_SEX;


    	write_to_buffer( d, "\n\rDo you want me to roll your stats? ", 0 );
    	d->connected = CON_ROLL_STATS;
  4. Handle the reply(s) to this question. eg. add this code to inside the switch statement:
             case CON_ROLL_STATS:
                /* do your new stuff */

    If you need to ask more than one question, then you need to repeat this process for each question. Read the "nanny" function to get the feel for how this works.

  5. Eventually go back to the old sequence (ask the remaining questions). eg. after getting their stats you would do this:
    	write_to_buffer( d, "\n\rWhat is your sex (M/F/N)? ", 0 );
    	d->connected = CON_GET_NEW_SEX;

Now you are back into the original login sequence.

Search for word or phrase

Enter a word or phrase in the box below to narrow the list down to those that match.

Search for:   

Leave blank to show all FAQs.

View all SMAUG server FAQ


Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]