Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Character creation order

Character creation order

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Tseris   (98 posts)  Bio
Date Tue 27 Oct 2009 10:38 PM (UTC)
Message
In stock 1.9 smaug during character creation it asks for the user to choose class, then race. This always seemed a little backward to me. Has anyone attempted to rearrange the order so it requests race choice first? Is it as simple as moving the get class section in the nanny function to be after the get race section?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 27 Oct 2009 11:49 PM (UTC)
Message
You need to change the order in which the state machine asks for things.

At the end of nanny_get_new_sex there are the lines:


   write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;


That is listing the current classes and asking which one you want (and setting the state machine to check your class).

Then at the end of nanny_get_new_class it lists your races and asks you to choose one:


   write_to_buffer( d, "\r\nYou may choose from the following races, or type help [race] to learn more:\r\n[", 0 );
   buf[0] = '\0';
   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( iRace != RACE_VAMPIRE
          && race_table[iRace]->race_name && race_table[iRace]->race_name[0] != '\0'
          && !IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class )
          && str_cmp( race_table[iRace]->race_name, "unused" ) )
      {
         if( iRace > 0 )
         {
            if( strlen( buf ) + strlen( race_table[iRace]->race_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, race_table[iRace]->race_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_RACE;


So basically you swap those pieces of code around. At the end of getting their sex, you now list the races and ask which one they want. Then at the end of getting the races you list the classes and ask which one they want.

So now, at the end of nanny_get_new_class you now do what it does at the end of nanny_get_new_race, that is to ask for whether you want colour or not:


   write_to_buffer( d, "\r\nWould you like RIP, ANSI or no graphic/color support, (R/A/N)? ", 0 );
   d->connected = CON_GET_WANT_RIPANSI;


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #2 on Tue 27 Oct 2009 11:54 PM (UTC)
Message
Thats what I was hoping for. My only concern was that it might have a problem since each race can only be certain classes, and I didnt know if this dependancy somehow necessitated them being asked in the order that they are.
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #3 on Wed 28 Oct 2009 01:25 AM (UTC)
Message
Alright, so I tried that and after making sure my iRace and iClass were declared in the right places it compiled. When starting a new character it asked for race first just as I want, however it only listed one of the six races I have set up, and when I attempted to choose a race not on the list, it returned with "That is not a race."

Any thoughts?
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 28 Oct 2009 02:10 AM (UTC)
Message
Well, see this line:


 && !IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class )


That is testing for the class restriction for the race (ie. only showing valid races for the class you selected). Now by asking for the race first, that would have to go, and rework it so you test for if the class is valid for the already-selected race.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #5 on Wed 28 Oct 2009 02:34 AM (UTC)
Message
Ok thanks Nick, ill work on it.
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #6 on Thu 29 Oct 2009 09:35 PM (UTC)
Message
Okay. So I changed the order around, and then had to move a few things like where it prompts for rip/ansi/no color. It appears to work, asks for race first, lists the races appropriately. But then it would only allow you to pick one race. Any other choices and it would return with "that is not a race". So I commented out the class restriction line to see if that was interfering with it. But now it wont accept any of the choices, and returns with "that is not a race" no matter what is typed in. Heres the code, although its a little lengthy i left in the section before it so you could see if theres something out of place that Im not seeing. At the end of this starts the void nanny_get_new_class section.


void nanny_get_new_sex( DESCRIPTOR_DATA * d, char *argument )
{
   CHAR_DATA *ch;
   char buf[MAX_STRING_LENGTH];
   int iRace;

   ch = d->character;

   switch ( argument[0] )
   {
      case 'm':
      case 'M':
         ch->sex = SEX_MALE;
         break;
      case 'f':
      case 'F':
         ch->sex = SEX_FEMALE;
         break;
      default:
         write_to_buffer( d, "That's not a sex.\r\nWhat IS your sex? ", 0 );
         return;
   }
   
   write_to_buffer( d, "\r\nYou may choose from the following races, or type help [race] to learn more:\r\n[", 0 );
   buf[0] = '\0';
   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( iRace != RACE_VAMPIRE
          && race_table[iRace]->race_name && race_table[iRace]->race_name[0] != '\0'
          && str_cmp( race_table[iRace]->race_name, "unused" ) )
      {
         if( iRace > 0 )
         {
            if( strlen( buf ) + strlen( race_table[iRace]->race_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, race_table[iRace]->race_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_RACE;
   
}

void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   CHAR_DATA *ch;
   char arg[MAX_STRING_LENGTH];
   int iRace;

   ch = d->character;
   argument = one_argument( argument, arg );
   if( !str_cmp( arg, "help" ) )
   {
      for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
      {
         if( toupper( argument[0] ) == toupper( race_table[iRace]->race_name[0] )
             && !str_prefix( argument, race_table[iRace]->race_name ) )
         {
            do_help( ch, argument );
            write_to_buffer( d, "Please choose a race: ", 0 );
            return;
         }
      }
      write_to_buffer( d, "No help on that topic.  Please choose a race: ", 0 );
      return;
   }


   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( toupper( arg[0] ) == toupper( race_table[iRace]->race_name[0] )
          && !str_prefix( arg, race_table[iRace]->race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

   if( iRace == MAX_PC_RACE
       || !race_table[iRace]->race_name || race_table[iRace]->race_name[0] == '\0'
       /*|| iRace == RACE_VAMPIRE */
       /*|| IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) */
       || !str_cmp( race_table[iRace]->race_name, "unused" ) )
   {
      write_to_buffer( d, "That's not a race.\r\nWhat IS your race? ", 0 );
      return;
   }

   if( check_bans( ch, BAN_RACE ) )
   {
      write_to_buffer( d, "That race is not currently available.\r\nWhat is your race? ", 0 );
      return;
   }

}


Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #7 on Thu 29 Oct 2009 10:16 PM (UTC)

Amended on Thu 29 Oct 2009 10:19 PM (UTC) by Nick Gammon

Message
I put your code in and tested it. It worked after a fashion. ;)

What you didn't say was, that when you put in the race nothing happened. Then if you hit <enter> it said "that is not a race".

The reason is, that after it gets a correct race, in your code you didn't change the d->connected to CON_GET_NEW_CLASS. Since you basically did nothing after a good race was entered, it just asked for the race again, until you got bored and entered an invalid race (like hitting enter would do).

My nanny_get_new_race, which works and then moves on to asking for the class, is as follows (extra lines in bold):



void nanny_get_new_race( DESCRIPTOR_DATA * d, const char *argument )
{
   CHAR_DATA *ch;
   char arg[MAX_STRING_LENGTH];
   int iRace, iClass;
   char buf[MAX_STRING_LENGTH];


   ch = d->character;
   argument = one_argument( argument, arg );
   if( !str_cmp( arg, "help" ) )
   {
      for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
      {
         if( toupper( argument[0] ) == toupper( race_table[iRace]->race_name[0] )
             && !str_prefix( argument, race_table[iRace]->race_name ) )
         {
            do_help( ch, argument );
            write_to_buffer( d, "Please choose a race: ", 0 );
            return;
         }
      }
      write_to_buffer( d, "No help on that topic.  Please choose a race: ", 0 );
      return;
   }


   for( iRace = 0; iRace < MAX_PC_RACE; iRace++ )
   {
      if( toupper( arg[0] ) == toupper( race_table[iRace]->race_name[0] )
          && !str_prefix( arg, race_table[iRace]->race_name ) )
      {
         ch->race = iRace;
         break;
      }
   }

   if( iRace == MAX_PC_RACE
       || !race_table[iRace]->race_name || race_table[iRace]->race_name[0] == '\0'
       /*|| iRace == RACE_VAMPIRE */
       /*|| IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) */
       || !str_cmp( race_table[iRace]->race_name, "unused" ) )
   {
      write_to_buffer( d, "That's not a race.\r\nWhat IS your race? ", 0 );
      return;
   }

   if( check_bans( ch, BAN_RACE ) )
   {
      write_to_buffer( d, "That race is not currently available.\r\nWhat is your race? ", 0 );
      return;
   }

  
 
  // good race entered at this point

   write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;   
}



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #8 on Thu 29 Oct 2009 10:39 PM (UTC)
Message
Okay, awesome. Now, can I take the line


If (IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }


and put it into


write_to_buffer( d, "\r\nSelect a class, or type help [class] to learn more about that class.\r\n[", 0 );
   buf[0] = '\0';

   for( iClass = 0; iClass < MAX_PC_CLASS; iClass++ )
   {
      if( class_table[iClass]->who_name && class_table[iClass]->who_name[0] != '\0' )
      {
         if( iClass > 0 )
         {
            if( strlen( buf ) + strlen( class_table[iClass]->who_name ) > 77 )
            {
               mudstrlcat( buf, "\r\n", MAX_STRING_LENGTH );
               write_to_buffer( d, buf, 0 );
               buf[0] = '\0';
            }
            else
               mudstrlcat( buf, " ", MAX_STRING_LENGTH );
         }
         mudstrlcat( buf, class_table[iClass]->who_name, MAX_STRING_LENGTH );
      }
   }
   mudstrlcat( buf, "]\r\n: ", MAX_STRING_LENGTH );
   write_to_buffer( d, buf, 0 );
   d->connected = CON_GET_NEW_CLASS;   


to allow only certain choices?
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #9 on Thu 29 Oct 2009 11:19 PM (UTC)
Message
I attempted to do this in several places and got a mud crash as soon as a class was selected. Hrmm
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #10 on Fri 30 Oct 2009 01:01 AM (UTC)
Message
Tseris said:



If (IS_SET( race_table[iRace]->class_restriction, 1 << ch->Class ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }



Apart from the strange upper-case "If", you need to rejig this a bit. They have already selected a race, right? So the race will be in ch->race, not iRace. The variable iRace may be undefined which could cause a crash. And they are currently selecting a class, so instead of ch->Class you need iClass.

You need to think about when these variables are set up.

So possibly this will work better:



if (IS_SET( race_table[ch->race]->class_restriction, 1 << iClass ) )
{
      write_to_buffer( d, "That class is not available to you", 0 );
      return;
   }


However I haven't actually tested it. Remember, gdb is your friend. If you can't get it to work, start up gdb, put a breakpoint in nanny_get_new_class (ie. type "break nanny_get_new_class") and then step through, checking variables as you go.

http://www.gammon.com.au/gdb

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Hanaisse   Canada  (114 posts)  Bio
Date Reply #11 on Fri 30 Oct 2009 02:34 AM (UTC)
Message
Just a thought, have you unset all the race dependencies for each class in-game?

What you said in the first post is right, I don't think this is as easy as it seems. And I'd hazard a guess to say it's the dependencies that are screwing things up. Sorry I can't offer any more insight than above.

aka: Hana
Owner in Training of: Fury of the Gods
alm-dev.org:4000
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #12 on Fri 30 Oct 2009 03:31 AM (UTC)
Message
I'm not sure the whole thing makes a heap of difference. After all if you ask the race first, they may find the class they wanted isn't available. But if you ask for the class first they may find the race they wanted isn't available too.

I would prefer some sort of system of allowing them to keep changing all aspects until they are ready, eg.


Currently:

Name:   Agreramond
Class:  Warrior
Race:   Troll
Gender: Male

Type Y to accept the above, or change:
(N)ame, (C)lass, (R)ace, (G)ender ...


That way they can keep fiddling with their character until they get it right.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Tseris   (98 posts)  Bio
Date Reply #13 on Fri 06 Nov 2009 04:50 PM (UTC)
Message
So after messing with it quite a bit, the short story is that no, the code does not like it if you ask for race first, and this leads to mud crashing. I agree with Nick, that in theory it shouldnt matter because whichever you ask for first, it should check what the race/class restrictions are and then give you the appropriate choices. So what Ive decided to do is start over and try a different way.

I copied over the source code for the section so its back to how it was originally. But for my particular mud, since the name of the race and the name of the class are the same, id like to have it ask what class you want, and then automatically assign your race without giving you any prompt at all, and go immediately into asking for rip/ansi.

Id like to do this because as far as the players are concerned, there is no race/class distinction. If you're a Werewolf, youre a Werewolf, thats it. But in terms of game mechanics Im still using the race and class so I can take advantage of things like race based RIS's. Im just removing the text displaying race and class from the "do_score" output.

What would the syntax look like for coding in automatic assignment of race, based on what class you chose?
Top

Posted by Noskire   (1 post)  Bio
Date Reply #14 on Tue 26 Jan 2010 06:16 AM (UTC)
Message
ive got it to work just fine...only it doesn't display classes anymore and any new attempts to alter the code only causes it to not compile at all
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


58,565 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

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