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, 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 ➜ Null Titles

Null Titles

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


Pages: 1 2  

Posted by Malti   USA  (55 posts)  Bio
Date Tue 25 Apr 2006 05:18 AM (UTC)
Message
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.
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #1 on Tue 25 Apr 2006 01:55 PM (UTC)
Message
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.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #2 on Tue 25 Apr 2006 02:25 PM (UTC)

Amended on Tue 25 Apr 2006 07:14 PM (UTC) by Malti

Message
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?
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Tue 25 Apr 2006 04:10 PM (UTC)

Amended on Tue 25 Apr 2006 04:11 PM (UTC) by David Haley

Message
Find the part:
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("");
}
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. :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #4 on Tue 25 Apr 2006 08:39 PM (UTC)
Message
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


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'?
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #5 on Tue 25 Apr 2006 09:13 PM (UTC)
Message
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.


Wrong. Their title would be blank. The two quotes with nothing inbetween is a blank string.

Quote:

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.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #6 on Tue 25 Apr 2006 09:49 PM (UTC)
Message
Didn't work :(
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Tue 25 Apr 2006 10:49 PM (UTC)
Message
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?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #8 on Wed 26 Apr 2006 12:57 AM (UTC)
Message
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,


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?
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #9 on Wed 26 Apr 2006 01:13 AM (UTC)
Message
OK. Where did you put that code? Is that in set_title, or somewhere else?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #10 on Wed 26 Apr 2006 01:33 AM (UTC)
Message
Quote:
So what i changed was the advance_level
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #11 on Wed 26 Apr 2006 01:43 AM (UTC)
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #12 on Wed 26 Apr 2006 01:50 AM (UTC)

Amended on Wed 26 Apr 2006 01:53 AM (UTC) by Malti

Message
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.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #13 on Wed 26 Apr 2006 02:13 AM (UTC)
Message
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)".

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Malti   USA  (55 posts)  Bio
Date Reply #14 on Wed 26 Apr 2006 02:32 AM (UTC)
Message

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.
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.


49,178 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.