|
do_say snippet [by Andrew] |
|
|
|
Posted Wednesday, December 2nd @ 01:11:05 AM, by George Greer in the Players dept.
Andrew Ritchie
writes: "Ok, this is basically a snippet on how to enhance the do_say ACMD, which
you will find in act.comm.c. I got a bit sick of people 'saying' emoticans -
which are ;) and :) etc. ACMD(do_say) does require a search and replace
function, which I have included in this snippet. If you have any problems
with ither the ACMD or search_replace(), I'd be happy to help you out seeing
as I wrote them both. Just email object@alphalink.com.au."
Enhanced do_say, by Andrew Ritchie.
----------------------------------
Ok, this is basically a snippet on how to enhance the do_say ACMD, which
you will find in act.comm.c. I got a bit sick of people 'saying' emoticans -
which are ;) and :) etc. ACMD(do_say) does require a search and replace
function, which I have included in this snippet. If you have any problems
with ither the ACMD or search_replace(), I'd be happy to help you out seeing
as I wrote them both. Just email object@alphalink.com.au.
- OPEN utils.h
Around line 36:
+ void search_replace(char *string, const char *find, const char *replace);
- CLOSE utils.h
- OPEN act.comm.c
Replace the entire ACMD(do_say) function with this:
ACMD(do_say)
{
int face, state;
skip_spaces(&argument);
if (!*argument) {
send_to_char("What do you want to say?\r\n", ch);
return;
}
sprintf(buf, "$n ");
sprintf(buf2, "You ");
if (strstr(argument, ":)") != NULL) {
face = 0;
}
else if (strstr(argument, ";)") != NULL) {
face = 1;
}
else if (strstr(argument, ";(") != NULL) {
face = 2;
}
else if (strstr(argument, ":(") != NULL) {
face = 2;
}
search_replace(argument, " :)", "");
search_replace(argument, " ;)", "");
search_replace(argument, " ;(", "");
search_replace(argument, " :(", "");
search_replace(argument, ":)", "");
search_replace(argument, ";)", "");
search_replace(argument, ";(", "");
search_replace(argument, ":(", "");
if (!*argument) {
send_to_char("What do you wish to say?\r\n", ch);
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), "smiles and ");
sprintf(buf2 + strlen(buf2), "smile and ");
break;
case 1:
sprintf(buf + strlen(buf), "winks and ");
sprintf(buf2 + strlen(buf2), "wink and ");
break;
case 2:
sprintf(buf + strlen(buf), "frowns and ");
sprintf(buf2 + strlen(buf2), "frown and ");
break;
default:
break;
}
switch(state) {
case 1:
sprintf(buf + strlen(buf), "asks, \"%s\"", argument);
sprintf(buf2 + strlen(buf2), "ask, \"%s\"", argument);
break;
case 2:
sprintf(buf + strlen(buf), "exclaims, \"%s\"", argument);
sprintf(buf2 + strlen(buf2), "exclaim, \"%s\"", argument);
break;
case 0:
sprintf(buf + strlen(buf), "says, \"%s\"", argument);
sprintf(buf2 + strlen(buf2), "say, \"%s\"", argument);
break;
default:
break;
}
act(buf, FALSE, ch, 0, 0, TO_ROOM);
if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_NOREPEAT))
send_to_char(OK, ch);
else {
act(buf2, FALSE, ch, 0, argument, TO_CHAR);
}
}
- CLOSE act.comm.c
- OPEN utils.c
Wherever you like, add in this function:
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;
}
- CLOSE utils.c
That should be about it. Hope this snippet helps in some way. Oh, and you don't
have to give me any credit. Trust me, running a MUD is so much harder than coding
it, so if you get a successful mud up with or without this snippet, I'll be
crediting you ;)
<< Merciful Mob Snippet [by Mulder] | Reply | View as text | Flattened | Updated AutoEQ [by Xual] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|