02 Nov, 2012, arholly wrote in the 1st comment:
Votes: 0
Hi there:
My exits command is jacked up. When I use it, it gives me:
Quote
exits
Obvious exits from room 4001:
Nor (rEas (rSou (rWes (r


What is wrong?

void do_exits( CHAR_DATA *ch, char *argument )
{
extern char * const dir_name[];
char buf[MSL]={'\0'};
EXIT_DATA *pexit;
bool found = FALSE;
bool fAuto;
int door = 0;
ROOM_INDEX_DATA *looking;

CheckCH(ch);

fAuto = !str_cmp( argument, "auto" );

if ( !check_blind( ch ) )
return;

if(IS_SET(ch->act2, ACT2_ASTRAL))
{
looking = ch->listening;
}
else
{
looking = ch->in_room;
}

if (fAuto)
{
send_to_char("[\tCExits:\tn", ch);
}
else if (IS_ADMIN(ch))
{
send_to_char(Format("\tCObvious exits from room %d:\tn\n\r",looking->vnum), ch);
}
else
{
send_to_char("\tCObvious exits:\tn\n\r", ch);
}

for ( door = 0; door <= 5; door++ )
{
if(!IS_ADMIN(ch))
{
if ( ( pexit = looking->exit[door] ) != NULL
&& pexit->u1.to_room != NULL
&& can_see_room(ch,pexit->u1.to_room)
&& !IS_SET(pexit->exit_info, EX_HIDDEN))
{
found = TRUE;
if ( fAuto )
{
if( !IS_SET(pexit->exit_info, EX_WINDOW) )
{
strncat( buf, " ", sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_HIDDEN) )
strncat( buf, "\tR-", sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_CLOSED) )
strncat( buf, "(", sizeof(buf) );
strncat( buf, dir_name[door], sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_CLOSED) )
strncat( buf, ")", sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_HIDDEN) )
strncat( buf, "-\tn", sizeof(buf) );
}
else
{
strncat( buf, " <", sizeof(buf) );
strncat( buf, dir_name[door], sizeof(buf) );
strncat( buf, ">", sizeof(buf) );
}
}
else
{
if(!IS_SET(pexit->exit_info, EX_HIDDEN))
{
snprintf( buf + strlen(buf), sizeof(buf + strlen(buf)), "%-5s - %s",
capitalize( dir_name[door] ),
room_is_dark( pexit->u1.to_room )
? "Too dark to tell"
: pexit->u1.to_room->name
);
if (IS_ADMIN(ch))
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), " (room %d)\n\r",pexit->u1.to_room->vnum);
else
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), "\n\r");
}
}
}
}
else
{
if ( ( pexit = looking->exit[door] ) != NULL
&& pexit->u1.to_room != NULL
&& can_see_room(ch,pexit->u1.to_room) )
{
found = TRUE;
if ( fAuto )
{
strncat( buf, " ", sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_WINDOW) )
strncat( buf, "<", sizeof(buf) );
else if( IS_SET(pexit->exit_info, EX_CLOSED) )
{
if( IS_SET(pexit->exit_info, EX_HIDDEN) )
strncat( buf, "\tR-(", sizeof(buf) );
else
strncat( buf, "(", sizeof(buf) );
}
strncat( buf, dir_name[door], sizeof(buf) );
if( IS_SET(pexit->exit_info, EX_WINDOW) )
strncat( buf, ">", sizeof(buf) );
else if( IS_SET(pexit->exit_info, EX_CLOSED) )
{
if( IS_SET(pexit->exit_info, EX_HIDDEN) )
strncat( buf, ")-\tn", sizeof(buf) );
else
strncat( buf, ")", sizeof(buf) );
}
}
else
{
snprintf( buf + strlen(buf), sizeof(buf + strlen(buf)), "%-5s - %s",
capitalize( dir_name[door] ),
room_is_dark( pexit->u1.to_room )
? "Too dark to tell"
: pexit->u1.to_room->name
);
if (IS_ADMIN(ch))
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), " (room %d)\n\r",pexit->u1.to_room->vnum);
else
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), "\n\r");
}
}
}
}

if ( !found )
strncat( buf, fAuto ? " none" : "None.\n\r", sizeof(buf) );

if ( fAuto )
strncat( buf, "]\n\r", sizeof(buf) );

send_to_char( buf, ch );
send_to_char( "", ch );
return;
}
02 Nov, 2012, Davion wrote in the 2nd comment:
Votes: 0
if (IS_ADMIN(ch))
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), " (room %d)\n\r",pexit->u1.to_room->vnum);
else
snprintf(buf + strlen(buf), sizeof(buf + strlen(buf)), "\n\r");


This is all kinds of wrong. You really should create a temp buffer (ie. buf2) sprintf() your roomvnums into it, then strcat it to buf.
02 Nov, 2012, arholly wrote in the 3rd comment:
Votes: 0
Unlikely. Because when you are in a room (moving or looking), it shows the exits:
Quote
[Exits: north east south west]


char *	const	dir_name	[]		=
{
"north", "east", "south", "west", "up", "down"
};


Cross-posting.:)
02 Nov, 2012, Davion wrote in the 4th comment:
Votes: 0
arholly said:
Unlikely. Because when you are in a room (moving or looking), it shows the exits:
Quote
[Exits: north east south west]


char *	const	dir_name	[]		=
{
"north", "east", "south", "west", "up", "down"
};


Cross-posting.:)


…You're quick :D I edited my original.
02 Nov, 2012, arholly wrote in the 5th comment:
Votes: 0
So are you.
02 Nov, 2012, arholly wrote in the 6th comment:
Votes: 0
Poke on AIM.
02 Nov, 2012, Rarva.Riendf wrote in the 7th comment:
Votes: 0
My code, if you ever want to get a little more stuff done with exits.
It allows to have the same exit string in the prompt than in look.
Why could it be different ? well because I implemented a detect invis door (that may give a random result), so I needed that the method return the same result when called once for the look, and once for prompt
just need a ch->pcdata->lastExits char* that you dont need to save.

bool_t do_exits(CHAR_DATA *ch, char *argument) {
send_to_char(get_exits(ch, NULL, argument), ch);
return TRUE;
}

/*
* We look for exits even it is an autoexit stuff to fire the skill detect doors
* if there is a room as parameter, use it instead of ch->in_room
*/
char *get_exits(CHAR_DATA *ch, ROOM_INDEX_DATA* initRoom, char *argument) {
initRoom = initRoom ? initRoom : ch ? ch->in_room : NULL;
if (!initRoom)
return NULL;
bool_t fAuto = !str_cmp(argument, "auto");
bool_t fPrompt = !str_cmp(argument, "prompt");

if (ch && !can_look(ch, !fPrompt)) {
if (ch->pcdata)
replace_string( &ch->pcdata->lastExits, "###");
return fPrompt ? "###" : NULL;
}

if (ch && ch->pcdata && fPrompt && ch->pcdata->lastRoomVnum == initRoom->vnum && str_cmp("###", ch->pcdata->lastExits))
return ch->pcdata->lastExits;

static char bufAuto[MAX_STRING_LENGTH];
sprintf(bufAuto, "%s[Exits:", get_color_ch(ch, COL_EXITS));
static char bufCommand[MAX_STRING_LENGTH];
if (ch && IS_IMMORTAL(ch))
sprintf(bufCommand, "Obvious exits from room %d:\n\r", initRoom->vnum);
else
sprintf(bufCommand, "Obvious exits:\n\r");
static char bufPrompt[MAX_STRING_LENGTH];
bufPrompt[0] = '\0';

bool_t found = FALSE, success = TRUE;
EXIT_DATA *pexit;
short int door;
for (door = 0;door < MAX_DIR;door ++) {
pexit = initRoom->exit[door];
if ( !pexit || !pexit->u1.to_room || !can_see_room(ch, pexit->u1.to_room))
continue;

if (IS_SET(pexit->exit_info, EX_INVISIBLE)) {
success = !ch || IS_IMP(ch) ? TRUE : rnd_rng(99) < (get_skill(ch, gsn_detect_doors) * (double)2 / 3);
if (success) {
strcat(bufAuto, get_acolor_ch(ch, C_RED));
strcat(bufPrompt, get_acolor_ch(ch, C_RED));
strcat(bufCommand, get_acolor_ch(ch, C_RED));
}
check_improve(ch, gsn_detect_doors, success, 16 * (success ? 1 : 2));
if ( !success)
continue;
}
else {
char* exitColor = IS_SET(pexit->exit_info, EX_CLOSED) ? get_color_ch(ch,COL_OBJ) : IS_SET(pexit->rs_flags, EX_ISDOOR) ? CC_GRN : get_color_ch(ch,COL_EXITS);
strcat(bufAuto, exitColor);
strcat(bufPrompt, exitColor);
strcat(bufCommand, exitColor);
}

found = TRUE;

sprintf(bufAuto, "%s \t(%s\t)", bufAuto, dir_name[door]);
sprintf(bufPrompt, "%s\t(%s\t)", bufPrompt, short_dir_name[door]);
sprintf(bufCommand, "%s\t(%-5s%s\t) - %s", bufCommand, capitalize(dir_name[door]),
room_is_dark(ch, pexit->u1.to_room) ? get_acolor_ch(ch, C_GRY) : get_color_ch(ch, COL_NORM),
room_is_dark(ch, pexit->u1.to_room) ? "Too dark to tell" : pexit->u1.to_room->name);
if (ch && IS_IMMORTAL(ch))
sprintf(bufCommand, "%s (vnum:%d)", bufCommand, pexit->u1.to_room->vnum);
strcat(bufCommand, ".\n\r");
}
strcat(bufAuto, get_color_ch(ch, COL_EXITS));
strcat(bufCommand, get_color_ch(ch, COL_EXITS));
strcat(bufPrompt, get_color_ch(ch, COL_EXITS));

if ( !found) {
strcat(bufAuto, " none");
strcat(bufPrompt, "none");
strcat(bufCommand, "None.");
}

sprintf(bufAuto, "%s]%s\n\r", bufAuto, get_color_ch(ch, COL_NORM));
sprintf(bufCommand, "%s%s\n\r", bufCommand, get_color_ch(ch, COL_NORM));
strcat(bufPrompt, get_color_ch(ch, COL_PROMPT));
if (ch && ch->pcdata) {
replace_string( &ch->pcdata->lastExits, bufPrompt);
ch->pcdata->lastRoomVnum = initRoom->vnum;
}
return fAuto ? ( ch && !IS_SET(ch->act, PLR_AUTOEXIT) ? NULL : bufAuto) : fPrompt ? bufPrompt : bufCommand;
}
0.0/7