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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Sex/Class/Race selection

Sex/Class/Race selection

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


Posted by Damzien   (6 posts)  [Biography] bio
Date Sat 15 Mar 2008 11:43 PM (UTC)

Amended on Sun 16 Mar 2008 12:16 AM (UTC) by Damzien

Message
First off, I'm using Smaugfuss 1.9

Secondly I have a limited understanding of C coding, though I did just start school for programming yesterday, and hopefully wont be too bothersome in the future :)

Basically I decided to use a mobprog to set the sex/class/race for new players as they progress through the learning area for my mud. I'm confident in my building skills with doing the mobprog's, the real question I have is:

I want the game to automatically choose a generic race and class for the character without showing them the choose class/race buffer during the input selection.

I've messed around in Comm.c and managed absolute frustration with my level of understanding. At first I thought it would be simple, I edited the nanny functions after

void nanny_confirm_new_password( DESCRIPTOR_DATA * d, char *argument )
{
CHAR_DATA *ch;

ch = d->character;
write_to_buffer( d, "\r\n", 2 );

if( str_cmp( sha256_crypt( argument ), ch->pcdata->pwd ) )
{
write_to_buffer( d, "Passwords don't match.\r\nRetype password: ", 0 );
d->connected = CON_GET_NEW_PASSWORD;
return;
}

write_to_buffer( d, echo_on_str, 0 );
write_to_buffer( d, "\r\nWhat is your sex (M/F/N)? ", 0 );
d->connected = CON_GET_NEW_SEX;
}

and changed the
write_to_buffer( d, "\r\nWhat is your sex (M/F/N)? ", 0 );
d->connected = CON_GET_NEW_SEX;

simply to
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;

and removed the

case CON_GET_NEW_SEX:
nanny_get_new_sex( d, argument );
break;

case CON_GET_NEW_CLASS:
nanny_get_new_class( d, argument );
break;

case CON_GET_NEW_RACE:
nanny_get_new_race( d, argument );
break;


Which compiles now, and sets a new player to a

neutral/human/warrior

Why? and how can I change that to my generic race/class?
I suppose the neutral sex is fine, after all I'll make a mobprog to let the player change that if they wish.

If some one could point me in the right direction, show a working example, slap me for being stupid, or just laugh mercilessly... either way. Thanks in advance.

P.S. if I'm forgetting to give any information, just ask. I really would like to get this to work.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Sun 16 Mar 2008 12:38 AM (UTC)
Message
Well, human/warrior are the default race/class, and since you didn't add code to change the race/class, they didn't get changed. :-)

Before talking about how to address that, though, why is it a problem if people get set to human/warrior if, as they progress through the newbie area, it gets changed for them anyhow?

Well, actually, it's easy to change the race/class... just do ch->race = MY_GENERIC_RACE (change appropriately to whatever you called your generic race) and similarly for class.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Damzien   (6 posts)  [Biography] bio
Date Reply #2 on Sun 16 Mar 2008 02:01 AM (UTC)
Message
"Well, human/warrior are the default race/class."
//Okay, makes sense. I'll make a backup and dabble a bit before I ask too many questions about that. Other then what file I could change this in?

"Well, actually, it's easy to change the race/class... just do ch->race = MY_GENERIC_RACE"
//I implemented these lines
ch->class = Generic_Class;
ch->race = Generic_Race;

Here in the Comm.c file

void nanny_get_want_ripansi( DESCRIPTOR_DATA * d, char *argument )
{
CHAR_DATA *ch;
char log_buf[MAX_STRING_LENGTH];

ch = d->character;

switch ( argument[0] )
{
case 'r':
case 'R':
xSET_BIT( ch->act, PLR_RIP );
xSET_BIT( ch->act, PLR_ANSI );
break;
case 'a':
case 'A':
xSET_BIT( ch->act, PLR_ANSI );
break;
case 'n':
case 'N':
break;
default:
write_to_buffer( d, "Invalid selection.\r\nRIP, ANSI or NONE? ", 0 );
return;
}
snprintf( log_buf, MAX_STRING_LENGTH, "%s@%s new %s %s.", ch->name, d->host,
race_table[ch->race]->race_name, class_table[ch->Class]->who_name );
log_string_plus( log_buf, LOG_COMM, sysdata.log_level );
to_channel( log_buf, CHANNEL_MONITOR, "Monitor", LEVEL_IMMORTAL );
write_to_buffer( d, "Press [ENTER] ", 0 );
show_title( d );
->HERE<-
->HERE<-
ch->level = 0;
ch->position = POS_STANDING;
d->connected = CON_PRESS_ENTER;
set_pager_color( AT_PLAIN, ch );
}

did a make clean and then make. These are the errors I recieved.

comm.c: In function 'void nanny_get_want_ripansi(DESCRIPTOR_DATA*, char*)':
comm.c:2360: error: expected unqualified-id before "class"
comm.c:2360: error: expected ';' before "class"
make[1]: *** [o/comm.o] Error 1
make: *** [all] Error 2

I'm assuming I did something wrong and it's going to make me feel stupid, though fire away. Hopefully it's an easy fix.

Thanks :)
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #3 on Sun 16 Mar 2008 02:17 AM (UTC)
Message
Quote:
Other then what file I could change this in?

I think you'd want to look at the function that creates a character. You might want to look up clear_char in db.c -- although keep in mind that changing that will change the defaults for all characters, not just players.

The better way to do this would be to look at load_char_obj in save.c and have it set race/gender/class appropriately.

Quote:
I'm assuming I did something wrong and it's going to make me feel stupid, though fire away. Hopefully it's an easy fix.

This is a slightly annoying side-effect of technical choices the details of which aren't very important at the moment. The variable is named "Class", not "class", so you just need to use the capitalized version.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Damzien   (6 posts)  [Biography] bio
Date Reply #4 on Sun 16 Mar 2008 02:46 AM (UTC)

Amended on Sun 16 Mar 2008 02:52 AM (UTC) by Damzien

Message
I changed them so they would look like
ch->Class = Generic_Class;
ch->race = Generic_Race;
saved, make clean, make

got the exact same error message as before.
Played around a bit, because that's how I learn best, still couldn't figure it out. It's okay though, as much as it bugs me I found a simpler way to get the desired effect. I merely renamed the default race/class files.

I remember seeing a post where I might need to define the generic class/race in the mud.h file?

It was an aesthetic's issue anyway, and now when new players type score they see the names I want. And without fudging with the clear_char in db.c just changed the name of the mobs class too.

Thanks David for your patience and help, you're awesome.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #5 on Sun 16 Mar 2008 02:55 AM (UTC)
Message
I'm surprised that you got the exact same error message, since that message only shows up when you use the literal string "class" -- "Class" will not trigger that error.

But, it sounds like you found a workaround for your problem, which was the goal in the end of the day anyhow. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Damzien   (6 posts)  [Biography] bio
Date Reply #6 on Sun 16 Mar 2008 03:06 AM (UTC)

Amended on Sun 16 Mar 2008 03:09 AM (UTC) by Damzien

Message
Last post on this subject from me, hey David I'm not asking you to explain it but I just wanted you to know.

When I amended the get_want_ripansi
so the bottom looks like this

ch->race = 1;
ch->Class = 2;
ch->level = 0;
ch->position = POS_STANDING;
d->connected = CON_PRESS_ENTER;
set_pager_color( AT_PLAIN, ch );
}

setting the race before Class this time, using the number of the race/class instead of the file name, and double spacing between the = <race/class number> made it work.

Without double spacing that error would show, now it compiled clean and does what I wanted the original way I wanted. Strange, but true.


... just noticed, posting here didn't show the double space between the = and the #. There is actually two spaces, and without it, it wont compile for me.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #7 on Sun 16 Mar 2008 03:27 AM (UTC)

Amended on Sun 16 Mar 2008 03:28 AM (UTC) by David Haley

Message
You should use the "code" forum tag if you want a monospaced font that respects multiple spaces.

But I am rather skeptical that spacing is the issue here. C doesn't pay attention to extra whitespace, so the statements:

i = 5;

and
i =     5;

are exactly equivalent.

It's easy to lose track of which changes did what when several changes are made in rapid succession; chances are that you had something else in there that confused the compiler, and made several changes at once (one of which was the whitespace thing) and one of them fixed it. But trust me, changing the whitespace like that really won't change the expressions. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #8 on Sun 16 Mar 2008 04:42 PM (UTC)
Message
It pays to be careful with spaces though, regarding actual variable names and operators.
For instance, you might have put a space in the middle of the ' -> ' operator, making it look like ' - > '. So, although whitespace is ignored it can disrupt your code unintentionally, and something like that might have happened.
Yeah, David is always a big help. This place is great.

regards,
Gadush
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #9 on Sun 16 Mar 2008 10:26 PM (UTC)
Message
Oh, yes, Gadush is right. I should have been clearer: whitespace is ignored between tokens (or operators, if you will), but whitespace still matters for recognizing those operators. So as he said, ' - > ' is not the same thing as '->'. Same for '= =' and '==', for example. But as soon as you've "finished" an operator, all extra whitespace is ignored. So for example, 'i=1' and i = 1' are the same thing.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] 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.


20,528 views.

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

Go to topic:           Search the forum


[Go to top] top

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.

[Home]


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 HostDash]