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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Do_Look
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Sat 13 Oct 2001 01:49 PM (UTC) Amended on Sat 13 Oct 2001 01:51 PM (UTC) by Kelsid
|
Message
| This message is a continuation of my previous messages listed in Compiling the Smaug Server:
Ok.... Heres my situation now.... its good... I got all of the objects, and mobiles/pc's to be listed under the room discriptions with comma's
Well.... I added what I thought was a simple IF statement (to add the text "You also see") if there were any objects/mobs in the room.
Well... I messed something up.
Heres the relevant code:
act_info.c
(do_look function)
if ( arg1[0] == '\0'
|| ( !IS_NPC(ch) && !xIS_SET(ch->act, PLR_BRIEF) ) )
{
send_to_char( MXPTAG ("rdesc"), ch);
send_to_char( ch->in_room->description, ch );
send_to_char( MXPTAG ("/rdesc"), ch);
/* Altered Room Descriptions */
if(ch->in_room->first_content != NULL || ( ch->in_room->first_person != NULL ) )
send_to_char("You also see ", ch);
return;
send_to_char( "\n\r", ch );
show_list_to_char( ch->in_room->first_content, ch, FALSE, FALSE, eItemGet );
show_char_to_char( ch->in_room->first_person, ch );
}
if ( !IS_NPC(ch) && xIS_SET(ch->act, PLR_AUTOMAP) ) /* maps */
{
if(ch->in_room->map != NULL)
{
do_lookmap(ch, NULL);
}
}
if ( !IS_NPC(ch) && xIS_SET(ch->act, PLR_AUTOEXIT) )
do_exits( ch, "auto" );
return;
}
Ok... now... when I do a look in a room, I get the following:
Ex.
[Mercuria, East Plaza]
Fairly expensive wares clutter this area of the plaza. Guards are particularly mindful to watch this area.
You also see
<1014hp 500m 734mv> (Invis 65)
Now.... There are two objects in the room (and one mobile). I know the problem is my IF statement. But Im still kinda new at C, and really havnt had formal (or non-formal) training. It would be a really big help if someone could tell me what Im doing wrong.
Kelsid |
-Kelsid | Top |
|
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Reply #1 on Sat 13 Oct 2001 04:59 PM (UTC) |
Message
| Nevermind.... It helps if you look at the output... then look at the code... Who would have thought... :)
Ok.... I found out that my problem was the return that was in there. I got everything working now. Ok... next task.. when im listing the mobs. How would I go about adding a "and" for the last item listed, as well as a period.
ex.
You also see: a hobgoblin, a kobold , and Kelsid.
My first thought would to look once again in the show_char_to_char_0 function.
just before my statement (the one seperating the names by a comma, instead of the normal spaces). Mabey put an IF in there... something like if it is the last victim in the room to place an "and" before it, and a period after it. Now... if someone could tell me how to make C understand that... The help would be appreciated.
Kelsid |
-Kelsid | Top |
|
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Reply #2 on Sat 13 Oct 2001 05:21 PM (UTC) |
Message
| Ok... I was just looking at the code, and came to a thought. I ended up going back to the show_char_to_char function, and noticed code for putting the mobs names into the buffer.
Heres the code:
void show_char_to_char( CHAR_DATA *list, CHAR_DATA *ch )
{
CHAR_DATA *rch;
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
{
show_char_to_char_0( rch, ch );
}
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
{
set_char_color( AT_BLOOD, ch );
send_to_char( "The red form of a living creature is here.\n\r", ch );
}
}
return;
}
Ok.... Now... Would it be vaild for me to make a statement like....
If ( rch->next_in_room = NULL)
strcat( buf, "." );
That would take care of the period at the end of the list, but would that also add a period in rooms with no mobs? More imporantly it still wouldnt add the "and" before the last mob. Anyways, This is a touchy function, and Id like to plan it out as best as I can. Please feel free to give me your input (tell me if Im gonna break something), as it is greatly appreciated. Im starting to realize that if you just stare at the code long enough, it starts to make sense.
Thanks for your help,
Kelsid |
-Kelsid | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 13 Oct 2001 09:56 PM (UTC) |
Message
| That would probably only partially work. For instance there is a test that skips showing yourself (if ( rch == ch )) and if you happened to be the last person in the room list then the period and "and" would be discarded. There is a similar problem with invisible characters.
What I would do is go through the list twice, the first time just counting the number you are planning to show (ie, do the IF tests but rather that doing strcat just add one to a counter (eg. count++ ).
Then the second time, you have another counter (count2) and now you know when you are at the end of the list (count == count2). Also, if count is zero, you know to omit any reference to "you see ...".
Doing the "and" is simple then, *before* you strcat the name of the last person you strcat in the word "and", and *after* it you strcat the period.
However, if the count is one, ie. only one thing in the room, then you skip adding the word "and".
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Reply #4 on Sun 14 Oct 2001 08:44 AM (UTC) |
Message
| Thanks for the reply Nick,
Ok... Ive read your posting 6 times now.. I understand exactly what your saying. But as I have forementioned, Im not exactly a C expert. The only part I dont know how to execute is the count that you were speaking of. Would I do that in the send_char_to_char function, or the send_char_to_char_0 one?
Thanks again,
Kelsid
|
-Kelsid | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #5 on Sun 14 Oct 2001 10:23 PM (UTC) |
Message
| I would probably change show_char_to_char like this, my changes in bold:
void show_char_to_char( CHAR_DATA *list, CHAR_DATA *ch )
{
CHAR_DATA *rch;
int count = 0;
/* Count visible characters */
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
count++;
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
count++;
}
/* Now go through the list again showing each name */
return;
}
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Reply #6 on Tue 16 Oct 2001 02:31 AM (UTC) |
Message
| Thanks Nick, Hes my code right now:
void show_char_to_char( CHAR_DATA *list, CHAR_DATA *ch )
{
CHAR_DATA *rch;
int count = 0;
int count2 = 0;
/* Count visible characters, Thanks Nick Gammon */
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
count++;
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
count++;
}
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
{
count2++;
if (count == 1)
{
show_char_to_char_0( rch, ch );
ch_printf( ch, "." );
}
if (count2 < count && count != 1)
{
show_char_to_char_0( rch, ch );
ch_printf( ch, ", " );
}
if ( count2 == count && count != 1)
{
ch_printf( ch, "and " );
show_char_to_char_0( rch, ch );
ch_printf( ch, "." );
}
}
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
{
set_char_color( AT_BLOOD, ch );
send_to_char( "The red form of a living creature is here.\n\r", ch );
}
}
return;
}
Ok... heres the deal... I was having some major problems with Mobiles. First of all, it was capitalizing the first letter of every name (I searched forever for the toupper string) and it somehow used a \n\r. I solved that by calling the short discription (instead of the long one). It works great now. I have one small problem though. I would like it to say "You also see:\r\n" If there is one person (other than yourself) in the room. Im having problems though. If I try to put the code in the above statement, it repeats the "You also see:" code for every person. I can get the rest on my own. I just wanted to thank you again. Also as soon as I complete the rest of the code, Ill post it up here. It looks alot cleaner than the old code.
-Kelsid
|
-Kelsid | Top |
|
Posted by
| Kelsid
USA (35 posts) Bio
|
Date
| Reply #7 on Tue 16 Oct 2001 02:57 AM (UTC) |
Message
| Ok,
Heres what I finally came up with.
void show_char_to_char( CHAR_DATA *list, CHAR_DATA *ch )
{
CHAR_DATA *rch;
int count = 0;
int count2 = 0;
/* Count visible characters, Thanks Nick Gammon */
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
count++;
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
count++;
}
if (count != 0)
send_to_char("Also here:\n\r", ch);
for ( rch = list; rch; rch = rch->next_in_room )
{
if ( rch == ch )
continue;
if ( can_see( ch, rch ) )
{
count2++;
if (count == 1)
{
show_char_to_char_0( rch, ch );
ch_printf( ch, "." );
}
if (count2 < count && count != 1)
{
show_char_to_char_0( rch, ch );
ch_printf( ch, ", " );
}
if ( count2 == count && count != 1)
{
ch_printf( ch, "and " );
show_char_to_char_0( rch, ch );
ch_printf( ch, "." );
}
}
else if ( room_is_dark( ch->in_room )
&& IS_AFFECTED(rch, AFF_INFRARED )
&& !(!IS_NPC(rch) && IS_IMMORTAL(rch)) )
{
count2++;
if (count == 1)
{
set_char_color( AT_BLOOD, ch );
send_to_char( "a red outline", ch );
}
if (count2 < count && count != 1)
{
set_char_color( AT_BLOOD, ch );
send_to_char( "a red outline", ch );
ch_printf( ch, ", " );
}
if ( count2 == count && count != 1)
{
set_char_color( AT_BLOOD, ch );
send_to_char( "and a red outline.", ch );
}
}
}
return;
}
Ok... It does everything I wanted it to. I just wanted to post it up here if anyone else wanted to use it. Im working on making the objects list in a simmilar fashion. Thanks Nick for pointing me in the right direction.
-Kelsid
|
-Kelsid | 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.
22,157 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top