I have spent several hours looking for the code and I simply can not find it. I want to change the smaug code so that if there is no title in the class file, it does not assign that person a title. Currently when you remove or change the title line to just ~, it make thier title 'the (null)'. Hope someone can help with this.
Null Titles
Posted by Malti on Tue 25 Apr 2006 05:18 AM — 21 posts, 71,919 views.
I can't remember offhand, but look in advance_level or the sort. There should be a call to a function that changes the title.
void set_title( CHAR_DATA * ch, char *title )
{
char buf[MAX_STRING_LENGTH];
if( IS_NPC( ch ) )
{
bug( "%s", "Set_title: NPC." );
return;
}
if( title[0] != '\0')
{
if( isalpha( title[0] ) || isdigit( title[0] ) )
{
buf[0] = ' ';
mudstrlcpy( buf + 1, title, MAX_STRING_LENGTH - 1 );
}
else
mudstrlcpy( buf, title, MAX_STRING_LENGTH );
STRFREE( ch->pcdata->title );
ch->pcdata->title = STRALLOC( buf );
}
return;
}
this is what I did, but when a new player joins, they still get 'the (null)' as thier title. I dont want them to have titles at all. Any ideas?
Find the part:
Add below it:That way, it'll always set the title to "" if the title argument is NULL.
Also, please use the code tag when posting code, it makes it much easier to read it. :)
if( title[0] != '\0')
{
if( isalpha( title[0] ) || isdigit( title[0] ) )
{
buf[0] = ' ';
mudstrlcpy( buf + 1, title, MAX_STRING_LENGTH - 1 );
}
else
mudstrlcpy( buf, title, MAX_STRING_LENGTH );
STRFREE( ch->pcdata->title );
ch->pcdata->title = STRALLOC( buf );
}Add below it:
else
{
STRFREE( ch->pcdata->title );
ch->pcdata->title = STRALLOC("");
}Also, please use the code tag when posting code, it makes it much easier to read it. :)
Didn't work. Plus, that added codes means that if there is no title for that level it will make thier title "" and I dont want that. Basically, here is what i want to do
I want titles to be assigned for special actions/duties. So I figured it would be better if I went into advance_level, the source of where the code takes place (for the most part)...
this is what I found
so I tried
and none of these worked. They all compile fine but besides that I get nothing. Also, is there a way to get a prefix? I.e. Make someone 'Baron' name 'title'?
if title exist for level
set title
else
leave current title
I want titles to be assigned for special actions/duties. So I figured it would be better if I went into advance_level, the source of where the code takes place (for the most part)...
this is what I found
snprintf( buf, MAX_STRING_LENGTH, "%s", title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
set_title( ch, buf );
so I tried
snprintf( buf, MAX_STRING_LENGTH, "%s", title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
if(buf != "(null)")
set_title( ch, buf );
snprintf( buf, MAX_STRING_LENGTH, "%s", title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
if(buf != '\0')
set_title( ch, buf );
snprintf( buf, MAX_STRING_LENGTH, "%s", title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
if(buf[0] != '\0')
set_title( ch, buf );
and none of these worked. They all compile fine but besides that I get nothing. Also, is there a way to get a prefix? I.e. Make someone 'Baron' name 'title'?
Quote:
Plus, that added codes means that if there is no title for that level it will make thier title "" and I dont want that.
Plus, that added codes means that if there is no title for that level it will make thier title "" and I dont want that.
Wrong. Their title would be blank. The two quotes with nothing inbetween is a blank string.
Quote:
if(buf != "(null)")
set_title( ch, buf );
if(buf != "(null)")
set_title( ch, buf );
You need to use a string comparison function. Thus, if you wanted it like that, you would need to write:
if ( str_cmp( buf, "(null)" ) != 0 )
set_title(ch, buf );
str_cmp returns zero on an exact match. Of course, this is supposing that you snprintf will throw (null) into the string by default. If this wasn't the case, you could easily change (or add an and && ) to be buf[0] != '\0'.
A more safe if statement would be:
if ( (buf[0] != '\0') && (str_cmp( buf, "(null)" ) != 0) )
set_title(ch, buf );
As for prefix's, I think you would either need to change the "rank" field to do what you want or add another field. Or perhaps only display titles and no names, making sure their name is in their title somewhere. To give the players that option could be bad, however, as then anyone could be a Baron or Duke of anything.
Didn't work :(
OK... I think we need to back up a little bit. Could you tell us:
- what precisely do you want this to do? Your first post said something, but then you changed your requirements in a later post.
- what exactly have you changed so far, both in the code and in the title data files? When you say "didn't work", what exactly did not work, and where exactly did you put the code?
- what precisely do you want this to do? Your first post said something, but then you changed your requirements in a later post.
- what exactly have you changed so far, both in the code and in the title data files? When you say "didn't work", what exactly did not work, and where exactly did you put the code?
ok, the requirements didn't change. If there is no title in the title file, I do not want the title to be updated. I.E. if I remove all of the titles from ranger.class, I dont want to see 'the (null)' show up as the persons title. So what i changed was the advance_level. Specifically,
but it still gives them a null title when they get advanced to level two (auto-auth). If there is no title for that level,class,gender, then I dont want it be updated. Understand?
if ( (buf[0] != '\0') && (str_cmp( buf, "(null)" ) != 0) )
set_title(ch, buf );
but it still gives them a null title when they get advanced to level two (auto-auth). If there is no title for that level,class,gender, then I dont want it be updated. Understand?
OK. Where did you put that code? Is that in set_title, or somewhere else?
Quote:
So what i changed was the advance_level
So what i changed was the advance_level
Where did you put it in the code? Where did you insert it? You didn't answer my question, which is why I asked it again... although I should have seen the function name, the function name on its own is basically useless. Can't help you with just a function name.
if ( (buf[0] != '\0') && (str_cmp( buf, "(null)" ) != 0) )
set_title(ch, buf );
the bold line is what was added, and the line below it is like the 10th line down from the function header. I dont really know how to be any more specific. Sorry.
Basically, I know how to do this in theroy, but I dont know how to do the code, so it might be easier to tell you what Im thinking theoretically.
1. Get the title for the level/Gender/Class (this is in the title table)
2. Check and see if that title acctually exits (ie. not null)
3. If it the title is null, then just dont call the set_title. If that title is acctually a title(not null) then we want to set it.
set_title(ch, buf );
the bold line is what was added, and the line below it is like the 10th line down from the function header. I dont really know how to be any more specific. Sorry.
Basically, I know how to do this in theroy, but I dont know how to do the code, so it might be easier to tell you what Im thinking theoretically.
1. Get the title for the level/Gender/Class (this is in the title table)
2. Check and see if that title acctually exits (ie. not null)
3. If it the title is null, then just dont call the set_title. If that title is acctually a title(not null) then we want to set it.
It'd be easier if you posted the whole function itself, if it's not too long, since I don't have the code here. (I have a different version of SMAUG that's heavily customized.)
I think I understand what it is that you want, but it's hard to debug without knowing exactly where you've put what and how it all fits into the bigger picture. One problem is that it seems that by "null" you don't really mean a null pointer, but the string "(null)".
What you can try doing is printing out the contents of "buf" to, say, the log channel. Then you'll be able to see exactly what its comparing again "(null)"; perhaps the actual string contents are "the (null)".
I think I understand what it is that you want, but it's hard to debug without knowing exactly where you've put what and how it all fits into the bigger picture. One problem is that it seems that by "null" you don't really mean a null pointer, but the string "(null)".
What you can try doing is printing out the contents of "buf" to, say, the log channel. Then you'll be able to see exactly what its comparing again "(null)"; perhaps the actual string contents are "the (null)".
void advance_level( CHAR_DATA * ch )
{
char buf[MAX_STRING_LENGTH];
int add_hp;
int add_mana;
int add_move;
int add_prac;
snprintf( buf, MAX_STRING_LENGTH, "%s" ,title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
if ( (buf[0] != '\0') && (str_cmp( buf, "(null)" ) != 0) )
set_title(ch, buf );
add_hp = con_app[get_curr_con( ch )].hitp + number_range( class_table[ch->Class]->hp_min,
class_table[ch->Class]->hp_max );
add_mana = class_table[ch->Class]->fMana ? number_range( 2, ( 2 * get_curr_int( ch ) + get_curr_wis( ch ) ) / 8 ) : 0;
add_move = number_range( 5, ( get_curr_con( ch ) + get_curr_dex( ch ) ) / 4 );
add_prac = wis_app[get_curr_wis( ch )].practice;
add_hp = UMAX( 1, add_hp );
add_mana = UMAX( 0, add_mana );
add_move = UMAX( 10, add_move );
/*
* bonus for deadlies
*/
if( IS_PKILL( ch ) )
{
add_mana = ( int )( add_mana + add_mana * .3 );
add_move = ( int )( add_move + add_move * .3 );
add_hp += 1; /* bitch at blod if you don't like this :) */
send_to_char( "Gravoc's Pandect steels your sinews.\n\r", ch );
}
ch->max_hit += add_hp;
ch->max_mana += add_mana;
ch->max_move += add_move;
ch->practice += add_prac;
if( !IS_NPC( ch ) )
xREMOVE_BIT( ch->act, PLR_BOUGHT_PET );
if( ch->level == LEVEL_AVATAR )
{
DESCRIPTOR_DATA *d;
for( d = first_descriptor; d; d = d->next )
if( d->connected == CON_PLAYING && d->character != ch )
{
set_char_color( AT_IMMORT, d->character );
ch_printf( d->character, "%s has just achieved Avatarhood!\n\r", ch->name );
}
set_char_color( AT_WHITE, ch );
do_help( ch, "M_ADVHERO_" );
}
if( ch->level < LEVEL_IMMORTAL )
{
if( IS_VAMPIRE( ch ) )
snprintf( buf, MAX_STRING_LENGTH,
"Your gain is: %d/%d hp, %d/%d bp, %d/%d mv %d/%d prac.\n\r",
add_hp, ch->max_hit, 1, ch->level + 10, add_move, ch->max_move, add_prac, ch->practice );
else
snprintf( buf, MAX_STRING_LENGTH,
"Your gain is: %d/%d hp, %d/%d mana, %d/%d mv %d/%d prac.\n\r",
add_hp, ch->max_hit, add_mana, ch->max_mana, add_move, ch->max_move, add_prac, ch->practice );
set_char_color( AT_WHITE, ch );
send_to_char( buf, ch );
}
return;
}
I am not sure whether it is a null pointer or not. I would assume it is not, becuase i dont think the compiler/enviorment would allow the print of a null pointer. It could be that in the code null pointer is converted to the string "(null)", but if that is the case, then my the above function should work. I'm not really sure.
Well, the easiest thing to do at this point is to just print to log the value of "buf". I think the command would be something like: log_string(buf).
I get "Log: (null)" and in the nanny its also says "(null)". Is there anyway to find out what the character at [0] is? I think this could helpme. I tried using log_buff( buf[0] ), but it does not allow it.
OK, here's something I note: in my version of SMAUG, which is admittedly quite different from yours, set_title is called in nanny when the character is created/authed. The title is then set to "the %s".
Maybe your code also has more references to set_title outside of advance_level, in which case you'll have to hunt them down and introduce a similar check that you have inside advance_level.
Maybe your code also has more references to set_title outside of advance_level, in which case you'll have to hunt them down and introduce a similar check that you have inside advance_level.
void advance_level( CHAR_DATA * ch )
{
char buf[MAX_STRING_LENGTH];
int add_hp;
int add_mana;
int add_move;
int add_prac;
snprintf( buf, MAX_STRING_LENGTH, "%s" ,title_table[ch->Class][ch->level][ch->sex == SEX_FEMALE ? 1 : 0] );
if (buf[0] != '(')
set_title(ch, buf );
add_hp = con_app[get_curr_con( ch )].hitp + number_range( class_table[ch->Class]->hp_min,
class_table[ch->Class]->hp_max );
add_mana = class_table[ch->Class]->fMana ? number_range( 2, ( 2 * get_curr_int( ch ) + get_curr_wis( ch ) ) / 8 ) : 0;
add_move = number_range( 5, ( get_curr_con( ch ) + get_curr_dex( ch ) ) / 4 );
add_prac = wis_app[get_curr_wis( ch )].practice;
add_hp = UMAX( 1, add_hp );
add_mana = UMAX( 0, add_mana );
add_move = UMAX( 10, add_move );
.....
and
void set_title( CHAR_DATA * ch, char *title )
{
char buf[MAX_STRING_LENGTH];
if( IS_NPC( ch ) )
{
bug( "%s", "Set_title: NPC." );
return;
}
if( isalpha( title[0] ) || isdigit( title[0] ) )
{
buf[0] = ' ';
mudstrlcpy( buf + 1, title, MAX_STRING_LENGTH - 1 );
}
else
{
mudstrlcpy( buf, title, MAX_STRING_LENGTH );
}
if( str_cmp( buf, " the (null)" ) != 0 )
{
STRFREE( ch->pcdata->title );
ch->pcdata->title = STRALLOC( buf );
}
return;
}
This code fixed my problem. Thanks for all the help!
Well, be careful; now you can't have class titles that start with a parenthesis. You probably won't have any, but it's good to keep in mind... but it's good that at least the basics are working! :)
point well taken, but i could just use the following
and that should allow titles with parentheses. For my mud, players will recieve titles based off of thier class and completion of quests. I choose to do it this way becuase when i logged into 'Realms of Dispair', people had non-rping titles. Seriously, there were things like 'is a smelly butt' and other rediculous titles. Kind of ruins the point of titles in my opinion.
if( str_cmp( buf, "(null)" ) != 0 )and that should allow titles with parentheses. For my mud, players will recieve titles based off of thier class and completion of quests. I choose to do it this way becuase when i logged into 'Realms of Dispair', people had non-rping titles. Seriously, there were things like 'is a smelly butt' and other rediculous titles. Kind of ruins the point of titles in my opinion.