So! Here's what I've been working on, which is a pretty clear yank and translation of DarkSun's emote targeting with objects and players. I have objects carried or worn handled with the * token, you can inject yourself into an emote with @, and you can target other players with /theirname.
Where I'm running into some weirdness is with player targeting -- the /theirname thing. It displays it properly to me:
But displays nothing to the target.
The remaining tokens work fine - both the sender and other folks in the room see them and the targeted objects/person.
Code:
void personalize_emote (char_data *src, char *emote)
{
char desc [MAX_STRING_LENGTH] = { '\0' };
char copy [MAX_STRING_LENGTH] = { '\0' };
char *charshortbuf = NULL;
char_data *tch = NULL;
room_data *room;
snprintf (copy, MAX_STRING_LENGTH, "%s", emote);
while ( *emote ) {
*desc = '\0';
if ( *emote == '#' ) {
emote++;
if ( *emote == '5' ) {
emote++;
while ( *emote != '#' ) {
snprintf (desc + strlen(desc), MAX_STRING_LENGTH, "%c", *emote);
emote++;
}
tch = get_char_room_vis (src, desc, NULL);
/** Find the first person who matches the description **/
for ( tch = room->people; tch; tch = tch->next_in_room ) {
charshortbuf = (GET_INTRO(tch));
if ( !str_cmp (charshortbuf, desc) )
break;
if ( !tch )
continue;
}
} /* end emote == '5'*/
}/* end emote == '#'*/
emote++;
}
for ( tch = room->people; tch; tch = tch->next_in_room ) {
if ( tch == src )
continue;
act (copy, TRUE, tch, 0, 0, TO_CHAR);
}
return;
}
ACMD(do_testemote)
{
char buf [MAX_STRING_LENGTH] = { '\0' };
char copy[MAX_STRING_LENGTH] = { '\0' };
char key [MAX_STRING_LENGTH] = { '\0' };
bool tochar = FALSE;
bool is_imote = FALSE;
obj_data *obj = NULL;
int key_e = 0;
char *p = NULL;
char *char_desc = NULL;
char *obj_desc = NULL;
char_data *char_vis = NULL;
char_data *victim;
while (isspace(*argument))
argument++;
if (argument == NULL)
send_to_char(ch,"What would you like to emote?\n");
else {
p = copy;
while(*argument) {
if ( *argument == '@' ) {
is_imote = TRUE;
char_desc = GET_INTRO(ch);
snprintf (p, MAX_STRING_LENGTH, "\tc%s\tn", char_desc);
p += strlen(p);
argument++;
}
if(*argument == '*') {
argument++;
while(*argument>='0' && *argument<='9'){
key[key_e++] = *(argument++);
}
if(*argument=='.'){
key[key_e++] = *(argument++);
}
while(isalpha(*argument) || *argument=='-') {
key[key_e++] = *(argument++);
}
key[key_e] = '\0';
key_e = 0;
if (!get_obj_in_list_vis(ch, key, NULL, ch->carrying) &&
!get_obj_in_equip_vis(ch, key, NULL, ch->equipment)) {
snprintf (buf, MAX_STRING_LENGTH, "I don't see %s here.\n",key);
send_to_char(ch,buf);
return;
}
obj = get_obj_in_list_vis (ch, key, NULL, ch->carrying);
if ( !obj )
obj = get_obj_in_equip_vis (ch, key, NULL, ch->equipment);
obj_desc = obj->short_description;
snprintf (p, MAX_STRING_LENGTH, "\tn%s\tn", obj_desc);
p += strlen(p);
} /*end if(*argument == '*')*/
else if(*argument == '/') {
argument++;
while(*argument>='0' && *argument<='9'){
key[key_e++] = *(argument++);
}
if(*argument=='.'){
key[key_e++] = *(argument++);
}
while(isalpha(*argument) || *argument=='-') {
key[key_e++] = *(argument++);
}
key[key_e] = '\0';
key_e = 0;
if (!get_char_room_vis(ch,key,NULL)) {
snprintf (buf, MAX_STRING_LENGTH, "Who is %s?\n",key);
send_to_char(ch,buf);
return;
}
char_vis = get_char_room_vis (ch,key,NULL);
if (char_vis == ch) {
send_to_char (ch,"You shouldn't refer to yourself using the token system.\n");
free(char_vis);
return;
}
victim = get_char_room_vis( ch,key,NULL );
char_desc = GET_INTRO(victim);
snprintf (p, MAX_STRING_LENGTH, "%s", char_desc);
p += strlen(p);
tochar = TRUE;
} /* end if(*argument == '~')*/
else
*(p++) = *(argument++);
}/* end while *argument*/
*p = '\0';
if ( copy [0] == '\'' ) {
if ( !is_imote ) {
char_desc = GET_INTRO(ch);
snprintf (buf, MAX_STRING_LENGTH, "%s%s", char_desc, copy);
buf[2] = toupper (buf[2]);
}
else {
snprintf (buf, MAX_STRING_LENGTH, "%s", copy);
}
}
else {
if ( !is_imote ) {
char_desc = GET_INTRO(ch);
snprintf (buf, MAX_STRING_LENGTH, "%s %s", char_desc, copy);
buf[2] = toupper (buf[2]);
}
else {
snprintf (buf, MAX_STRING_LENGTH, "%s", copy);
}
}
if ( buf[strlen(buf)-1] != '.' && buf[strlen(buf)-1] != '!' && buf[strlen(buf)-1] != '?' )
strcat (buf, ".");
if ( !tochar )
act(buf,FALSE,ch,0,0,TO_ROOM);
else
personalize_emote (ch, buf);
act(buf,FALSE,ch,0,0,TO_CHAR);
}
return;
}