Problems with changing spell targets

Posted by Toy on Sat 18 May 2002 01:43 PM — 4 posts, 17,093 views.

#0
Just need a bit of help from anyone who can. :)

I wish to change the targets of some of my spells so you can cast them without needing a target- ie, fireball should be an area spell and not need a target. So, I changed the target on the fireball spell to ignore, and the mud crashed leaving me with this message:

Segmentation fault (CORE DUMPED)

Anyone know how to fix this so I can make my spells work right?

Thanx!
-Alexander
Australia Forum Administrator #1
Did you change the code itself? Can you post the changed function, or at least what you changed? What version of SMAUG did you use?
#2
I'm using smaug1.4a_mxp.tgz and I'm compiling with Cygwin. I'm still new to this coding stuff, and I didn't alter the code. I used the Area Editor program to change the target of fireball to ignore, then logged on and tried it. Dropped the core segment. I tried the same with acid breath, since I know that gas breath works on an ignore target. Changed acid breath's target and lost the core segment too. I attempted to change the code for lightning breath to work like gas breath in magic.c in an attempt to make them work alike:


ch_ret spell_gas_breath( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    int dam;
    int hpch;
    bool ch_died;

    ch_died = FALSE;

    if ( IS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
    {
	set_char_color( AT_MAGIC, ch );
	send_to_char( "You fail to breathe.\n\r", ch );
	return rNONE;
    }

    for ( vch = ch->in_room->first_person; vch; vch = vch_next )
    {
	vch_next = vch->next_in_room;
        if ( !IS_NPC( vch ) && xIS_SET( vch->act, PLR_WIZINVIS ) 
             && vch->pcdata->wizinvis >= LEVEL_IMMORTAL )
          continue;

	if ( IS_NPC(ch) ? !IS_NPC(vch) : IS_NPC(vch) )
	{
	    hpch = UMAX( 10, ch->hit );
	    dam  = number_range( hpch/16+1, hpch/8 );
	    if ( saves_breath( level, vch ) )
		dam /= 2;
	    if ( damage( ch, vch, dam, sn ) == rCHAR_DIED || char_died(ch) )
	      ch_died = TRUE;
	}
    }
    if ( ch_died )
      return rCHAR_DIED;
    else
      return rNONE;
}
------------------------------------------------
ch_ret spell_lightning_breath( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;
    int hpch;

    hpch = UMAX( 10, ch->hit );
    dam = number_range( hpch/16+1, hpch/8 );
    if ( saves_breath( level, victim ) )
	dam /= 2;
    return damage( ch, victim, dam, sn );
}

changed to:
ch_ret spell_lightning_breath( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *vch;
    CHAR_DATA *vch_next;
    int dam;
    int hpch;
    bool ch_died;

    ch_died = FALSE;

    if ( IS_SET( ch->in_room->room_flags, ROOM_SAFE ) )
    {
	set_char_color( AT_MAGIC, ch );
	send_to_char( "You fail to breathe.\n\r", ch );
	return rNONE;
    }

    for ( vch = ch->in_room->first_person; vch; vch = vch_next )
    {
	vch_next = vch->next_in_room;
        if ( !IS_NPC( vch ) && xIS_SET( vch->act, PLR_WIZINVIS ) 
             && vch->pcdata->wizinvis >= LEVEL_IMMORTAL )
          continue;

	if ( IS_NPC(ch) ? !IS_NPC(vch) : IS_NPC(vch) )
	{
	    hpch = UMAX( 10, ch->hit );
	    dam  = number_range( hpch/16+1, hpch/8 );
	    if ( saves_breath( level, vch ) )
		dam /= 2;
	    if ( damage( ch, vch, dam, sn ) == rCHAR_DIED || char_died(ch) )
	      ch_died = TRUE;
	}
    }
    if ( ch_died )
      return rCHAR_DIED;
    else
      return rNONE;
}


didn't quite work they way I wanted it to. I don't know if this is gonna be any help Nick, but it's the best I can do. :)
-Alexander

Amended by Nick to add forum codes for readability
Amended on Mon 20 May 2002 01:16 AM by Nick Gammon
Australia Forum Administrator #3
Hard to say for certain, but in your original spell_lightning_breath it had...

CHAR_DATA *victim = (CHAR_DATA *) vo;

Now with an "ignore" target, vo may well be NULL, in which case victim will be NULL, in which case saves_breath( level, victim) will cause a segmentation fault.