Need a little help getting SEARCH to work right

Posted by Toy on Fri 06 Feb 2004 10:20 PM — 7 posts, 23,354 views.

#0
[code]
void do_search( CHAR_DATA *ch, char *argument )
{
char arg [MAX_INPUT_LENGTH];
OBJ_DATA *obj;
OBJ_DATA *container;
OBJ_DATA *startobj;
int percent, door;

door = -1;
switch( ch->substate )
{
default:
if ( IS_NPC(ch) && IS_AFFECTED( ch, AFF_CHARM ) )
{
send_to_char( "You can't concentrate enough for that.\n\r", ch );
return;
}
if ( ch->mount )
{
send_to_char( "You can't do that while mounted.\n\r", ch );
return;
}
argument = one_argument( argument, arg );
if ( arg[0] != '\0' && (door = get_door( arg )) == -1 )
{
container = get_obj_here( ch, arg );
if ( !container )
{
send_to_char( "You can't find that here.\n\r", ch );
return;
}
if ( container->item_type != ITEM_CONTAINER )
{
send_to_char( "You can't search in that!\n\r", ch );
return;
}
if ( IS_SET(container->value[1], CONT_CLOSED) )
{
send_to_char( "It is closed.\n\r", ch );
return;
}
}
// add_timer( ch, TIMER_DO_FUN, UMIN(skill_table[gsn_search]->beats / 10, 3),
// do_search, 1 );
send_to_char( "You begin your search...\n\r", ch );
ch->alloc_ptr = str_dup( arg );
return;

case 1:
if ( !ch->alloc_ptr )
{
send_to_char( "Your search was interrupted!\n\r", ch );
bug( "do_search: alloc_ptr NULL", 0 );
return;
}
strcpy( arg, ch->alloc_ptr );
DISPOSE( ch->alloc_ptr );
break;
case SUB_TIMER_DO_ABORT:
DISPOSE( ch->alloc_ptr );
ch->substate = SUB_NONE;
send_to_char( "You stop your search...\n\r", ch );
return;
}
ch->substate = SUB_NONE;
if ( arg[0] == '\0' )
startobj = ch->in_room->first_content;
else
{
if ( (door = get_door( arg )) != -1 )
startobj = NULL;
else
{
container = get_obj_here( ch, arg );
if ( !container )
{
send_to_char( "You can't find that here.\n\r", ch );
return;
}
startobj = container->first_content;
}
}

if ( (!startobj && door == -1) || IS_NPC(ch) )
{
send_to_char( "You find nothing.\n\r", ch );
// learn_from_failure( ch, gsn_search );
return;
}

percent = number_percent( ) + number_percent( ) - ( ch->level / 10 );

if ( door != -1 )
{
EXIT_DATA *pexit;

if ( (pexit = get_exit( ch->in_room, door )) != NULL
&& IS_SET( pexit->exit_info, EX_SECRET )
&& IS_SET( pexit->exit_info, EX_xSEARCHABLE ) )
// && can_use_skill( ch, percent, gsn_search ) )
{
act( AT_SKILL, "Your search reveals the $d!", ch, NULL, pexit->keyword, TO_CHAR );
act( AT_SKILL, "$n finds the $d!", ch, NULL, pexit->keyword, TO_ROOM );
REMOVE_BIT( pexit->exit_info, EX_SECRET );
// learn_from_success( ch, gsn_search );
return;
}
}
else
for ( obj = startobj; obj; obj = obj->next_content )
{
if ( IS_OBJ_STAT( obj, ITEM_HIDDEN ) )
// && can_use_skill(ch, percent, gsn_search ) )
{
separate_obj(obj);
xREMOVE_BIT( obj->extra_flags, ITEM_HIDDEN );
act( AT_SKILL, "Your search reveals $p!", ch, obj, NULL, TO_CHAR );
act( AT_SKILL, "$n finds $p!", ch, obj, NULL, TO_ROOM );
// learn_from_success( ch, gsn_search );
return;
}
}

send_to_char( "You find nothing.\n\r", ch );
// learn_from_failure( ch, gsn_search );
return;
}
[/code]
Canada #1
Uhhhh, whats the problem? A bunch of code makes it hard to know where to look. Is it crashing? Is it always failing? Perhaps your getting a bug message?
#2
OK, what I'm trying to do is alter the code so instead of players needing to practice search over and over, it just because a normal command. I made the changes above, recompiled clean, and started the mud up. Here's the thing: the command now works... it just doesn't finish the search. You see this:

You begin your search...

But then it looks like it just totally aborts the search. Can someone gimme some help on what I'm doing wrong?

-Toy
Canada #3
Yeah, I think I see the problem.
send_to_char( "You begin your search...\n\r", ch );
ch->alloc_ptr = str_dup( arg );
return;


This return will just end it. What would normally happen is it would return after the timer was added, but since you commented it out, it won't do anything, it will just end. You options are put the timer back, but make it use, perhaps, 5 as the beats value to pass, or to add a wait_state, and have it work instantly, but they be delayed.
#4
OK... need help with those options. I see that the time calls to the skill_table for the previous skill search. HOw can I change that so it won't, or how do I make a wait_state? Never done that before.

-Toy
Canada #5
Well, if you uncomment the add_timer function, you can do something simple like this:

 add_timer( ch, TIMER_DO_FUN, 4 , do_search, 1 );


That should work.
Amended on Fri 06 Feb 2004 10:40 PM by Greven
#6
Ah... there we go. Cool. Thanks. Now I'm gonna attempt to tackle do_scan. See if I can get my last issue with that one fixed so an arguement isn't needed when using scan. Tried to remove the arguement calls and segment faulted. ;p

-Toy