Odd Bug with Emote System

  • Chime
  • Chime's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #8112 by Chime
Odd Bug with Emote System was created by Chime
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:
testemote dances wildly at /maker
A Redheaded woman dances wildly at an unremarkable person.

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.

Any help is appreciated!
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;
}

Please Log in or Create an account to join the conversation.

More
2 years 10 months ago - 2 years 10 months ago #8114 by lacrc
Replied by lacrc on topic Odd Bug with Emote System
Hmm, I'm not entirely sure about why that is happening but, where is the *room variable being set? I can't seem to find that in the code you provided.
In fact you should be getting seg faults by trying to access room->people without it being initialized so I'm going to guess that either you are initializing it somewhere else (like in some unprovided code, since it's a local variable), the personalize_emote() function is never getting actually called or the function never reaches that point where you access room->people, otherwise you would most definitely get a seg fault crash.

Also in this part in personalize_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 ) {
The value of tch var that you set with get_char_room_vis() isn't used, you override it when you start the for with tch = room->people.
Was the first tch the intended target of the emote? Should you send him/her a message before starting the loop?

And, in the same loop, I don't think you'll ever reach the (!tch) if near the end, since having tch != NULL is the condition of the loop, I **think** you can simply remove that, but please test lol.

I also think that the next for loop:
	for ( tch = room->people; tch; tch = tch->next_in_room ) {
		if ( tch == src )
			continue;
		act (copy, TRUE, tch, 0, 0, TO_CHAR);
	}
Can be replaced by simply:
act (copy, TRUE, src, 0, 0, TO_ROOM);
That will send an act() message to everybody in the room of src except for src (which was what your loop was doing).

Hope it helps!
Last edit: 2 years 10 months ago by lacrc.
The following user(s) said Thank You: Chime

Please Log in or Create an account to join the conversation.

  • Chime
  • Chime's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #8115 by Chime
Replied by Chime on topic Odd Bug with Emote System
Oh god, you were dead on with room not being set. Fixing that resolved the initial issue with the lack of echo to tch as well. I have NO IDEA how that wasn't imploding before...

Thank you for going over it so thoroughly and providing feedback, also! I worked through and tested the suggestions and they're positively perfect.

I think I'll polish this up with a helpfile and drop it into the snippets board. Thanks again!
The following user(s) said Thank You: lacrc

Please Log in or Create an account to join the conversation.

More
2 years 10 months ago - 2 years 10 months ago #8118 by lacrc
Replied by lacrc on topic Odd Bug with Emote System
Thank you for your contribution! :)

And I know right haha, maybe if it was crashing you would've seen it... But glad it works!
Last edit: 2 years 10 months ago by lacrc.

Please Log in or Create an account to join the conversation.

Time to create page: 0.086 seconds