[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  check_social question

check_social question

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Toy   (206 posts)  [Biography] bio
Date Fri 18 Jun 2004 09:31 PM (UTC)

Amended on Fri 18 Jun 2004 09:33 PM (UTC) by Toy

Message
bool check_social( CHAR_DATA *ch, char *command, char *argument )
{
    	char arg[MAX_INPUT_LENGTH];
    	char buf[MAX_INPUT_LENGTH];
    	CHAR_DATA *victim; *** THIS LINE IS THE ERROR ***
    	SOCIALTYPE *social;
	CHAR_DATA *remfirst, *remlast, *remtemp;      /* for ignore cmnd */

    	if ( (social=find_social(command)) == NULL )
		return FALSE;

    	if ( !IS_NPC(ch) && xIS_SET(ch->act, PLR_NO_EMOTE) )
    	{
		send_to_char( "You are anti-social!\n\r", ch );
		return TRUE;
    	}
   
    	switch ( ch->position )
    	{
    		case POS_DEAD:
			send_to_char( "Lie still; you are DEAD.\n\r", ch );
			return TRUE;

    		case POS_INCAP:
    		case POS_MORTAL:
			send_to_char( "You are hurt far too bad for that.\n\r", ch );
			return TRUE;

    		case POS_STUNNED:
			send_to_char( "You are too stunned to do that.\n\r", ch );
			return TRUE;

    		case POS_SLEEPING:
/* I just know this is the path to a 12" 'if' statement.  :( But two players asked for it already! -- Furey */
			if ( !str_cmp( social->name, "snore" ) )
	    			break;
	
			send_to_char( "In your dreams, or what?\n\r", ch );
			return TRUE;
    	}

    	remfirst = NULL;
    	remlast = NULL;
    	remtemp = NULL;
    
    	one_argument( argument, arg );

    	if ( arg[0] == '\0' )
    	{
      		if( !social->others_no_arg || !social->char_no_arg)
      		{
        		send_to_char("Incomplete social, try again soon.\n\r", ch);
        		sprintf(buf, "Social %s", social->name);
        		bug(buf);
        		return TRUE;
      		}
	
		act( AT_SOCIAL, social->others_no_arg, ch, NULL, victim, TO_ROOM    );
		act( AT_SOCIAL, social->char_no_arg,   ch, NULL, victim, TO_CHAR    );
    	}
    	else if ( ( victim = get_char_world( ch, arg ) ) == NULL )
    	{
    		for(victim = remfirst; victim; victim = victim->next_in_room)
    		{
    			if(nifty_is_name(victim->name,arg) || nifty_is_name_prefix(arg,victim->name))
    			{
    				set_char_color(AT_IGNORE, ch);
    				ch_printf(ch,"%s is ignoring you.\n\r", victim->name);
    				break;
    			}
    		}
    	}
    	else if((victim = get_char_world(ch, arg)) != NULL && !IS_NPC(victim) 
       	&& (victim->in_room->vnum != ch->in_room->vnum))
    	{
      		if( !social->vict_found || !social->char_found)
      		{
        		send_to_char("Incomplete social, try again soon.\n\r", ch);
        		sprintf(buf, "Social %s", social->name);
        		bug(buf);
        		return TRUE;
      		}
      
      		strcpy( buf, "From afar...");
      		strcat( buf, social->vict_found );
      		act( AT_SOCIAL, buf, ch, NULL, victim, TO_VICT );
      		strcpy( buf, "From afar...");
      		strcat( buf, social->char_found);
      		act( AT_SOCIAL, buf, ch, NULL, victim, TO_CHAR );
    	}
    	else if(victim != NULL && !IS_NPC(victim) && victim != ch)
    	{
      		if( !social->vict_found || !social->char_found || !social->others_found)
      		{
        		send_to_char("Incomplete social, try again soon.\n\r", ch);
        		sprintf(buf, "Social %s", social->name);
        		bug(buf);
        		return TRUE;
      		}
      
      		act( AT_SOCIAL, social->vict_found,    ch, NULL, victim, TO_VICT    );
      		act( AT_SOCIAL, social->char_found,    ch, NULL, victim, TO_CHAR    );
      		act( AT_SOCIAL, social->others_found,  ch, NULL, victim, TO_NOTVICT );
    	}

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
[Go to top] top

Posted by Toy   (206 posts)  [Biography] bio
Date Reply #1 on Fri 18 Jun 2004 09:33 PM (UTC)
Message
pt 2:
    	else if ( victim == ch )
    	{
      		if( !social->char_auto || !social->others_auto)
      		{
        		send_to_char("Incomplete social, try again soon.\n\r", ch);
        		sprintf(buf, "Social %s", social->name);
        		bug(buf);
        		return TRUE;
      		}
	
		act( AT_SOCIAL, social->others_auto,   ch, NULL, victim, TO_ROOM    );
		act( AT_SOCIAL, social->char_auto,     ch, NULL, victim, TO_CHAR    );
    	}
    	else
    	{
      		if( !social->char_found || !social->others_found || !social->vict_found)
      		{
        		send_to_char("Incomplete social, try again soon.\n\r", ch);
        		sprintf(buf, "Social %s", social->name);
        		bug(buf);
        		return TRUE;
      		}
	
		act( AT_SOCIAL, social->others_found,  ch, NULL, victim, TO_NOTVICT );
		act( AT_SOCIAL, social->char_found,    ch, NULL, victim, TO_CHAR    );
		act( AT_SOCIAL, social->vict_found,    ch, NULL, victim, TO_VICT    );

		if ( !IS_NPC(ch) && IS_NPC(victim)
		&&   !IS_AFFECTED(victim, AFF_CHARM)
		&&   IS_AWAKE(victim) 
		&&   !HAS_PROG(victim->pIndexData, ACT_PROG) )
		{
	    
	    		switch ( number_bits( 4 ) )
	    		{
	    
	    			case 0:
					if (IS_EVIL(ch) && !is_safe(victim, ch, TRUE)) 
/* was IS_EVIL(ch) ||.... didn't make sense to me - FB */
		  				multi_hit( victim, ch, TYPE_UNDEFINED );
					else
					if ( IS_NEUTRAL(ch) )
					{
		    				act( AT_ACTION, "$n slaps $N.",  victim, NULL, ch, TO_NOTVICT );
		    				act( AT_ACTION, "You slap $N.",  victim, NULL, ch, TO_CHAR    );
		    				act( AT_ACTION, "$n slaps you.", victim, NULL, ch, TO_VICT    );
					}
					else
					{
		    				act( AT_ACTION, "$n acts like $N doesn't even exist.",  victim, NULL, ch, TO_NOTVICT );
		    				act( AT_ACTION, "You just ignore $N.",  victim, NULL, ch, TO_CHAR    );
		    				act( AT_ACTION, "$n appears to be ignoring you.", victim, NULL, ch, TO_VICT    );
					}
					break;

	    				case 1: case 2: case 3: case 4:
	    				case 5: case 6: case 7: case 8:
						act( AT_SOCIAL, social->others_found, victim, NULL, ch, TO_NOTVICT );
						act( AT_SOCIAL, social->char_found, victim, NULL, ch, TO_CHAR    );
						act( AT_SOCIAL, social->vict_found, victim, NULL, ch, TO_VICT    );
						break;

	    				case 9: case 10: case 11: case 12:
						act( AT_ACTION, "$n slaps $N.",  victim, NULL, ch, TO_NOTVICT );
						act( AT_ACTION, "You slap $N.",  victim, NULL, ch, TO_CHAR    );
						act( AT_ACTION, "$n slaps you.", victim, NULL, ch, TO_VICT    );
						break;
	    		}
		}
    	}
    
/* Replace the chars in the ignoring list to the room 
   note that the ordering of the players in the room might change */
    	for(victim = remfirst; victim; victim = remtemp)
    	{
    		remtemp = victim->next_in_room;
    		char_to_room(victim, ch->in_room);
    	}

    	return TRUE;
}

I'm getting this error:
interp.c: In function `check_social':
interp.c:814: warning: `victim' might be used uninitialized in this function

I've marked the line in error at the very top of the first post.

-Toy

It's always good to know how far you are willing to go to be the best...

Karl Mancine
aka
Toy the Dark Puppet
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 18 Jun 2004 10:34 PM (UTC)
Message
It's a warning, not an error. Note the word "warning". There is a distinction. This means it compiled but may not work as you expect.

The problem is that further down you do this:


act( AT_SOCIAL, social->others_no_arg, ch, NULL, victim, TO_ROOM );


However you never set "victim" to be anything, thus it will be uninitialised data, and the server will probably crash. It is warning you of this.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #3 on Sat 19 Jun 2004 03:30 AM (UTC)
Message
I've had it before as well. To get rid of it I merely did this:

CHAR_DATA *victim = NULL;

This can be very fatal if you are not sure what you are doing, so make sure you thrown in your if checks and what not to make sure that if its NULL then it does something like returning out of the function to prevent a crash.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Sun 20 Jun 2004 02:37 AM (UTC)
Message
The other advantage to initializing it to NULL is that it's easier to track down the problem if it does crash - instead of having what could have been a useful character (but you don't know because it has apparently random information that may have been corrupted) you *know* that it was never set to something useful.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


12,652 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]