ok on the mud I am making I pulled the locker code out of my old source and put it into my new source. The problem I am having is that if there are other objects laying in the floor of the room that the locker is in, then it writes those items to the locker files as well, then when a player opens the locker, you get a log message in the mud. I.E. 3 items on the floor when closed desk chair and rug. close locker... writes it to file, open locker:
LOG UNKNOWN LOCKER
LOG UNKNOWN LOCKER
LOG UNKNOWN LOCKER
You open your locker.
Here is the code that handles this process:
act(AT_ACTION, "$n opens $s locker.",ch, NULL, NULL, TO_ROOM);
act(AT_ACTION, "You open your locker.",ch, NULL, NULL, TO_CHAR);
}
else if( !str_cmp( arg, "close" ) )<-----From here down is the code that controls the saving of the locker
{
for( locker = ch->in_room->first_content; locker ; locker = locker->next_content )
{
if ( !str_cmp(locker->name, ch->name) ) break;
}
if (!locker)
{
send_to_char("That locker is not open.nr",ch);
return;
}
else
{
act(AT_ACTION, "$n closes the locker.",ch, NULL, NULL, TO_ROOM);
act(AT_ACTION, "You close the locker.", ch, NULL, NULL, TO_CHAR);
fwrite_locker( ch, locker );
extract_obj(locker);
}
}
return;
}
void fwrite_locker( CHAR_DATA *ch, OBJ_DATA *locker )
{
/* Variables */
FILE *fp = NULL;
char strsave[MAX_INPUT_LENGTH];
char tch[MSL];
if( !locker )
{
sprintf(tch, "Fwrite_locker: NULL object: %s", ch->name);
log_string( tch );
return;
}
send_to_char("CHECK POINT FOURnr",ch);
sprintf( strsave, "%s%s", LOCKER_DIR, capitalize( ch->name ) );
if ( ( fp = fopen( strsave, "w" ) ) != NULL )
{
fwrite_obj( ch, locker, fp, 0, OS_LOCKER, FALSE );
fprintf( fp, "#END nr" );
fclose( fp );
}
return;
}
I put the check points in there so I could see what was happening. I'm not the best with loops yet.. but I am getting there.. I was inclined to think that I needed to separate_obj for the locker but that failed miserably for me.. could be that I did it wrong... Any suggests would be great. |