Cool_do_say.txt
snippets · 5.0 KB · 2010-03-30
Replacement do_say for CircleMUD that shows facial expressions and other flavor, public domain.
Download « Back to the snippets list
No credit wanted or needed, not at fault if this wrecks your stuff.
Replace your do_say with this first:
ACMD(do_say)
{
int face = 0;
int state;
char buf[MAX_INPUT_LENGTH];
char buf2[MAX_INPUT_LENGTH];
skip_spaces(&argument);
if (!*argument) {
send_to_char(ch, "What do you want to say?\r\n");
return;
}
sprintf(buf, "$n");
sprintf(buf2, "You");
if (strstr(argument, ":)") != NULL) {
face = 1;
}
else if (strstr(argument, ";)") != NULL) {
face = 2;
}
else if (strstr(argument, ";(") != NULL) {
face = 3;
}
else if (strstr(argument, ":(") != NULL) {
face = 3;
}
else if (strstr(argument, ":O") != NULL) {
face = 4;
}
else if (strstr(argument, ":P") != NULL) {
face = 5;
}
search_replace(argument, " :)", "");
search_replace(argument, " ;)", "");
search_replace(argument, " ;(", "");
search_replace(argument, " :(", "");
search_replace(argument, " :O", "");
search_replace(argument, " :P", "");
search_replace(argument, ":)", "");
search_replace(argument, ";)", "");
search_replace(argument, ";(", "");
search_replace(argument, ":(", "");
search_replace(argument, ":O", "");
search_replace(argument, ":P", "");
if (!*argument) {
send_to_char(ch, "What do you wish to say?\r\n");
return;
}
if (argument[strlen(argument)-1] != '.' && argument[strlen(argument)-1]$
&& argument[strlen(argument)-1] != '!')
strcat(argument, ".");
if(strstr(argument, "?") != NULL)
state = 1;
else if(strstr(argument, "!") != NULL)
state = 2;
else
state = 0;
switch(face) {
case 0:
sprintf(buf + strlen(buf), " ");
sprintf(buf2 + strlen(buf2), " ");
break;
case 1: // :)
sprintf(buf + strlen(buf), " smiles and ");
sprintf(buf2 + strlen(buf2), " smile and ");
break;
case 2: // ;)
sprintf(buf + strlen(buf), " winks and ");
sprintf(buf2 + strlen(buf2), " wink and ");
break;
case 3: // :( or ;(
sprintf(buf + strlen(buf), " frowns and ");
sprintf(buf2 + strlen(buf2), " frown and ");
break;
case 4: // :O
sprintf(buf + strlen(buf), " looks shocked and ");
sprintf(buf2 + strlen(buf2), " look shocked and ");
break;
case 5: // :P
sprintf(buf + strlen(buf), " laugh and ");
sprintf(buf2 + strlen(buf2), " laugh and ");
break;
default:
break;
}
switch(state) {
case 1:
sprintf(buf + strlen(buf), "asks, \"%s\"", CAP(argument));
sprintf(buf2 + strlen(buf2), "ask, \"%s\"", CAP(argument));
break;
case 2:
sprintf(buf + strlen(buf), "exclaims, \"%s\"", CAP(argument));
sprintf(buf2 + strlen(buf2), "exclaim, \"%s\"", CAP(argument));
break;
case 0:
sprintf(buf + strlen(buf), "says, \"%s\"", CAP(argument));
sprintf(buf2 + strlen(buf2), "say, \"%s\"", CAP(argument));
break;
default:
break;
} else {
msg = act(buf, FALSE, ch, 0, 0, TO_ROOM | DG_NO_TRIG);
for (vict = world[IN_ROOM(ch)].people; vict; vict = vict->next_in_room)
if (vict != ch && GET_POS(vict) > POS_SLEEPING)
add_history(vict, msg, HIST_SAY);
if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_NOREPEAT))
send_to_char(ch, "Ok.\r\n");
else {
act(buf2, FALSE, ch, 0, argument, TO_CHAR);
add_history(ch, msg, HIST_SAY);
}
speech_mtrigger(ch, argument);
speech_wtrigger(ch, argument);
}
Ok now at the bottom of utils.c or where you feel inclined to do so in the file
Code:
void search_replace(char *string, const char *find, const char *replace)
{
char final[MAX_INPUT_LENGTH], temp[2];
size_t start, end, i;
while (strstr(string, find) != NULL) {
final[0] = '\0';
start = strstr(string, find) - string;
end = start + strlen(find);
temp[1] = '\0';
strncat(final, string, start);
strcat(final, replace);
for (i = end; string[i] != '\0'; i++) {
temp[0] = string[i];
strcat(final, temp);
}
sprintf(string, final);
}
return;
}