| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
| OK, now that Kris has sent me the code, I'll comment here on what happened, so it will hopefully help others as well as Kris.
What he had done was put the messages into do_mptransformcat like this:
void do_mptransformcat ( CHAR_DATA *ch, char *argument )
{
char arg[MAX_STRING_LENGTH];
CHAR_DATA *victim;
int level;
int iLevel;
int iLang;
CHAR_DATA *tempchb=ch;
char *tempvictimb=argument;
if ( !IS_NPC( ch ) || IS_AFFECTED( ch, AFF_CHARM ))
{
send_to_char( "Huh?\n\r", ch );
return;
}
argument = one_argument( argument, arg );
if ( arg[0] == '\0' )
{
progbug( "Mptransform - Bad syntax", ch );
return;
}
if ( ( victim = get_char_room( ch, arg ) ) == NULL )
{
progbug( "Mptransform - Victim not there", ch );
return;
}
if ( IS_NPC(victim) )
{
progbug( "Mptransform - Victim is NPC", ch );
return;
}
if ( ( victim->tempch != tempchb ) || ( victim->tempvictim != tempvictimb )
)
{
victim->tempch = tempchb;
victim->tempvictim = tempvictimb;
}
/*
To remember where in the message sequence the player is; part of the institution
of a delay
--Kris
*/
if ( victim->tempwaitb >=1 && victim->tempwaitb <=23 )
{
switch ( victim->tempwaitb )
{
case 1:
send_to_char( "\nWhat the bloody hell?!\n", victim );
TEMPWAIT_STATE(victim, 20);
break;
case 2:
send_to_char( "\n\n\nA vast, open field flashes before your eyes....\n",
victim );
TEMPWAIT_STATE(victim, 20);
break;
case 3:
send_to_char( "\nYou are standing in this field....\n", victim );
TEMPWAIT_STATE(victim, 20);
break;
case 4:
send_to_char( "\nYour ears perk-up, your eyes focus, and you crouch down
low in the grass....\n", victim );
TEMPWAIT_STATE(victim, 20);
break;
... and so on ...
if ( victim->race == RACE_CAT )
{
send_to_char( "A mystical voice says: You're already a cat, you mook!\n",
victim );
return;
}
send_to_char( "\n\nYou start to feel a strange sensation in your body....\n"
, victim );
TEMPWAIT_STATE(victim, 20);
victim->tempwaitb = 1;
victim->tempwaitc = 1;
return;
}
The problem with this is that do_mptransformcat is only called once by the mob, and thus that the sequence of messages won't be displayed.
However he tried to work around this by re-calling do_mptransformcat from the main game_loop ...
if ( FD_ISSET( d->descriptor, &in_set ) )
{
d->idle = 0;
if ( d->character )
d->character->timer = 0;
if ( !read_from_descriptor( d ) )
{
FD_CLR( d->descriptor, &out_set );
if ( d->character
&& ( d->connected == CON_PLAYING
|| d->connected == CON_EDITING ) )
save_char_obj( d->character );
d->outtop = 0;
close_socket( d, FALSE );
continue;
}
}
if ( d->character && d->character->wait > 0 )
{
--d->character->wait;
continue;
}
if ( d->character && d->character->tempwait > 0 )
{
--d->character->tempwait;
write_to_descriptor( d->descriptor,
"debug1.\n\r", 0 );
if (d->character->tempwait < 1)
{
write_to_descriptor( d->descriptor,
"debug2.\n\r", 0 );
/* if (d->character->tempwaitc == 1) */
do_mptransformcat(d->character->tempch, d->character->tempvictim);
}
continue;
}
read_from_buffer( d );
I can see what he is trying to do here, but I think that this approach is doomed to failure, particularly when do_mptransformcat is recalled from the game loop, because he has had to "dummy up" the arguments to do_mptransformcat, which then eventually gives the error messages that he reported.
My approach would be to split the delayed messages into a totally different routine, because you are really doing two things here:
- Initiating the transformation into a cat
- Displaying a message to the player every second or so
Thus, I have only the following code in do_mptransformcat:
void do_mptransformcat ( CHAR_DATA *ch, char *argument )
{
char arg[MAX_STRING_LENGTH];
CHAR_DATA *victim;
if ( !IS_NPC( ch ) || IS_AFFECTED( ch, AFF_CHARM ))
{
send_to_char( "Huh?\n\r", ch );
return;
}
argument = one_argument( argument, arg );
if ( arg[0] == '\0' )
{
progbug( "Mptransformcat - Bad syntax", ch );
return;
}
if ( ( victim = get_char_room( ch, arg ) ) == NULL )
{
progbug( "Mptransformcat - Victim not there", ch );
return;
}
if ( IS_NPC(victim) )
{
progbug( "Mptransformcat - Victim is NPC", ch );
return;
}
if ( victim->race == RACE_CAT )
{
send_to_char( "A mystical voice says: You're already a cat, you mook!\n", victim );
return;
}
send_to_char( "\n\nYou start to feel a strange sensation in your body....\n", victim );
victim->tempwait = 1; /* initiate message sequence */
}
Basically I deleted all the message stuff (and pasted elsewhere) - the only thing left, to initiate the messages to the player, is setting the tempwait flag to 1 (shown in bold), which means that message number 1 is due to be shown to the player.
Now we make another function "special_messages" that will display the messages in sequence (adding 1 to tempwait each time). When we get to the end of the sequence we set tempwait to zero to indicate that we have finished.
void special_messages (CHAR_DATA *ch)
{
int iLang;
switch ( ch->tempwait++ )
{
case 1:
send_to_char( "\nWhat the bloody hell?!\n", ch );
break;
case 2:
send_to_char( "\n\n\nA vast, open field flashes before your eyes....\n", ch );
break;
case 3:
send_to_char( "\nYou are standing in this field....\n", ch );
break;
... and so on ...
case 22:
send_to_char( "\n\nYou have been transformed into a CAT!!\n", ch );
ch->tempwait = 0; /* no more messages */
break;
} /* end of switch */
}
The remaining trick is to call this function each second, which can be easily done by following what game_loop does. Amongst other things, it calls "update_handler", which calls "char_check" every second.
Some way into char_check, after deciding that we have a player and not a mob, we add a couple of lines:
if (ch->tempwait)
special_messages (ch); /* extra messages for Kris */
Finally, we need to zero out ch->tempwait when a player connects, otherwise if it happened to have a non-zero value when a player connected, they might start seeing messages about turning into a cat ...
add_char( ch );
d->connected = CON_PLAYING;
ch->tempwait = 0;
I will send the complete changes to Kris as a patchfile, hopefully he will be able to get his messages working, and the technique could be used for other muds as well.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|